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
;;; sync-git-repos.el -- sample emacs lisp script | |
;;; Commentary: | |
;;; Code: | |
;; colors | |
(defconst *color-nc* "\033[0m") | |
(defconst *color-red* "\033[31m") | |
(defconst *color-green* "\033[32m") | |
(defconst *color-yellow* "\033[33m") |
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 snake(n): | |
arr = [[0 for _ in range(n)] for _ in range(n)] | |
value = 1 | |
border = 0 | |
while value <= n*n: | |
x, y = border, border | |
for y in range(border, n-border): |
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
#!/usr/bin/env python | |
""" | |
Modification of `python -m SimpleHTTPServer` with a fallback to /index.html | |
on requests for non-existing files. | |
This is useful when serving a static single page application using the HTML5 | |
history API. | |
""" | |
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 threading | |
from functools import wraps | |
from Queue import Queue, Empty | |
class Timeout(object): | |
def __init__(self, seconds): | |
self.seconds = seconds | |
self.q = Queue(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 signal | |
import functools | |
class TimeoutError(Exception): pass | |
def timeout(seconds, error_message='Function called timed out!'): | |
def _handle_timeout(signum, frame): | |
raise TimeoutError(error_message) |
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
palindrome = lambda s: s == s[::-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
def parlindrome(s): | |
splitter = len(s)/2 | |
return s[:splitter] == s[-1:-1-splitter:-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
# -*- coding: utf-8 -*- | |
def palindrome(s): | |
a = 0 | |
b = len(s) - 1 | |
while a < b: | |
if s[a] != s[b]: | |
return False | |
a, b = a+1, b-1 | |
return True |
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
#!/usr/bin/env python2 | |
def palindrome(s): | |
length = len(s) | |
barrier = length / 2 | |
head2tail = (c for c in s) | |
tail2head = (s[i] for i in xrange(length-1, -1, -1)) | |
for _ in xrange(barrier): | |
if head2tail.next() != tail2head.next(): |
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
#!/usr/bin/env python2 | |
def fib(max): | |
a, b = 0, 1 | |
for _ in xrange(n): | |
yield b | |
a, b = b, a+b | |
for i in fib(10): | |
print i, |
NewerOlder