Skip to content

Instantly share code, notes, and snippets.

View notsobad's full-sized avatar

notsobad notsobad

View GitHub Profile
import base64
from Crypto.Cipher import AES
from Crypto import Random
BS = 16
pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS)
unpad = lambda s : s[:-ord(s[len(s)-1:])]
class AESCipher:
'''AES
@notsobad
notsobad / autopdb.py
Last active August 29, 2015 14:08 — forked from rctay/sitecustomize.py
auto run pdb when there is a exception throw.
'''
original: http://code.activestate.com/recipes/65287/
Put this in python module dir, on mac: /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
Run your script this way:
>> python -m autopdb /path/script.py
'''
// CloudFlare: Challenge Page
// ===========================
// @author: CloudFlare WWW Team
// @date: 2013-05-28
// CloudFlare Challenge Page Setup
// --------------------------------
(function( $, window, undefined ) {
var challenge_message_length = 100;
@notsobad
notsobad / allow_ip.conf
Created August 21, 2014 09:21
Get real ip under proxy, and only alow some ip to access.
server {
listen 80;
location /secret {
access_by_lua '
local function string_starts(String,Start)
return string.sub(String,1,string.len(Start)) == Start
end
local ip = nil
local cdn_ip = ngx.req.get_headers()["X-Real-Forwarded-For"]
if cdn_ip then
@notsobad
notsobad / nginx-dev.md
Last active January 16, 2020 10:03
Install nginx-systemtap-toolkit and nginx-systemtap-toolkit

install openresty

sudo apt-get install libreadline-dev libncurses5-dev libpcre3-dev libssl-dev perl make
wget http://openresty.org/download/ngx_openresty-1.7.2.1.tar.gz
tar xzvf ngx_openresty-1.7.2.1.tar.gz
cd ngx_openresty-1.7.2.1/
./configure
make
make install
@notsobad
notsobad / fabfile.py
Created July 26, 2014 01:58
Use fabric and svn to deploy code to multi servers.
import os
from fabric.api import task, run, env, cd
'''
* fab version
* fab deploy user:password:version
* fab reload_ui
'''
__author__ = 'notsobad'
@notsobad
notsobad / .tmux.conf
Last active August 29, 2015 14:03
My tmux.conf
# remap prefix to Control + a
set -g prefix C-a
unbind C-b
bind C-a send-prefix
# Base
set -g history-limit 30000
set -g status-justify left
set-window-option -g utf8 on
set-window-option -g automatic-rename on
@notsobad
notsobad / syslog2hipchat.sh
Created June 6, 2014 07:34
Send some syslog to hipchat
#!/bin/bash
log=/var/log/syslog.log
api_url='https://api.hipchat.com/v1/rooms/message?auth_token=XXXXXXXXXX'
tail -f $log|grep --line-buffered 'XXXXXXX'|while read line;do
msg=`echo "$line" | cut -d' ' -f5-`
echo 'Got' $msg
curl $api_url -vv -d "room_id=ops&from=Syslog&notify=1&color=yellow&message_format=text" --data-urlencode "message=$msg @notsobad"
@notsobad
notsobad / nginx-redirect.conf
Created March 24, 2014 15:31
Redirect all request to a server except static files.
server {
listen 80 ;
server_name 127.0.0.1;
client_header_timeout 60s;
client_body_timeout 30s;
send_timeout 60s;
#access_log /var/log/redirect.access_log redirect;