This file contains hidden or 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 __future__ import with_statement | |
import signal, time | |
from contextlib import contextmanager | |
def long_function_call(): | |
while True: | |
if time.time() % 1 == 0: | |
print '*' | |
class TimeoutException(Exception): pass |
This file contains hidden or 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
jQuery.fn.filterByText = function(textbox, selectSingleMatch) { | |
return this.each(function() { | |
var select = this; | |
var options = []; | |
$(select).find('option').each(function() { | |
options.push({value: $(this).val(), text: $(this).text(), disabled:$(this).is(':disabled')}); | |
}); | |
$(select).data('options', options); | |
$(textbox).bind('change keyup', function() { | |
var options = $(select).empty().scrollTop(0).data('options'); |
This file contains hidden or 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 bcrypt | |
def generate_password(str): | |
return bcrypt.hashpw(str, bcrypt.gensalt()) | |
def check_password(str, stored_hash): | |
hash_check = bcrypt.hashpw(str, stored_hash) | |
return hash_check == stored_hash |
This file contains hidden or 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
def is_ajax(request): | |
try: | |
if request.META['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest': | |
return True | |
else: | |
return False | |
except KeyError: | |
return False |
This file contains hidden or 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
def upper2lower(string): | |
string1 = '' | |
start = 0 | |
for m in re.finditer('[A-Z]', string): | |
if m.start() != 0: | |
string1 += string[start+1:m.start()] + '_' + m.group(0).lower() | |
else: | |
string1 += string[start:m.end()].lower() | |
start = m.start() | |
string1 += string[start+1:] |
This file contains hidden or 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 time | |
from math import ceil | |
def time2duration(stamp): | |
# 对当前时间向上取整,防止出现负数~ | |
stamp = int(ceil(stamp)) | |
cur_time = int(ceil(time.time())) | |
during = cur_time - stamp | |
if during < 30: |
This file contains hidden or 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
<?php | |
function print_vars() { | |
$vars = func_get_args(); | |
echo '<pre>'; | |
foreach ($vars as $var) { | |
ob_start(); | |
var_dump($var); | |
echo htmlspecialchars(ob_get_clean()); | |
} | |
echo '</pre>'; |
NewerOlder