Skip to content

Instantly share code, notes, and snippets.

Avatar

Joe Sak joemsak

View GitHub Profile
View reading_writing.py
from twython import Twython
import time
twitter = Twython('consumer_key', 'consumer_secret', 'oauth_key', 'oauth_secret')
img = open('album_artwork.jpeg', 'rb')
filepath = 'tmp/replied_status_ids.txt'
while True:
mention = twitter.get_mentions_timeline()[0]
status_id = mention['id']
View .vimrc
function! RunTests(filename)
" Write the file and run tests for the given filename
if filereadable(@%)
:wa
else
:w
endif
:silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
:silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
:silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
View mention.py
import sqlalchemy.orm
sqlalchemy.orm.ScopedSession = sqlalchemy.orm.scoped_session
from elixir import *
metadata.bind = "postgres://humanure@localhost/humanure_dev"
metadata.bind.echo = True
class Mention(Entity):
status_id = Field(Integer)
View .vimrc
if match(a:filename, '\.feature$') != -1
exec ":!script/features " . a:filename
else
if filereadable("script/test")
exec ":!script/test " . a:filename
elseif filereadable("Gemfile")
if match(a:filename, '_test') != -1
exec ":!bundle exec rake test " . a:filename
else
exec ":!bundle exec rspec --color " . a:filename
View document.rb
module Eader
class Document
attr_reader :doc
def initialize(path)
file = open(path)
@doc = xml_doc_class.parse(file)
end
def series
View short_url.rb
class ShortUrl
def self.create(url)
url.shortened_hash = first_five_of_sha256(url)
url.save
end
def self.for(url)
ENV['HOSTNAME'] + url.shortened_hash
end
View default_config.rb
def config
conf = default_config
path = 'config/writer.yml'
if File.exist?(path)
config_file = File.open(path)
user_config = YAML.load(config_file)
conf = conf.merge(user_config)
end
View ui_menu.rb
module BaseballStats
module UI
class PlainTextMenu
attr_reader :reporters, :printer, :input_device
# dependency injection
def initialize(reporters, printer, input_device)
@reporters = reporters
@printer = printer
@input_device = input_device
View chronic_spec.rb
require 'chronic'
describe Chronic do
def assert_parsed(input, bool = true)
(Chronic.parse(input) != nil).should == bool
end
it "doesn't seem to like timezones" do
assert_parsed('11/15/2013 11:56 PST', false)
assert_parsed('11/15/2013 11:56 -0400', false)
View view_helper.rb
module Rehearsal
module ViewHelpers
def rehearsal_banner(message = nil)
return unless rehearsing_with_banner?
content_tag :div, :id => 'rehearsal-banner' do
if block_given?
yield
else
message || default_message