Skip to content

Instantly share code, notes, and snippets.

View pnhoang's full-sized avatar

Hoang Pham pnhoang

View GitHub Profile
[To delete all local branches that are already merged into the currently checked out branch:](https://stackoverflow.com/questions/6127328/how-can-i-delete-all-git-branches-which-have-been-merged)
```git branch --merged | egrep -v "(^\*|master|dev)" | xargs git branch -d```
explain:
- git branch --merged: get all merged branch, this may include master or dev branch that you want to keep
- the second command, egrep -v, will look for all these branches and invert the search with a regular expression to search for master or dev branch
- all the results are listed on multiple lines, we need them as input parameters to the next command, we use xargs. The xargs utility reads space, tab, newline and end-of-file delimited strings from the standard
input and executes utility with the strings as arguments.
- then we can delete them with git branch -d as usual.
@pnhoang
pnhoang / bumpme
Last active November 24, 2017 14:59
Fri Nov 24 14:59:11 UTC 2017
@pnhoang
pnhoang / gist:a5032fce9eeb8df4bc6da591f7ae8d72
Created April 16, 2017 22:21
node.js express testing with supertest and mocha
SuperTest works with any test framework, here is an example without using any test framework at all:
const request = require('supertest');
const express = require('express');
const app = express();
app.get('/user', function(req, res) {
res.status(200).json({ name: 'tobi' });
});
@pnhoang
pnhoang / gist:dae226aa5353c92d184232ed365e3a6e
Created April 16, 2017 21:24
node.js express session secret
How I use sessions:
.env file (always in my .gitignore file so it never hits my public repos):
SECRET="This is my funky secret oh my god it has ninja turtles"
app.js:
var express = require('express'),
env = (function(){
var Habitat = require("habitat");