Skip to content

Instantly share code, notes, and snippets.

View alexalemi's full-sized avatar

Alex Alemi alexalemi

View GitHub Profile
@alexalemi
alexalemi / moebius2.py
Created August 11, 2011 22:27
Alternative Moebius Transformation
""" An alternative way to do the moebius transformation,
using scipy.ndimage.geometric_transform,
that interpolates the points for a smoother transformation """
from pylab import *
from numpy import *
zp=[157+148j, 78+149j, 54+143j]; # (zs) the complex point zp[i]
wa=[147+143j, 78+140j, 54+143j]; # (ws) will be in wa[i]
@alexalemi
alexalemi / primefactors2.py
Created August 11, 2011 22:48
Alternative Prime Factors
from itertools import chain
def factors2(n):
result = []
# test 2 and all of the odd numbers
# xrange instead of range avoids constructing the list
for i in chain([2],xrange(3,n+1,2)):
s = 0
while n%i == 0: #a good place for mod
n /= i
@alexalemi
alexalemi / maps.html
Created August 16, 2011 19:17
Scaled Planetary Positions Google Map
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=0.5, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Planet Locations</title>
<link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function initialize() [
@alexalemi
alexalemi / links.py
Created August 24, 2011 20:50
A Dictionary of Links
@alexalemi
alexalemi / twittercompress.py
Created August 31, 2011 03:24
Twitter Compression
""" A script to attempt the compression of written english
to the chinese character set """
import os
from collections import OrderedDict
from math import log
import itertools
from collections import Counter
@alexalemi
alexalemi / palindrome.py
Created October 3, 2011 15:53
Longest Palindrome
import difflib
def longest_palindrome(text):
matcher = difflib.SequenceMatcher(None,text,text[::-1])
length = len(text)
a,b,k = matcher.find_longest_match(0,length-1,0,length-1)
return text[a:a+k]
@alexalemi
alexalemi / circle.py
Created October 12, 2011 22:50
python antialiased circles
#! /usr/bin/env python
# -*- coding: latin-1 -*-
import math
characters = [32,0x2591,0x2592,0x2593,0x2588]
breakpoints = [0.1,0.177,0.316,0.563]
#reakpoints = [0.2,0.4,0.6,0.8]
def raster(x,y,R,center,SIGMA=1.5):
@alexalemi
alexalemi / permuteeven.py
Created November 3, 2011 21:10
Checkerboard Permutation
import numpy as np
from itertools import permutations
foo = np.arange(25).reshape(5,5)
def permuteevens(A):
mask = np.fromfunction(lambda i,j: (i+j)%2==0, A.shape )
vals = A[mask]
for p in permutations(vals):
A[mask] = p
@alexalemi
alexalemi / ruptime.py
Created November 8, 2011 04:18
Ruptime CGI-Script
#!/usr/bin/env python
import cgi
import os
from collections import namedtuple
uptime_tuple= namedtuple('uptime','up time users load_1 load_5 load_15')
hosts = ['ept','dain','heveled','kempt','gruntled']
@alexalemi
alexalemi / gravitysim.pde
Created November 16, 2011 21:54
GravitySim
//Make the rocket object
Rocket myRocket;
//Define planets arraylist
planets = new ArrayList();
// Global variables
//Strength of gravity
float gravstrength = -0.01;
// Thrust strength
float dv = 0.06;