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
""" | |
Decode a super-secret message | |
""" | |
import sys | |
from string import maketrans | |
# setup translation | |
in_wrds = "abcdefghijklmnopqrstuvwxyz" | |
out_wrds = "cdefghijklmnopqrstuvwxyzab" | |
trans_tbl = maketrans(in_wrds, out_wrds) |
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
# solution 1 - nested loops | |
temp = "" | |
f = open('mess.txt', 'r') | |
for l in f: | |
for c in l: | |
if c.isalpha(): | |
temp += c | |
print temp | |
# solution 2 - list comprehension |
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
import re | |
import gdata.photos.service | |
user = 'intakescreensinc' | |
service = gdata.photos.service.PhotosService() | |
tags = service.GetUserFeed(user=user, kind='tag').entry | |
cfs = re.compile("^(\d+)cfs$") | |
cfs_sizes = [] | |
for tag in tags: |
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
import re | |
import gdata.photos.service | |
class Collection: | |
def __init__(self, username): | |
self.feed = "/data/feed/api/user/%s" % username | |
self.service = gdata.photos.service.PhotosService() | |
def fetch(self, feed): | |
"""Make a call to the photo service.""" | |
return self.service.GetFeed(feed) |
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 "bundler/capistrano" | |
# use ssh key from local system | |
ssh_options[:forward_agent] = true | |
default_run_options[:pty] = true | |
set :user, "markhayes" | |
# set :password, "" | |
set :domain, "markhayes.webfactional.com" | |
set :application, "trackr" |
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
#!/usr/bin/env ruby | |
require 'optparse' | |
options = {} | |
optparse = OptionParser.new do |opts| | |
opts.on('-f', '--file FILE', 'Specify espresso output file') do |file| | |
options[:espresso_file] = file | |
end | |
opts.on('-h', '--help', 'View help') do |
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 'test/unit' | |
class Node | |
attr_accessor :value, :lchild, :rchild | |
def initialize(val=nil) | |
@value = val | |
end | |
def depth |
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 | |
#rotate characters n positions to left or right | |
def rotate(n) | |
alpha = ("a".."z").to_a + ("A".."Z").to_a | |
self.tr(alpha.join(""), alpha.rotate(n).join("")) | |
end | |
def rotate!(n) | |
replace rotate(n) | |
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
# convert n from base10 to base2 | |
# return base10 representation of | |
# k least significant bits | |
# $> bitwise_chop(29,3) => 5 | |
def bitwise_chop(n,k) | |
n.to_s(2).slice(-k,k).to_i(2) | |
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
require 'rubygems' | |
require 'open-uri' | |
require 'sinatra' | |
get '/signature.png' do | |
content_type 'image/png' | |
File.open("stats.txt", "a") {|f| f.write request.env.select {|k,v| ["HTTP_USER_AGENT", "REMOTE_HOST"].include? k}} | |
open("http://s3.deployfx.com/mhayes-resume/images/mhayes-signature.png") {|image| image.read} | |
end |