Skip to content

Instantly share code, notes, and snippets.

@silviud
silviud / singleton.py
Created November 14, 2013 18:31
python singleton
class Singleton(object):
"""
Singleton interface:
http://www.python.org/download/releases/2.2.3/descrintro/#__new__
"""
def __new__(cls, *args, **kwds):
it = cls.__dict__.get("__it__")
if it is not None:
return it
@silviud
silviud / bash.py
Last active June 15, 2016 13:47
Python sub-process with timeout
from subprocess import PIPE, Popen
from signal import alarm, signal, SIGALRM, SIGKILL
import logging
from traceback import format_exception
import sys
class RuntimeException(Exception):
pass
class Bash:
source ~/.git-completion.sh
alias gco='git co'
alias gci='git ci'
alias grb='git rb'
#!flask/bin/python
from flask import Flask, jsonify, abort, request, make_response, url_for
from flask.ext.httpauth import HTTPBasicAuth
app = Flask(__name__, static_url_path = "")
auth = HTTPBasicAuth()
@auth.get_password
def get_password(username):
if username == 'miguel':
@silviud
silviud / mysq-infos.sql
Last active August 29, 2015 13:56
MySQL Infos
/* index size per db */
SELECT DBName,CONCAT(LPAD(FORMAT(SDSize/POWER(1024,pw),3),17,' '),' ',
SUBSTR(' KMGTP',pw+1,1),'B') "Data Size",CONCAT(LPAD(
FORMAT(SXSize/POWER(1024,pw),3),17,' '),' ',SUBSTR(' KMGTP',pw+1,1),'B') "Index Size",
CONCAT(LPAD(FORMAT(STSize/POWER(1024,pw),3),17,' '),' ',
SUBSTR(' KMGTP',pw+1,1),'B') "Total Size" FROM
(SELECT IFNULL(DB,'All Databases') DBName,SUM(DSize) SDSize,SUM(XSize) SXSize,
SUM(TSize) STSize FROM (SELECT table_schema DB,data_length DSize,
index_length XSize,data_length+index_length TSize FROM information_schema.tables
WHERE table_schema NOT IN ('mysql','information_schema','performance_schema')) AAA
#!/bin/sh
# download this script
# make sure s3cmd is installed
# yum install s3cmd
# if yum mentioned above does not work then
# wget http://downloads.sourceforge.net/project/s3tools/s3cmd/1.5.0-alpha1/s3cmd-1.5.0-alpha1.tar.gz
# tar xvf s3cmd-1.5.0-alpha1.tar.gz
# cd s3cmd-1.5.0-alpha1
# python setup.py install
# python 2.6+ is required
@silviud
silviud / iibench.py
Created March 12, 2014 14:06
iibench.py
#!/usr/bin/python -W ignore::DeprecationWarning
#
# Copyright (C) 2009 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
@silviud
silviud / string_to_utf
Created March 17, 2014 13:44
Encode utf python
def try_utf8(data):
"Returns a Unicode object on success, or None on failure"
try:
return data.decode('utf-8')
except UnicodeDecodeError, ue:
print ue
return None
# vim e! ++enc=utf8
@silviud
silviud / bash_keys.md
Created April 6, 2014 12:26
Bash Keys
Key Binding Action
Ctrl-r History reverse search
Ctrl-a Jump to BOL
Ctrl-e Jump to EOL
@silviud
silviud / setup.sh
Created April 6, 2014 13:53
Git Hooks
#!/bin/bash
repos=( repo03 repo04 )
for dir in $(seq 0 $((${#repos[@]} - 1)))
do
if [ ! -d "server_repo/${repos[$dir]}.git" ]; then
echo "${repos[$dir]}"
echo "creating repos"
mkdir -p server_repo/${repos[$dir]}.git