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
(function($) { | |
function addUL(parent) { | |
var $ul = $("<ul/>"); | |
var baseId = "_" + $(parent).attr("id"); | |
$(parent).children("option,optgroup").each(function(index, tag) { | |
if (tag.tagName.toLowerCase() === "option") { | |
var $option = $(this); | |
var id = baseId + index; | |
var $li = $("<li/>").appendTo($ul); |
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
def fibonacci(max): | |
a, b = 1, 2 | |
while a < max: | |
yield a | |
a, b = b, a+b | |
print sum(x for x in fibonacci(4000000) if x % 2 == 0) |
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 base64;exec base64.b64decode('ZGVmIGZpYm9uYWNjaShtYXgpOgogICAgYSwgYiA9IDEsIDIKICAgIHdoaWxlIGEgPCBtYXg6CiAgICAgICAgeWllbGQgYQogICAgICAgIGEsIGIgPSBiLCBhK2IKCnByaW50IHN1bSh4IGZvciB4IGluIGZpYm9uYWNjaSg0MDAwMDAwKSBpZiB4ICUgMiA9PSAwKQ==') |
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
# | |
# Example init.py for documentation purposes | |
# | |
# Use this file as a template/example for creating an | |
# initialization/configuration script for PyCmd. Scripts are loaded and applied | |
# based on the following rules: | |
# | |
# * If present, an init.py script in PyCmd's installation directory is | |
# automatically executed and defines "global" (system-wide) settings | |
# |
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
def sieve(numbers, n): | |
for i in range(n * 2, len(numbers), n): | |
numbers[i] = False | |
def skip_to_next_prime(numbers, n): | |
n += 1 | |
while n < max and not numbers[n]: | |
n += 1 | |
return n |
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
def is_palindrome(x): | |
x = str(x) | |
return x == x[::-1] | |
def find_palindromes(m, n): | |
for i in xrange(m, n): | |
for j in xrange(i, n): | |
x = i * j | |
if is_palindrome(x): | |
yield x |
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
# Translation of https://gist.github.com/alaafqandil/9009412 to Python | |
def multiple_of_3x3(num): | |
return any(num % i == 0 and len(str(num / i)) == 3 for i in reversed(xrange(100, 1000))) | |
def find_max_palindrome(): | |
for i in reversed(xrange(10)): | |
for j in reversed(xrange(10)): | |
for k in reversed(xrange(10)): | |
palindrome = int('{0}{1}{2}{2}{1}{0}'.format(i, j, k)) | |
if palindrome < 999 ** 2: |
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 sys, os | |
from PIL import Image | |
files = os.listdir(sys.argv[1]) | |
for i, f in enumerate(files): | |
fname = os.path.join(sys.argv[1], f) | |
im = Image.open(fname).save(fname) | |
print 'Compressing {} of {}'.format(i, len(files)) |
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
from bottle import route, run, template, request | |
index_template = '''<table width=100% height=100% border=1> | |
<tr> | |
<td width=50%> | |
<textarea style="width: 100%; height: 100%"></textarea> | |
</td> | |
<td> | |
<div id="result"> | |
</div> |
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
# [Pelican](http://docs.getpelican.com/) is a static site generator. I'm using it for building [my own website](http://mtayseer.net/). | |
# To make the editing experience easier, I created this script to launch a webserver to view generated output & at the same time watch | |
# the content for changes & rebuild it. | |
# | |
# I'm using [Bottle](http://bottlepy.org/) for the webserver & [watchdog](https://pythonhosted.org/watchdog/) to watch directory | |
# | |
from bottle import route, run, static_file | |
from watchdog.observers import Observer | |
from watchdog.events import FileSystemEventHandler |
OlderNewer