Skip to content

Commit

Permalink
fix config and posts
Browse files Browse the repository at this point in the history
  • Loading branch information
loverajoel committed Mar 2, 2016
1 parent 9dd12cc commit 8213e10
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 1 addition & 2 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ highlighter: rouge
kramdown:
input: GFM
syntax_highlighter: rouge

paginate: 10
paginate: 30
paginate_path: "/:num/"

# The release of Jekyll Now that you're using
Expand Down
6 changes: 5 additions & 1 deletion _posts/en/2016-01-18-rounding-the-fast-way.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,23 @@ In contrast, the very names of the `Math.xyz()` functions clearly communicate th

##### When dealing with large-magnitude numbers
Because `~` first does a 32-bit conversion, `~~` results in bogus values around ±2.15 billion. If you don't properly range-check your input, a user could trigger unexpected behavior when the transformed value ends up being a great distance from the original:

```js
a = 2147483647.123 // maximum positive 32-bit integer, plus a bit more
console.log(~~a) // -> 2147483647 (ok)
a += 10000 // -> 2147493647.123 (ok)
console.log(~~a) // -> -2147483648 (huh?)
```
One particularly vulnerable area involves dealing with Unix epoch timestamps (measured in seconds from 1 Jan 1970 00:00:00 UTC). A quick way to get such values is:

```js
epoch_int = ~~(+new Date() / 1000) // Date() epochs in milliseconds, so we scale accordingly
```
However, when dealing with timestamps after 19 Jan 2038 03:14:07 UTC (sometimes called the **Y2038 limit**), this breaks horribly:

```js
// epoch timestamp for 1 Jan 2040 00:00:00.123 UTC
epoch = +new Date('2040-01-01') / 1000 + 0.123 // -> 2208988800.123
epoch = +new Date('2040-01-01') / 1000 + 0.123 // -> 2208988800.123

// back to the future!
epoch_int = ~~epoch // -> -2085978496
Expand All @@ -80,6 +83,7 @@ console.log(new Date(epoch_flr * 1000)) // -> Sun Jan 01 2040 00:00

##### When the original input wasn't sanitized
Because `~~` transforms every non-number into `0`:

```js
console.log(~~[]) // -> 0
console.log(~~NaN) // -> 0
Expand Down
2 changes: 1 addition & 1 deletion _posts/en/2016-01-27-short-circuit-evaluation-in-js.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ title: Short circuit evaluation in JS.
tip-number: 27
tip-username: bhaskarmelkani
tip-username-profile: https://www.twitter.com/bhaskarmelkani
tip-tldr: Short-circuit evaluation says, the second argument is executed or evaluated only if the first argument does not suffice to determine the value of the expression, when the first argument of the AND (&&) function evaluates to false, the overall value must be false; and when the first argument of the OR (||) function evaluates to true, the overall value must be true.
tip-tldr: Short-circuit evaluation says, the second argument is executed or evaluated only if the first argument does not suffice to determine the value of the expression, when the first argument of the AND `&&` function evaluates to false, the overall value must be false, and when the first argument of the OR `||` function evaluates to true, the overall value must be true.

categories:
- en
Expand Down

0 comments on commit 8213e10

Please sign in to comment.