Skip to content

Instantly share code, notes, and snippets.

View dbrugne's full-sized avatar

Damien Brugne dbrugne

  • Toulouse, France
View GitHub Profile
@dbrugne
dbrugne / gist:f454b85dd5596d0b066e
Created February 21, 2015 13:06
Uninstall NodeJS installed from .pkg on MacOS X
# installed node version 0.10
# http://stackoverflow.com/questions/9044788/how-do-i-uninstall-nodejs-installed-from-pkg-mac-os-x
sudo npm uninstall npm -g
sudo rm -rf /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
sudo rm -rf /usr/local/include/node /Users/$USER/.npm
sudo rm /usr/local/bin/node
sudo rm /usr/local/share/man/man1/node.1
@dbrugne
dbrugne / app.js
Created February 1, 2015 15:07
Simplest static webserver with node and express
/**
* express could be installed globally (npm install -g) and loaded with global node_modules path set in NODE_PATH env
*/
var express = require('express');
var app = express();
app.use(express.static(__dirname));
app.listen(3000);
@dbrugne
dbrugne / gist:84cb2845b10dc5fe4c70
Created January 15, 2015 17:55
Javascript full date and time string
// "20150115185533114"
var d = new Date();
var date = ''+d.getFullYear()+('0'+(d.getMonth()+1)).substr(-2, 2)+('0'+(d.getDate())).substr(-2, 2)+d.getHours()+d.getMinutes()+d.getSeconds()+d.getMilliseconds();
@dbrugne
dbrugne / gist:349fcd788677d58e578a
Last active August 29, 2015 14:12
View bound ports on Linux
netstat -ln -A inet
@dbrugne
dbrugne / gist:686ce36a753f446abd19
Last active August 29, 2015 14:09
Simple node process HTTP redirect
var http = require('http'),
url = require('url');
var fqdnToRedirect = 'http://fqdn.tld';
var server = http.createServer(function(req, res) {
var q = url.parse(req.url).path;
console.log('now redirect to '+q);
res.writeHead(302, {
'Location': fqdnToRedirect+q
@dbrugne
dbrugne / create_user_database
Last active August 29, 2015 13:56
Create a new user and an associated database in MySQL
DROP DATABASE foo;
CREATE DATABASE foo;
GRANT ALL ON foo.* TO foo@localhost IDENTIFIED BY 'fooPassword';
FLUSH PRIVILEGES;