Skip to content

Instantly share code, notes, and snippets.

@bulv1ne
bulv1ne / puppy.sh
Created May 17, 2013 12:58
My lazy way to commit and push at a remote server
#!/bin/bash
# Get directory of project where this script is
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Go to directory
cd $DIR
# Get the remote SSH command
SSH="$( git remote -v | grep live | grep push | awk '{ print $2; }' | cut -f1 -d":" )"
# Do the command as root over ssh
ssh -t $SSH "cd $DIR; sql/sqlbackup.sh && git add . && git commit -a -m 'Puppy' && git push"
@bulv1ne
bulv1ne / shorty.js
Created May 30, 2013 09:32
Read more
if ($('.shorty').height() > 300) {
$('.shorty').css('max-height', '300px');
$('.shorty').css('overflow', 'hidden');
$('.shorty').after('<a href="#" class="readmore">Läs mer</a>');
$('a.readmore').click(function() {
$('.shorty').css('max-height', '');
$(this).remove();
return false;
});
}
@bulv1ne
bulv1ne / rootdir.py
Last active December 18, 2015 08:39
Get the directory of the file
import os
ROOT_DIR = os.path.dirname(os.path.realpath(__file__))
#!/bin/sh
CMD=$1
SUBJECT=$2
FROM_EMAIL="server@example.com"
EMAIL=`cat ~/.email_addr`
if [ -z "$SUBJECT" ]
then
SUBJECT="'$CMD' `date +\"%A %d/%m/%Y\"`"
from math import sqrt
def score(phat, n, z=1.0):
#z 1.0 = 85%, 1.6 = 95%
return ((phat + z*z/(2*n) - z * sqrt((phat*(1-phat)+z*z/(4*n))/n))/(1+z*z/n))
def confidence(ups, downs):
n = ups + downs
if n == 0:
OUT=mongobackup/$(date +%Y%m%d-%H%M)
mkdir -p $OUT
mongodump --out $OUT
@bulv1ne
bulv1ne / ratelimit.py
Created September 2, 2013 12:08
Ratelimit in Python and Redis
import redis
r = redis.Redis()
def ratelimit(key):
EXPIRE = 10
RATE = 10
value = r.incr(str(key))
build-essential
libz-dev
libreadline-dev
libncursesw5-dev
libssl-dev
libgdbm-dev
libsqlite3-dev
libbz2-dev
GRANT SELECT, INSERT, UPDATE, DELETE, INDEX, ALTER, CREATE, LOCK TABLES,CREATE TEMPORARY TABLES, DROP, REFERENCES ON database.* TO user@localhost IDENTIFIED BY 'password';
# self.app can be None
# self.app.config.get('DATABASE') can be None
try:
db = self.app.config['DATABASE']
logger.debug('Using database "{db}"'.format(db=db))
except:
db = 'test'
logger.warning('DATABASE setting not set, using database "test"')