This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function formatN (n) { | |
var nn = n.toExponential(2).split(/e/); | |
var u = Math.floor(+nn[1] / 3); | |
return nn[0] * Math.pow(10, +nn[1] - u * 3) + ['p', 'n', 'u', 'm', '', 'k', 'M', 'G', 'T'][u+4]; | |
} | |
var array = [1e7, 1e6, 2345, 100, 10, 1, 1e-2, 1e-3, 1e-5, 1e-6, 256e-9]; | |
for (var i = 0, len = array.length; i < len; i++) { | |
var n = array[i]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"private": true, | |
"devDependencies": { | |
"babel-core": "^6.18.2", | |
"babel-eslint": "^7.1.1", | |
"babel-plugin-syntax-trailing-function-commas": "^6.13.0", | |
"babel-plugin-transform-async-to-generator": "^6.16.0", | |
"babel-plugin-transform-es2015-destructuring": "^6.19.0", | |
"babel-plugin-transform-es2015-parameters": "^6.18.0", | |
"babel-plugin-transform-flow-strip-types": "^6.18.0", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (!localStorage) { | |
console.log('unavailable'); | |
} else { | |
var max = 'x', s; | |
var lower_bound = 1, upper_bound = 1, middle; | |
// determine lower and upper bound | |
try { | |
while (true) { | |
localStorage.setItem('test', max); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git branch | grep -v "master" | xargs git branch -D |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Find out the process ID (PID) which is occupying the port number (e.g., 5955) you would like to free | |
sudo lsof -i :5955 | |
Kill the process which is currently using the port using its PID | |
sudo kill -9 PID |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm audit | grep -E "(High)" -B3 -A10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Deploy nodejs app with gitlab.com and pm2 | |
========================================= | |
This manual is about setting up an automatic deploy workflow using [nodejs](https://nodejs.org/en/), | |
[PM2](http://pm2.keymetrics.io/), [nginx](https://nginx.org/) and | |
[GitLab CI](https://about.gitlab.com/features/gitlab-ci-cd/). It is tested on: | |
* Target server: **Ubuntu 16.04 x64.** This is suitable for Ubuntu 14.x. | |
* **Windows 10** on my PC to work. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
frameworks-related specifics: | |
Django generates indexes on foreign keys automatically under the hood. You can change it by providing db_index=False to ForeignKey constructor - https://docs.djangoproject.com/en/1.10/ref/models/fields/#foreignkey | |
A database index is automatically created on the ForeignKey. You can disable this by setting db_index to False. You may want to avoid the overhead of an index if you are creating a foreign key for consistency rather than joins, or if you will be creating an alternative index like a partial or multiple column index. | |
Almost all real-life cases require having these indexes. But Postgres doesn’t create them automatically as MySQL (innodb) does. It’s a significant difference | |
So, all migration tools or/and ORM systems except of Django require to do these indexes for Postgres in addition. I mean SQLAlchemy, Knex-migrations etc. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var canvas = document.getElementById("canvas"); | |
var ctx = canvas.getContext("2d"); | |
var PI2 = Math.PI * 2; | |
var corners = [] | |
corners.push({ | |
x: 50, | |
y: 100 | |
}); | |
corners.push({ |