This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if | |
timeout 5s sleep 2; | |
then | |
echo 'OK'; | |
else | |
echo 'Not OK'; | |
fi | |
if | |
timeout 5s sleep 10; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Disable crontab -r | |
function crontab () | |
{ | |
# Replace -r with -e | |
/usr/bin/crontab "${@/-r/-e}" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print "run a from", __file__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import begin | |
@begin.subcommand | |
def add(): | |
print "add" | |
@begin.subcommand | |
def dele(): | |
print "dele" | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import timeit | |
import random | |
import string | |
data = ''.join([random.choice(string.ascii_letters) for x in range(1024*1024)]) | |
print "md5", | |
print timeit.timeit('hashlib.md5().update(data)', number=10000, setup='import hashlib; data="%s"' % data) | |
print "sha1", | |
print timeit.timeit('hashlib.sha1().update(data)', number=10000, setup='import hashlib; data="%s"' % data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from attrdict import AttrDict | |
a = AttrDict({'foo': 'bar'}) | |
a.foo | |
# OUT: 'bar' | |
a.foo == a['foo'] | |
# OUT: True | |
a.foo = 'yeah' | |
a['foo'] | |
# OUT: 'yeah' | |
foo in a |
NewerOlder