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 python2 | |
# -*- coding: utf-8 -*- | |
from jnius import autoclass, cast | |
def get_classpath(): | |
ClassLoader = autoclass('java.lang.ClassLoader') | |
cl = ClassLoader.getSystemClassLoader() | |
ucl = cast('java.net.URLClassLoader', cl) |
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
# -*- coding: utf-8 -*- | |
from __future__ import unicode_literals | |
import threading | |
class Observer(object): | |
def update(self, o, *args, **kwargs): | |
""" |
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 Future(object): | |
def __init__(self, func, *args, **kwargs): | |
self._lock = threading.Lock() | |
self._thread = threading.Thread(target=self._locked(func), args=args, | |
kwargs=kwargs) | |
self._result = None | |
self._done = False | |
def _locked(self, 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
char *c[]={ | |
"ENTER", | |
"NEW", | |
"POINT", | |
"FIRST" | |
}; | |
char **cp[]={c+3,c+2,c+1,c}; | |
char ***cpp=cp; | |
main() | |
{ |
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
(defun align-numbers (start end) | |
(interactive "r") | |
(let* ((reg (buffer-substring-no-properties start end)) | |
(parts (mapcar #'y:string-strip (split-string reg ","))) | |
(widest (apply #'max (mapcar #'length parts))) | |
(full (mapcar (lambda (s) | |
(concat (make-string (- widest (length s)) ? ) s)) | |
parts)) | |
(line (mapconcat #'identity full ", "))) | |
(delete-region start end) |
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 | |
# -*- coding: utf-8 -*- | |
import random | |
import multiprocessing | |
def gen_case(): | |
return ['goat' if e else 'car' for e in random.sample(range(3), 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
;; http://forums.bgdev.org/index.php?showtopic=44083 | |
(defvar ace (/ 1 13)) | |
(defvar heart0 (/ 13 51)) | |
(defvar heart1 (/ 12 51)) | |
(defvar heart (/ (+ heart1 (* 3 heart0)) 4)) | |
(defvar probability (* ace heart)) | |
;; Our deck of cards: | |
;; 0-12 -- spades (2 3 4 5 6 7 8 9 10 jack queen king ace) |
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
# -*- coding: utf-8 -*- | |
import importlib | |
import os | |
class ImproperlyConfigured(Exception): | |
pass | |
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 python3 | |
from math import log | |
import heapq | |
first = lambda h: 2**h - 1 # H stands for level height | |
last = lambda h: first(h + 1) | |
level = lambda heap, h: heap[first(h):last(h)] | |
prepare = lambda e, field: str(e).center(field) |
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 python2 | |
# -*- coding: utf-8 -*- | |
from __future__ import print_function | |
from itertools import count | |
from math import sqrt | |
seqsum = lambda step, end: (step + end - (end % step)) * (end // step) // 2 |