Skip to content

Instantly share code, notes, and snippets.

@giladno
giladno / .zshrc
Last active October 14, 2020 10:57
.zshrc
export ZSH=$HOME/.oh-my-zsh
source $ZSH/oh-my-zsh.sh
unset zle_bracketed_paste
source /usr/local/share/antigen/antigen.zsh
antigen use oh-my-zsh
antigen bundle dircycle
antigen bundle colored-man-pages
@giladno
giladno / .gitignore
Last active September 11, 2018 12:45
Dot files
*.DS_Store
*.swp
npm-debug.log*
build/
DerivedData/
Pods/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
@giladno
giladno / aexpress.js
Last active August 16, 2018 15:02
Async/await express wrapper
'use strict';
const methods = require('methods');
const express = require('express');
const {application} = express;
const ewrap = f => {
if (typeof f != 'function' || f.length > 3) return f;
if (f.handle && f.set) return f;
return (req, res, next) => (async () => f(req, res, next))().catch(next);
};
@giladno
giladno / generate.sh
Created April 25, 2018 00:15
Generate flags from svgs
#/bin/bash
for size in 16 32 48 64
do
echo $size
mkdir -p $size
echo "" > $size/index.js
find . -name '*.svg' -exec sh -c 'rsvg-convert -h $1 -o $1/$(basename ${0%.*}).png $0' {} $size \;
find . -name '*.svg' -exec sh -c 'echo "export const $(echo $(basename ${0%.*}) | tr 'a-z' 'A-Z') = require(\x22./$(basename ${0%.*}).png\x22);" >> $1/index.js' {} $size \;
done
@giladno
giladno / deploy.md
Last active August 10, 2019 22:16
deploy procedure to AWS

Deploy

This assumes an Ubuntu based EC2 instance.

add this line to /etc/environment; then reboot

LC_ALL="en_US.UTF-8"
@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'});
@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 / .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 / .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 / 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);
}
});