Skip to content

Instantly share code, notes, and snippets.

View tlehman's full-sized avatar

Tobi Lehman tlehman

View GitHub Profile
@tlehman
tlehman / imgscr.py
Created December 14, 2011 00:04
imgscraper
# a simple image scraper by tlehman
# this code is too basic for me to care what you do with it, so have at it.
#
from urllib import urlopen
from BeautifulSoup import BeautifulSoup
# usage: getimg(url, filetype)
# return will be list of src attributes of a tags in page
# referred to by url
def getimg(url, filetype):
@tlehman
tlehman / asciibrot.py
Created December 31, 2011 01:16
an ASCII Mandelbrot set in python
# code golf: generating a Mandelbrot set in ASCII
# Height and Width of terminal
H = 40; W = 80;
def coord_to_complex(i, j):
""" map the region [0,H)x[0,W) into the
complex plane """
re = float(4*i)/float(W-1) - 2.0 # real component
im = float(2.2*j)/float(H-1) - 1.1 # imaginary component
@tlehman
tlehman / ComplexNumber.rb
Created February 26, 2012 20:09
ComplexNumber data type
class ComplexNumber
attr_accessor :re, :im
def initialize(re, im)
# when ComplexNumber.new is called, initialize
# is run after the object is instantiated
@re = re
@im = im
end
@tlehman
tlehman / Integer_ordinal_indicator.rb
Created March 4, 2012 22:43
Integer patch: ordinal indicator
# Gives a string for the suffix of the ordinal number
# example usage:
# 2.suffix => "nd"
# 11.suffix => "th"
# 21.suffix => "st"
#
# TODO: Figure out what to do about 101?
# by tlehman: Sun 03/04/2012
class Integer
def suffix
@tlehman
tlehman / imgScaleToggle.js
Created March 17, 2012 00:43
Make images larger when clicked, and restores original size on next click, (depends on jQuery or similar library)
// imgscale by tlehman: Fri 03/16/2012
// toggles the size of images by some factor, defined as the variable "scale"
//
// NOTE: To change how much an image scales, just set the "scale" variable to
// some number, with 1.0 being 100%, 2.0 being 200% ... etc
//
// select images
var imgs = $("img");
@tlehman
tlehman / sow_totalhours.rb
Created March 27, 2012 01:01
find hours left in sow.txt file
# a very inelegant script to find the total number of hours in the scope of work file
# by tlehman
# get the lines from the sow file
file = File.open('sow.txt')
lines = file.readlines
file.close
# join list of strings and regex out the hours, then turn those strings into ints
hours_list = lines.join.scan(/(\d+) hours/i).map {|hs| hs.first.to_i}
$(document).ready =>
$("#ongoing").bind 'click', (event) =>
end_dates = $("select[id^=project_end_date]")
# toggle the disabled attribute of the end date fields
if ($("#ongoing").attr("checked") != undefined)
end_dates.attr("disabled", true)
else
end_dates.removeAttr("disabled")
@tlehman
tlehman / .vimrc
Created April 2, 2012 00:05
My vim configuration file
" tlehman's vimrc as of Wed 03/28/2012
"
" Pathogen.vim is a plugin by tpope available here: https://github.com/tpope/vim-pathogen
" It allows for vim plugins be easily installed in their own private
" directories.
"
" To install pathogen, (Assuming vim is installed), create an autoload and
" bundle directory:
" mkdir -p ~/.vim/autoload ~/.vim/bundle
" Then curl the file into autoload
@tlehman
tlehman / threeio.rb
Created June 4, 2012 01:56
List all available three-character .io domain names (depends on colorize)
require 'net/http'
require 'colorize'
# find all available three-letter .io domains
alph = ('a'..'z')
# generate all three-character strings
threes = alph.map { |a| alph.map { |b| alph.map { |c| "#{a}#{b}#{c}" } } }.flatten
def io_available?(tld)
url = URI.parse("http://www.nic.io/cgi-bin/whois?query=#{tld}.io")
@tlehman
tlehman / anagram.rb
Created June 11, 2012 06:54
anagram.rb
class String
def anagram
self.split(//).permutation.map { |a| a.join }
end
end