Skip to content

Instantly share code, notes, and snippets.

View apua's full-sized avatar
💭
Seeking next epic moment

Apua Juan apua

💭
Seeking next epic moment
View GitHub Profile
atsukunareyumemitaasuwo
熱くなれ夢見た明日を
kanarazuitsukatsukamaeru
必ずいつかつかまえる
hashiridasefurimukukotonaku
走り出せ振り向くなれことなく
tsumetaiyowotsukinukero
冷ろnankagamunedesakenderunoni
何かが胸で叫んでるのに
kizukanufuridesugoshiteta
########
# auto #
########
class M(type):
def __new__(mcls, *a, **kw):
print("in metaclass M - __new__:", locals())
return super().__new__(mcls, *a, **kw)
def __init__(cls, name, base, dicts):
@apua
apua / singleton.py
Last active September 12, 2015 18:51
# Singleton.py
class SingletonClass:
# __init__ will be triggered if the obj returned from __new__ is instance of __class__
# thus __init__ should also check
_ = None
def __new__(cls, *a, **kw):
if cls._:
return cls._
else:
'Ref: http://winaero.com/blog/how-to-view-your-product-key-in-windows-10-windows-8-and-windows-7/
Option Explicit
Dim objshell,path,DigitalID, Result
Set objshell = CreateObject("WScript.Shell")
'Set registry key path
Path = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\"
'Registry key value
DigitalID = objshell.RegRead(Path & "DigitalProductId")
from string import printable
for i in printable:
try:
print repr(i), eval('"\%s"' % i)
except:
pass
@apua
apua / bats.py
Created November 24, 2015 06:27
bats.py
from itertools import combinations
def checkio(bunker):
class Point:
def __init__(self, x, y):
self.x, self.y = x, y
def __repr__(self):
return "Point({},{})".format(self.x, self.y)
@apua
apua / crap_again.py
Last active November 28, 2015 08:54
real world side effect
def check_job_status(job):
if job.status=='error':
raise Exception
def task(...):
"""
It is a task of thread. When it detects job (parent) failed,
it should stop and raise exception so that the thread stop, too.
"""
try:
http://davidscottlyons.com/threejs/presentations/frontporch14/#slide-9
import functools
# decorator for method?!
class Cache(object):
def __init__(self, func):
self.func = func
self.cache = {}
def __call__(self, *args):
if args not in self.cache:
@apua
apua / retry.py
Created January 5, 2016 10:13
retry
import functools
import sys
logger = lambda: 0
logger.info = lambda s: sys.stdout.write(s+'\n')
logger.error = lambda s: sys.stdout.write(s+'\n')
def retry(tries, exceptions, logger):
def retry_dec(func):