Skip to content

Instantly share code, notes, and snippets.

@obazoud
obazoud / node_debian_init.sh
Last active Sep 25, 2018 — forked from peterhost/node_debian_init.sh
Daemon init script for node.js based app/server (DEBIAN/UBUNTU)
View node_debian_init.sh
#! /bin/sh
# ------------------------------------------------------------------------------
# SOME INFOS : fairly standard (debian) init script.
# Note that node doesn't create a PID file (hence --make-pidfile)
# has to be run in the background (hence --background)
# and NOT as root (hence --chuid)
#
# MORE INFOS : INIT SCRIPT http://www.debian.org/doc/debian-policy/ch-opersys.html#s-sysvinit
# INIT-INFO RULES http://wiki.debian.org/LSBInitScripts
# INSTALL/REMOVE http://www.debian-administration.org/articles/28
@obazoud
obazoud / latency.txt
Created Jun 10, 2012 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
View latency.txt
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms
Read 4K randomly from SSD* 150,000 ns 0.15 ms
@obazoud
obazoud / Vagrantfile
Created Jul 18, 2012
Vagrant intialisation
View Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant::Config.run do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "precise64"
@obazoud
obazoud / download-jdk7.sh
Last active Oct 7, 2015
By pass Oracle license agreement
View download-jdk7.sh
#!/bin/bash
JAVA_FILE_SOURCE="jdk-7u45-linux-x64.tar.gz"
REMOTE_JAVA_SDK="http://download.oracle.com/otn-pub/java/jdk/7u45-b18/${JAVA_FILE_SOURCE}"
wget --header "Cookie:oraclelicensejdk-7u5-oth-JPR=accept-securebackup-cookie;gpw_e24=http://edelivery.oracle.com" $REMOTE_JAVA_SDK --no-check-certificate
View scalaskel.md
object Money {
// Equation: x = 1*foo + 7*bar + 11*qix + 21*bar
val FOO = 1; val BAR = 7; val QIX = 11; val BAZ = 21;
def change(cents: Int): List[Map[String, Int]] = {
lazy val tuple = for (
foo <- 0 to cents; bar <- 0 to (cents - FOO * foo) / BAR;
qix <- 0 to (cents - FOO * foo - BAR * bar) / QIX;
baz <- 0 to (cents - FOO * foo - BAR * bar - QIX * qix) / BAZ
) yield (foo, bar, qix, baz)
Stream(tuple: _*)
@obazoud
obazoud / gist:4707183
Created Feb 4, 2013
Graphite Apache configuration
View gist:4707183
<VirtualHost *:80>
ServerName graphite
DocumentRoot "/opt/graphite/webapp"
ErrorLog /opt/graphite/storage/log/webapp/error.log
CustomLog /opt/graphite/storage/log/webapp/access.log common
<Location "/">
SetHandler python-program
PythonPath "['/opt/graphite/webapp'] + sys.path"
PythonHandler django.core.handlers.modpython
View vm-clean.sh
#!/bin/bash
for vm in `VBoxManage list runningvms | awk '{ print $1 }' | sed "s/\"//g"`; do
VBoxManage controlvm "$vm" poweroff
done
for vm in `VBoxManage list vms | awk '{ print $1 }' | sed "s/\"//g"`; do
VBoxManage unregistervm --delete "$vm"
done
View flowdock-new.css
@namespace url(http://www.w3.org/1999/xhtml);
@-moz-document domain("flowdock.com") {
.chat-message, .comment-message, .action-message, .line-message, .status-message, .file-message, .error-message {
padding-top: 0 !important;
padding-bottom: 0 !important;
font-family: Ubuntu,Tahoma,sans-serif !important;
font-size: 10px !important;
}
}
View backup.sh
# TO_FOLDER=/something
# FROM=/your-es-installation
DATE=`date +%Y-%m-%d_%H-%M`
TO=$TO_FOLDER/$DATE/
echo "rsync from $FROM to $TO"
# the first times rsync can take a bit long - do not disable flusing
rsync -a $FROM $TO
# now disable flushing and do one manual flushing
View app.js
var config = {
"database": {
"connection": "mongodb://localhost/scrapService"
},
"cookieSecret": "EhAIj3NmtJ1sem5StHXV0Mk"
};
require("./user")
var express = require('express')
, mongoose = require('mongoose')
, User = mongoose.models["User"]