Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

import begin
@begin.subcommand
def add():
print "add"
@begin.subcommand
def dele():
print "dele"
# Cloudflare
set_real_ip_from 199.27.128.0/21;
set_real_ip_from 173.245.48.0/20;
set_real_ip_from 103.21.244.0/22;
set_real_ip_from 103.22.200.0/22;
set_real_ip_from 103.31.4.0/22;
set_real_ip_from 141.101.64.0/18;
set_real_ip_from 108.162.192.0/18;
set_real_ip_from 190.93.240.0/20;
set_real_ip_from 188.114.96.0/20;
@baojie
baojie / youtube_search_simple.py
Created May 4, 2014 19:35
Simplified youtube search example
from apiclient.discovery import build
from apiclient.errors import HttpError
from oauth2client.tools import argparser
# Get API key https://cloud.google.com/console
DEVELOPER_KEY = "REPLACE ME"
YOUTUBE_API_SERVICE_NAME = "youtube"
YOUTUBE_API_VERSION = "v3"
@baojie
baojie / a.py
Created December 17, 2014 03:48
Test whether statements in a module will just run once under multiple imports
print "run a from", __file__
(lambda _, __, ___, ____, _____, ______, _______, ________:
getattr(
__import__(True.__class__.__name__[_] + [].__class__.__name__[__]),
().__class__.__eq__.__class__.__name__[:__] +
().__iter__().__class__.__name__[_____:________]
)(
_, (lambda _, __, ___: _(_, __, ___))(
lambda _, __, ___:
chr(___ % __) + _(_, __, ___ // __) if ___ else
(lambda: _).func_code.co_lnotab,
# Disable crontab -r
function crontab ()
{
# Replace -r with -e
/usr/bin/crontab "${@/-r/-e}"
}
@baojie
baojie / timeout.py
Last active August 29, 2015 14:22
Timeout any function
from functools import wraps
import errno
import os
import signal
import time
# timeout any function in given seconds
# solution from http://stackoverflow.com/questions/2281850/timeout-function-if-it-takes-too-long-to-finish
class TimeoutError(Exception):
if
timeout 5s sleep 2;
then
echo 'OK';
else
echo 'Not OK';
fi
if
timeout 5s sleep 10;
@baojie
baojie / .zshrc
Last active October 13, 2015 01:18
zsh config
DISABLE_AUTO_UPDATE="true"
ZSH=$HOME/.oh-my-zsh
# Look in ~/.oh-my-zsh/themes/
ZSH_THEME="bira"
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
@baojie
baojie / PyccuracyHello.acc
Created December 1, 2012 09:53
Pyccuracy Hello World
As a Google User
I want to search Google
So that I can test Pyccuracy
Scenario 1 - Searching for Hello World
Given
I go to "http://www.google.com"
When
I fill "q" textbox with "Hello World"
And I click "btnG" button and wait