Skip to content

Instantly share code, notes, and snippets.

(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);
@mtayseer
mtayseer / euler_2.py
Last active August 29, 2015 13:55
Project euler #2
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)
import base64;exec base64.b64decode('ZGVmIGZpYm9uYWNjaShtYXgpOgogICAgYSwgYiA9IDEsIDIKICAgIHdoaWxlIGEgPCBtYXg6CiAgICAgICAgeWllbGQgYQogICAgICAgIGEsIGIgPSBiLCBhK2IKCnByaW50IHN1bSh4IGZvciB4IGluIGZpYm9uYWNjaSg0MDAwMDAwKSBpZiB4ICUgMiA9PSAwKQ==')
#
# 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
#
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
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
# 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:
@mtayseer
mtayseer / compress_images.py
Created February 23, 2014 11:55
Given a directory, compress all images in it
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))
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>
@mtayseer
mtayseer / watch_n_serve.py
Last active August 29, 2015 13:57
Launch a webserver to view generated output & at the same time watch the content for changes & rebuild it.
# [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