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
# 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): |
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
# 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 |
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
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 |
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
# 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 |
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
// 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"); |
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
# 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} |
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
$(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") |
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
" 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 |
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
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") |
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
class String | |
def anagram | |
self.split(//).permutation.map { |a| a.join } | |
end | |
end |
OlderNewer