Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dggriffin/hubot-jstips
A hubot script that grabs and displays the latest jstip.
https://github.com/dggriffin/hubot-jstips
Last synced: 3 months ago
JSON representation
A hubot script that grabs and displays the latest jstip.
- Host: GitHub
- URL: https://github.com/dggriffin/hubot-jstips
- Owner: dggriffin
- License: mit
- Created: 2016-01-20T13:31:34.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2022-07-29T02:24:24.000Z (over 2 years ago)
- Last Synced: 2024-06-30T22:59:52.873Z (5 months ago)
- Language: CoffeeScript
- Size: 9.77 KB
- Stars: 9
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- jstips - Hubot
README
A hubot script that grabs and displays the latest jstip from https://github.com/loverajoel/jstips.
See [`src/jstips.coffee`](src/jstips.coffee) for full documentation.
## Installation
In hubot project repo, run:
`npm install hubot-jstips --save`
Then add **hubot-jstips** to your `external-scripts.json`:
```json
["hubot-jstips"]
```## Sample Interaction
```
user1>> hubot jstip
hubot>>
#18 - Rounding the fast way2016-01-18 by pklinger
Today's tip is about performance. Ever came across the double tilde ~~ operator? It is sometimes also called the double NOT bitwise operator. You can use it as a faster substitute for Math.floor(). Why is that?
One bitwise shift ~ transforms the 32 bit converted input into -(input+1). The double bitwise shift therefore transforms the input into -(-(input + 1)+1) making it a great tool to round towards 0. For numeric input, it therefore mimics the Math.ceil() for negative and Math.floor() for positive input. On failure, 0 is being returned, which might come in handy sometimes instead of Math.floor() return value NaN on failure.
// single ~
console.log(~1337) // -1338// numeric input
console.log(~~47.11) // -> 47
console.log(~~-12.88) // -> -12
console.log(~~1.9999) // -> 1
console.log(~~3) // -> 3// on failure
console.log(~~[]) // -> 0
console.log(~~NaN) // -> 0
console.log(~~null) // -> 0// greater than 32 bit integer fails
console.log(~~(2147483647 + 1) === (2147483647 + 1)) // -> 0
Although ~~ may perform better, for the sake of readability please use Math.floor().
```