Skip to content

Instantly share code, notes, and snippets.

View indatawetrust's full-sized avatar
🏠
Working from home

indatawetrust

🏠
Working from home
View GitHub Profile
<!doctype html>
<head>
<style>canvas{background-color: #ecf0f1}</style>
</head>
<body>
<canvas width="500" height="500"></canvas>
<script src="https://cdn.rawgit.com/indatawetrust/abba3318ccbd051bfcb4c52002ca53b5/raw/3331d6bf9d03853655715fcadf3f5c977e1360aa/polygon-editor.min.js"></script>
</body>
</html>
'use strict';var canvas=document.querySelector('canvas'),c=canvas.getContext('2d'),polygons=[],polygonTouch=!1,startX=null,startY=null,pointInPolygon=function(a,b,d){var f,g=d.length-1,h=!1;for(f=0;f<d.length;f++){var l=d[f].x,m=d[g].x,n=d[f].y,o=d[g].y;(n<b&&o>=b||o<b&&n>=b)&&(l<=a||m<=a)&&l+(b-n)/(o-n)*(m-l)<a&&(h=!h),g=f}return h},polygonPoints=function(a,b,d){for(var f=[],g=0;g<a+1;g++)f.push({x:75*Math.sin(Math.PI*(g*(360/a)/180))+b,y:75*Math.cos(Math.PI*(g*(360/a)/180))+d});return f},drawPolygon=function(a){c.clearRect(0,0,500,500);var b=[];return a.forEach(function(d){var f=[];c.save(),c.beginPath(),d.forEach(function(g){c.lineTo(g.x,g.y)}),c.fillStyle='#fff',c.fill(),c.stroke(),c.closePath(),c.restore(),d.forEach(function(g,h){h<d.length-1&&(c.save(),c.translate(g.x,g.y),c.fillStyle='#2c3e50',c.fillRect(-5,-5,10,10),c.restore(),f.push({x:g.x,y:g.y,w:10,h:10,index:h}))}),b.push(f)}),b},rectForEach=function(a,b,d,f){return a.forEach(function(g){f?b>=g.x&&b<=g.x+g.w&&d>=g.y&&d<=g.y+g.h&&(g.down=!0):b>=g.
[
{
"cmn":"Mandarin Chinese"
},
{
"spa":"Spanish"
},
{
"eng":"English"
},
@indatawetrust
indatawetrust / backup.sh
Created May 16, 2017 12:32
mongodb gdrive backup
export db=app
docker exec -it mongo bash -c "mongodump -d $db -o $db"
docker cp mongo:/$db $db
apt install zip -y
zip -r $db.zip $db
apt install golang-go -y
export GOPATH=$HOME/go
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
go get github.com/prasmussen/gdrive
# Enter verification code
@indatawetrust
indatawetrust / monitor.sh
Created May 10, 2017 00:21
redis-cli monitor grep
redis-cli monitor | grep -E ' "set" '
@indatawetrust
indatawetrust / pm2.js
Created May 7, 2017 01:08
pm2 automatic restart
var restart_time = 30e4;
var pm2 = require('pm2');
pm2.connect(function(err) {
if (err) throw err;
setTimeout(function worker() {
console.log("Restarting app...");
pm2.restart('app', function() {});
# delete all indexes
curl -XDELETE 'http://localhost:9200/_all'
# get all indexes
curl -XGET 'localhost:9200/_search' -d '
{
"query" : {
"match_all" : {}
}
}'
sudo swapon -s
sudo fallocate -l 4G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
This file has been truncated, but you can view the full file.
[{"url":"/title/tt2771200/?ref_=adv_li_tt","title":"Beauty and the Beast","image":"https://images-na.ssl-images-amazon.com/images/M/MV5BMTUwNjUxMTM4NV5BMl5BanBnXkFtZTgwODExMDQzMTI@._V1_UX67_CR0,0,67,98_AL_.jpg","score":"7.9"},{"url":"/title/tt3315342/?ref_=adv_li_tt","title":"Logan","image":"https://images-na.ssl-images-amazon.com/images/M/MV5BMjI1MjkzMjczMV5BMl5BanBnXkFtZTgwNDk4NjYyMTI@._V1_UX67_CR0,0,67,98_AL_.jpg","score":"8.5"},{"url":"/title/tt3731562/?ref_=adv_li_tt","title":"Kong: Skull Island","image":"https://images-na.ssl-images-amazon.com/images/M/MV5BMTUwMzI5ODEwNF5BMl5BanBnXkFtZTgwNjAzNjI2MDI@._V1_UX67_CR0,0,67,98_AL_.jpg","score":"7.1"},{"url":"/title/tt5052448/?ref_=adv_li_tt","title":"Get Out","image":"https://images-na.ssl-images-amazon.com/images/M/MV5BNTE2Nzg1NjkzNV5BMl5BanBnXkFtZTgwOTgyODMyMTI@._V1_UX67_CR0,0,67,98_AL_.jpg","score":"8.3"},{"url":"/title/tt3890160/?ref_=adv_li_tt","title":"Baby Driver","image":"https://images-na.ssl-images-amazon.com/images/M/MV5BNTNmNzgzMzEtYjExMS00YTA0LWE
const serialize = uri => decodeURIComponent(uri).split('&').map(uri => ({ [uri.split('=')[0]]: uri.split('=')[1] })).reduce((a,b) => Object.assign(a,b))
console.log(serialize("_id%3D58c43d995cb9191a2f676b25%26index%3D0%26guid%3D798ebd68-22d5-4465-9d34-d4717891901d%26isActive%3Dfalse%26balance%3D%242%2C569.51%26picture%3Dhttp%3A%2F%2Fplacehold.it%2F32x32%26age%3D33%26eyeColor%3Dgreen%26name%3DDesiree%20Cervantes%26gender%3Dfemale%26company%3DSYNKGEN%26email%3Ddesireecervantes%40synkgen.com%26phone%3D%2B1%20(975)%20536-2019%26address%3D855%20Hendrickson%20Street%2C%20Libertytown%2C%20Marshall%20Islands%2C%205292%26about%3DElit%20anim%20occaecat%20proident%20consectetur%20veniam%20et%20deserunt%20irure.%20Sint%20aliquip%20fugiat%20aute%20tempor%20veniam%20eu%20duis%20mollit%20eiusmod%20aliquip%20ipsum%20enim%20do%20in.%20Pariatur%20nisi%20proident%20commodo%20duis%20nisi%20id%20ut%20commodo%20aute%20irure.%20Minim%20ut%20tempor%20in%20tempor%20dolor%20ex%20veniam%20fugiat.%20Sint%20cillum%20non%20qui%20elit%20a