Skip to content

Instantly share code, notes, and snippets.

View aausch's full-sized avatar
💭
everyday I'm hustlin'

Alex Ausch aausch

💭
everyday I'm hustlin'
View GitHub Profile
@aausch
aausch / StaticFileScanner.py
Last active December 27, 2015 06:49
Serves static files from multiple local directories at a single external url
# Serves static files from multiple local directories at a single external url
# usage demo: https://gist.github.com/aausch/7348230
#
# Copyright 2013, Alex Ausch
# Free to use under attribution license: http://creativecommons.org/licenses/by/2.0/ca/
from twisted.web.resource import Resource
from twisted.web.static import File
class StaticFileScanner(Resource):
@aausch
aausch / triangle_dict.py
Last active December 22, 2016 00:26
Generates a sequence of triangle numbers
# Copyright 2013, Alex Ausch
# Free to use under attribution license: http://creativecommons.org/licenses/by/2.0/ca/
try:
from collections.abc import Mapping
except ImportError:
from collections import Mapping
class TriangleDictionary(Mapping):
@aausch
aausch / euler_9.py
Last active December 24, 2015 03:39
http://projecteuler.net/problem=9 A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, a2 + b2 = c2 For example, 32 + 42 = 9 + 16 = 25 = 52. There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc.
# Copyright 2013, Alex Ausch
# Free to use under attribution license: http://creativecommons.org/licenses/by/2.0/ca/
for b in range(1,500):
c = (- b ** 2 + 1000 * b - 500000)/(b-1000)
a = (c**2 - b**2)**0.5
if (a+b+c) == 1000 and int(a) == a and a > 0:
print a,b,c
print a * b * c
@aausch
aausch / palindrome_detector.py
Last active December 24, 2015 00:59
http://projecteuler.net/problem=4 A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. Find the largest palindrome made from the product of two 3-digit numbers.
# Copyright 2013, Alex Ausch
# Free to use under attribution license: http://creativecommons.org/licenses/by/2.0/ca/
def is_palindrome(num):
palindrome = str(num)
return palindrome == palindrome[::-1]
def fn(n):
max_palindrome = 1
for x in range(n,1,-1):
@aausch
aausch / prime_set.py
Last active December 23, 2015 23:29
A read-only dictionary, which only contains prime numbers
# inspired by http://ceasarjames.wordpress.com/2011/07/10/the-quadratic-sieve/
#
# Copyright 2013, Alex Ausch
# Free to use under attribution license: http://creativecommons.org/licenses/by/2.0/ca/
try:
from collections.abc import Mapping
except ImportError:
from collections import Mapping
@aausch
aausch / fib_dict.py
Last active December 23, 2015 23:09
A read-only dictionary, storing fibonacci numbers
# Copyright 2013, Alex Ausch
# Free to use under attribution license: http://creativecommons.org/licenses/by/2.0/ca/
try:
from collections.abc import Mapping
except ImportError:
from collections import Mapping
class FibDict(Mapping):
"""A FibDict object stores the Fibonnaci sequence, mapping numbers
@aausch
aausch / script-fu-overlay.scm
Last active September 4, 2019 00:10
automatically overlaying two images, using Gimp
;; script for automatically overlaying two images,
;; for comparison, in gimp.
;;
;; 1. save the file in your scripts directory
;; (/Applications/Gimp.app/Contents/MacOS/Resources/share/gimp/2.0/scripts/ or
;; /Users/[user]/Library/Application Support/GIMP/2.8/plug-ins on my mac)
;; 2. generate two images to compare
;; 3. run:
;; bash: /Applications/Gimp.app/Contents/MacOS/gimp-2.8 -b '(script-fu-overlay "image1.pdf" "image2.jpg")'
;;
@aausch
aausch / recursive_touch.py
Last active December 23, 2015 00:59
Python script for running touch on a list of directories, and their contents
#!/usr/bin/python
#
# run with: python recursive_touch.py <directory_name>
# touches all contents of <directory_name>, and recurses into subdirectories.
# WARNING! don't run unless you actually intend to do all that touching.
# some things, should not be touched.
#
# Copyright 2013, Alex Ausch
# Free to use under attribution license: http://creativecommons.org/licenses/by/2.0/ca/
#