Skip to content

Instantly share code, notes, and snippets.

@yalab
yalab / heroku_mongo_backup
Created November 17, 2011 10:24
Backup scripts MongoHQ databases using heroku.
#!/bin/bash
HEROKU="/home/yalab/.rvm/gems/ruby-1.9.3-p0/bin/heroku"
BACKUP_DIR="$HOME/.backup/mongohq"
if [ ! -d $BACKUP_DIR ];then
mkdir -p $BACKUP_DIR
fi
for APP in `$HEROKU list`;do
MONGOHQ_URL=`heroku config --app $APP | grep MONGOHQ_URL | awk '{print $3}'`
@yalab
yalab / gist:1504270
Created December 21, 2011 02:20
STDERR redirect to STDOUT
# stderr_to_stdout do
# warn("warning message")
# end
module Kernel
def stderr_to_stdout
old_std_err = STDERR.clone
STDERR.reopen(STDOUT)
yield
ensure
@yalab
yalab / ssh_tunnel.sh
Created January 12, 2012 00:05
SSH Tunnering
#!/bin/zsh
USER='yalab'
SOURCE_HOST='YOUR GLOBAL IP ADDRESS'
SOURCE_PORT=8888
DEST_HOST='DESTINATION HOST IP ADDRESS'
DEST_PORT=22
SSH_KEY='/home/yalab/.ssh/id_rsa'
sudo kill `ps ax | grep 'ssh -N'| awk '{print $1}'`
@yalab
yalab / pre-commit.sh
Created May 11, 2012 05:55
PHP Syntax check before pre-commit hook of git
#!/bin/sh
PHP="/usr/bin/php"
PWD=`pwd`
SYNTAXCHECK="/usr/bin/php -l"
GIT_ROOT=`pwd`/`git rev-parse --show-cdup`
MODIFIED_FILES=`git diff-index --cached HEAD | awk '{print $6}'`
ERRORS=""
for f in $MODIFIED_FILES;do
@yalab
yalab / qrcode.html
Created June 6, 2012 04:01
QR Code Generator
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>QR Code Generator</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="https://raw.github.com/jeromeetienne/jquery-qrcode/master/jquery.qrcode.min.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(function($){
$("#button").on('click', function(){
@yalab
yalab / gist:2893762
Created June 8, 2012 05:26
anything-bzr-grep.el
(eval-when-compile (require 'cl))
(require 'vc-bzr)
(provide 'anything-bzr-grep)
(defvar anything-c-source-bzr-grep-cache nil "path")
(setq bzr-command "/usr/local/bin/bzr")
(defun anything-bzr-grep-init ()
(setq anything-c-source-bzr-grep-cache
(vc-bzr-root (if (buffer-file-name)
@yalab
yalab / mongoc.conf
Created June 16, 2012 03:54
Upstart script mongodb sharding config server
# Ubuntu upstart file at /etc/init/mongoc.conf
pre-start script
mkdir -p /var/lib/mongoc/
chown mongodb:mongodb /var/lib/mongoc/
end script
start on runlevel [2345]
stop on runlevel [06]
@yalab
yalab / mongos.conf
Created June 16, 2012 03:55
Upstart script mongodb sharding router
# Ubuntu upstart file at /etc/init/mongos.conf
start on runlevel [2345]
stop on runlevel [06]
script
ENABLE_MONGODB="yes"
PIDFILE=/var/run/mongos.pid
if [ "x$ENABLE_MONGODB" = "xyes" ]; then exec start-stop-daemon --start --quiet --chuid mongodb -m --pidfile $PIDFILE --exec /usr/bin/mongos -- --config /etc/mongos.conf; fi
end script
@yalab
yalab / gist:3788931
Created September 26, 2012 16:11
yalab-color.el
(set-face-foreground 'font-lock-comment-face "#ff6666") ;red
(set-face-foreground 'font-lock-string-face "#66ff66") ;green
(set-face-foreground 'font-lock-keyword-face "cyan")
(set-face-bold-p 'font-lock-keyword-face t)
(set-face-foreground 'font-lock-function-name-face "#6699ff") ;blue
(set-face-bold-p 'font-lock-function-name-face t)
(set-face-foreground 'font-lock-variable-name-face "#ffd314") ;yellow
(set-face-foreground 'font-lock-type-face "#66ff66") ;green
(set-face-foreground 'font-lock-builtin-face "purple")
(set-face-foreground 'font-lock-constant-face "purple")
require 'kramdown'
require 'uri'
require 'pathname'
body =<<EOS
> [link](test)
>> [google](http://www.google.com)
EOS
kramdown = Kramdown::Document.new(body)