Skip to content

Instantly share code, notes, and snippets.

@giladno
giladno / upgrade.sh
Created March 24, 2017 22:26
Update react-native project
#!/bin/bash
INPUT=`pwd`
OUTPUT=`pwd`'_upgrade'
NAME=`node -e "console.log(require('./package.json').name);"`
DEPENDENCIES=`node -e "console.log(Object.keys(require('./package.json').dependencies).join(' '));"`
DEV_DEPENDENCIES=`node -e "console.log(Object.keys(require('./package.json').devDependencies).join(' '));"`
rm -rf $OUTPUT
(cd /tmp && react-native init $NAME)
@giladno
giladno / push.js
Created April 20, 2017 14:26
push aws
module.exports.push = coroutine(function*(data, users){
let params = {
MessageStructure: 'json',
Message: JSON.stringify({
default: data.subject,
APNS: JSON.stringify(assign({
aps: assign({alert: data.alert, sound: data.sound}, data.apns||{}),
},_.omit(data, 'alert', 'collapseKey', 'subject', 'apns', 'sound'))),
GCM: JSON.stringify({
collapseKey: data.collapseKey,
@giladno
giladno / .vimrc
Last active December 16, 2018 09:28
My .vimrc file
set autoindent
set autoread " Make Vim automatically open changed files
set background=dark
" set cinoptions=:0,(s,u0,U1
set clipboard=unnamed
set colorcolumn=120
set columns=130
set copyindent
set cursorline
set directory^=$HOME/.vim/swp//
@giladno
giladno / ewrap.js
Created November 25, 2017 15:09
ewrap
'use strict';
const express = require('express');
const app = express();
const ewrap = f=>(...args)=>f(...args).catch(args[args.length-1]);
app.all('/test', ewrap(async (req, res)=>{
await new Promise(function (resolve, reject) {
setTimeout(function () {
@giladno
giladno / ewrap.js
Last active November 25, 2017 16:55
ewrap all
'use strict';
const express = require('express');
const app = (()=>{
const ewrap = f=>{
if (f.length>3)
return f;
return (req, res, next)=>(async ()=>f(req, res, next))().catch(next);
};
let app = express();
for (let fn of ['use', 'all', 'get', 'post', 'put', 'delete', 'head', 'options'])
@giladno
giladno / index.js
Created November 25, 2017 15:47
user auth in express
app.use(async (req, res, next)=>{
try {
req.user = await auth.validate(req);
} catch(err) {
if (...)
return res.json({error: 'user not found'});
next(err);
}
});
@giladno
giladno / .bash_profile
Last active July 31, 2018 11:34
My bash_profile
export PS1="\[\033]0;\w\007\]\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$ "
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
export LANG=en_US.UTF-8
alias ls='ls -GFh'
alias rgrep='ag --vimgrep'
alias rfind='find . | grep -i'
alias tldr='tldr -t ocean'
alias sizes='du -hd1'
export NODE_ENV=development
@giladno
giladno / .gitignore
Created November 26, 2017 17:32
My .gitignore
*.DS_Store
*.swp
Podfile.lock
npm-debug.log*
node_modules
build/
DerivedData/
Pods/
*.pbxuser
!default.pbxuser
@giladno
giladno / express.js
Created January 19, 2018 17:18
'route' test on express
'use strict';
const express = require('express');
const axios = require('axios');
let app = express();
app.use('/test', (req, res, next)=>next('route'), (req, res)=>res.json({ok: true}));
app.listen(8080, async ()=>{
let {data} = await axios.get('http://localhost:8080/test');
@giladno
giladno / pdf
Created January 26, 2018 15:18
app.get('/pdf', authenticated, async (req, res)=>{
let browser = await puppeteer.launch();
try {
let page = await browser.newPage();
await page.goto(url.format({
protocol: 'http:',
host: '127.0.0.1:3000',
pathname: '/',
query: req.query,
}), {waitUntil: 'networkidle'});