Skip to content

Instantly share code, notes, and snippets.

Avatar

이정민(Jeong-Min Lee) falsetru

View GitHub Profile
@falsetru
falsetru / datameta.py
Last active Dec 7, 2018 — forked from tempKDW/datameta.py
Use `new_attrs` when creating __slots__
View datameta.py
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):
@falsetru
falsetru / 3n_1.py
Created Oct 16, 2013
우박 수열
View 3n_1.py
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:
View ex.py
functions = []
for val in ['foo', 'bar', 'baz']:
def f(val=val):
return val
functions.append(f)
for func in functions:
print(func())
View test_selenium_webdriverwait.py
# 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()
View proc_bind.rb
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)
View qr_scan.py
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')
View repair-fastq.py
import collections
import sys
def is_valid_fastq(lines):
return (
lines[0].startswith('@') and
lines[2].startswith('+') and
len(lines[1]) == len(lines[3])
)
View CLOCKSYNC-WA.cc
#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),
@falsetru
falsetru / submit.py
Last active Dec 13, 2015
submit solution to algospot judge.
View submit.py
#!/usr/bin/env python
import cookielib
import os
from contextlib import closing
import re
import getpass
import webbrowser
import sys
View count.py
from functools import lru_cache
coins= 10,20,50,100,200,500,1000,2000,5000,10000
@lru_cache(None)
def count(amount, idx=len(coins)-1):
if amount < 0 or idx < 0: return 0
if amount == 0: return 1
return count(amount - coins[idx], idx) + count(amount, idx-1)