Skip to content

Instantly share code, notes, and snippets.

@didip
didip / add_to__all__decorator.py
Created January 2, 2013 03:45
Use decorator to avoid retyping function/class names into __all__ module variable. It's an effective way to cut down large number of unnecessary imports caused by "from some_module import *". Works on Python 2.6 and greater.
import sys
def add_to__all__(func_or_class):
""""Use decorator to avoid retyping function/class names into __all__ module level variable."""
all_list = sys.modules[func_or_class.__module__].__dict__.setdefault('__all__', [])
if func_or_class.__name__ not in all_list:
all_list.append(func_or_class.__name__)
return func_or_class
@didip
didip / jenkins-project-names-parser.sh
Last active December 10, 2015 14:18
Grab Jenkins project names from cc.xml
curl --silent http://your.jenkins/cc.xml | grep -o '<Project[^>]*/>' | grep -o 'name="[^"]*"' | cut -f2 -d'"'
@didip
didip / add-self-signed-cert.sh
Last active December 10, 2015 20:38
Script to download and add self-signed SSL cert exception to OS X keychain. Usage: ./add-self-signed-cert.sh www.example.com
#!/bin/sh
DOMAIN=$1;
echo -n | openssl s_client -connect $DOMAIN:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /tmp/$DOMAIN.cert && open /tmp/$DOMAIN.cert
# Notes:
# 1. After you ran this script, simple refresh your stubborn browser. i.e. Chrome.
# 2. When you are done, don't forget to delete /tmp/$DOMAIN.cert file.
@didip
didip / download-centos-mirror.sh
Last active March 13, 2019 13:53
Simple script to download CentOS mirror. You can totally put this in cron.
#!/bin/bash
# Number of arguments should be at least 1
if [ $# -lt 1 ]; then
echo "Usage: $0 centos-version-number"
exit 1
fi
VERSION=$1
@didip
didip / $.browser.port.js
Created January 17, 2013 05:39
Replicate $.browser functionality since jQuery 1.9 removed $.browser.
browser: {
mozilla: /firefox/.test(navigator.userAgent.toLowerCase()),
webkit: /webkit/.test(navigator.userAgent.toLowerCase()),
chrome: /chrome/.test(navigator.userAgent.toLowerCase()),
safari: /safari/.test(navigator.userAgent.toLowerCase()) && !/chrome/.test(navigator.userAgent.toLowerCase()),
opera: /opera/.test(navigator.userAgent.toLowerCase()),
msie: /msie/.test(navigator.userAgent.toLowerCase())
}
@didip
didip / stathat-https-embed.js
Last active December 14, 2015 22:29
StatHat HTTPS embed.js
StatHatEmbed=new function(){function d(){var a=document.getElementsByTagName("script");return a[a.length-1]}function e(a,b){var d=document.createElement("script"),c="//www.stathat.com/embed/"+a+"/"+b.s1;b.dev&&(c="//localhost:8081/embed/"+a+"/"+b.s1);b.s2&&(c+="/"+b.s2);b.s3&&(c+="/"+b.s3);c+="?w="+b.w+"&h="+b.h+"&tf="+b.tf;b.style&&(c+="&style="+b.style);b.dev&&(c+="&dev=1");b.title&&(c+="&title="+b.title);d.src=c;d.type="text/javascript";document.getElementsByTagName("head")[0].appendChild(d)}
function f(a){return[a.s1,a.s2,a.s3,a.w,a.h,a.tf,a.style].join("_")}this.render_graph=function(a){DIV_ID="statd_embed_graph_"+f(a);d().insertAdjacentHTML("AfterEnd","<div id='"+DIV_ID+"' style='display:none'></div>");e("graph",a)};this.render_data=function(a){DIV_ID="statd_embed_data_"+f(a);d().insertAdjacentHTML("AfterEnd","<div id='"+DIV_ID+"' style='display:none'></div>");e("data",a)};this.render_table=function(a){DIV_ID="statd_embed_table_"+f(a);d().insertAdjacentHTML("AfterEnd","<div id='"+DIV_ID+
"' style='displ
@didip
didip / setup-multiple-venvs.sh
Last active December 16, 2015 01:39
Setup multiple virtualenvs using pythonz.
#!/bin/bash
#
# Setup multiple Pythons for On the Plates
#
# VARIABLES
PYTHON27_VERSION='2.7.4'
PYTHON27_NAME="CPython-$PYTHON27_VERSION"
PYTHON27_BIN="~/.pythonz/pythons/$PYTHON27_NAME/bin/python"
@didip
didip / generic-dot-profile
Created May 8, 2013 05:22
My generic .profile file
# say
alias say="say -v Vicki"
# Don't check mail
unset MAILCHECK
#
# Fancy bash functions
#
function ifconfig_line {
@didip
didip / setup-remi-repo.sh
Created June 28, 2013 00:27
Remi's Repo. God send for CentOS 6.4
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm
begin;
insert into table select * from only table where id between 1 and 10000000;
delete from only table where id between 1 and 10000000;
commit;
begin;
insert into table select * from only table where id between 10000001 and 20000000;
delete from only table where id between 10000001 and 20000000;
commit;