Skip to content

Instantly share code, notes, and snippets.

View dannycroft's full-sized avatar

Danny Croft dannycroft

View GitHub Profile
@dannycroft
dannycroft / roles.js
Created April 27, 2016 16:24
User roles & routing demo
function requireRole(role) {
return function(req, res, next) {
if (req.session.user && req.session.user.role === role) {
next();
else {
res.send(403);
}
}
}
@dannycroft
dannycroft / .vimrx
Created January 14, 2016 15:17
Temp vimrc
set nocompatible
set t_Co=256
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Bundle 'gmarik/Vundle.vim'
@dannycroft
dannycroft / .eslintrc
Created July 14, 2015 10:47
Formatting and validation for node apps
{
"env": {
"browser": true,
"node": true,
"amd": true
},
"rules": {
"no-console": 2,
"no-comma-dangle": 2,
@dannycroft
dannycroft / mem.sh
Created July 2, 2015 09:26
One liner for docker container memory usage (LXC)
for line in `docker ps | awk '{print $1}' | grep -v CONTAINER`; do docker ps | grep $line | awk '{printf $NF" "}' && echo $(( `cat /sys/fs/cgroup/memory/docker/$line*/memory.usage_in_bytes` / 1024 / 1024))MB ; done
@dannycroft
dannycroft / gist:b59fbe457aa866b3160c
Created May 29, 2015 08:09
Forward traffic on port 80 to 3000
sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 3000
@dannycroft
dannycroft / gist:f0e3b766d8a7fd273766
Created May 18, 2015 08:23
clean-shrinkwrap-task
node -e '
function clean(j) {
if (!j) return
for (var k in j) {
delete j[k].from
delete j[k].resolved
if (j[k].dependencies) clean(j[k].dependencies)
}
}
x = JSON.parse(require("fs").readFileSync("./npm-shrinkwrap.json"))
@dannycroft
dannycroft / utopic-node
Created April 20, 2015 15:55
Dockerfile
FROM ubuntu:utopic
RUN apt-get update \
&& apt-get install -y --force-yes \
apt-transport-https \
build-essential \
curl \
lsb-release \
python-all \
rlwrap \
@dannycroft
dannycroft / gist:fbfd46fd1b4a071fc964
Created April 15, 2015 09:33
Elasticsearch shutdown via CURL
# Shutdown local node
curl -XPOST 'http://localhost:9200/_cluster/nodes/_local/_shutdown'
# Shutdown all nodes in the cluster
curl -XPOST 'http://localhost:9200/_shutdown'
@dannycroft
dannycroft / gist:930fe73318e1fa1a14c1
Created April 14, 2015 09:58
Docker - Last run container still running
# is the last run container still running?
docker inspect --format '{{.State.Running}}' $(docker ps -lq)
@dannycroft
dannycroft / remove.sh
Created April 9, 2015 13:43
Docker - Remove all images and containers
#!/bin/bash
# Delete all containers
docker rm $(docker ps -a -q)
# Delete all images
docker rmi $(docker images -q)