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
class DataMeta(type): | |
def __new__(cls, name, bases, attrs): | |
def check_type(k, v): | |
cls._validate(attrs[k]['type'], v) | |
def set_default(self, kwargs): | |
for key_meta, value_meta in attrs.items(): | |
if key_meta.startswith('__') and key_meta.endswith('__'): | |
continue | |
if not isinstance(value_meta, dict): |
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
#!/usr/bin/kivy | |
import kivy | |
#kivy.require('1.0.6') | |
from kivy.app import App | |
from kivy.uix.floatlayout import FloatLayout | |
from kivy.uix.label import Label | |
from kivy.graphics import Color, Rectangle, Point, GraphicException | |
from kivy.clock import Clock | |
from kivy.logger import Logger |
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 functools | |
import sys | |
@functools.lru_cache(maxsize=None) # Python 3.2+ | |
def f(n): | |
if n == 1: | |
return 1 | |
elif n % 2 == 0: | |
return 1 + f(n // 2) | |
else: |
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
functions = [] | |
for val in ['foo', 'bar', 'baz']: | |
def f(val=val): | |
return val | |
functions.append(f) | |
for func in functions: | |
print(func()) |
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
# See https://code.google.com/p/selenium/source/browse/py/selenium/webdriver/support/wait.py | |
from selenium import webdriver | |
from selenium.webdriver.support.wait import WebDriverWait | |
driver = webdriver.Firefox() | |
driver.get('http://jsfiddle.net/falsetru/M6tdQ/show/') | |
WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_id('status').text == 'ready') | |
driver.execute_script('alert("done")') | |
#driver.quit() |
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
class CurriedProc < Proc | |
attr_accessor :arity | |
def parameters | |
(1..arity).map { |i| [:opt, "_#{i}".to_sym] } | |
end | |
end | |
class Proc | |
def bind(pos, value) | |
raise ArgumentError.new("wrong position of argument (#{pos} for #{arity})") unless (1..arity).include?(pos) |
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 lxml.html | |
import requests | |
FILENAME = '3.png' | |
r = requests.get('http://www.onlinebarcodereader.com/') | |
root = lxml.html.fromstring(r.text) | |
MAX_FILE_SIZE, = root.cssselect('input[name=MAX_FILE_SIZE]') | |
senderid, = root.cssselect('#senderid') |
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 collections | |
import sys | |
def is_valid_fastq(lines): | |
return ( | |
lines[0].startswith('@') and | |
lines[2].startswith('+') and | |
len(lines[1]) == len(lines[3]) | |
) |
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
#include <stdio.h> | |
#include <algorithm> | |
#define swc(i) (1L << (i * 3)) | |
long long switches[10] = { | |
swc(0) | swc(1) | swc(2), | |
swc(3) | swc(7) | swc(9) | swc(11), | |
swc(4) | swc(10) | swc(14) | swc(15), | |
swc(0) | swc(4) | swc(5) | swc(6) | swc(7), | |
swc(6) | swc(7) | swc(8) | swc(10) | swc(12), |
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
#!/usr/bin/env python | |
import cookielib | |
import os | |
from contextlib import closing | |
import re | |
import getpass | |
import webbrowser | |
import sys |
NewerOlder