Skip to content

Instantly share code, notes, and snippets.

View tlehman's full-sized avatar

Tobi Lehman tlehman

View GitHub Profile
@tlehman
tlehman / bar.rb
Created June 27, 2012 17:41
ActiveRecord silliness
[6] pry(main)> p.gimme :title
=> "Streetcar Feasibility Study"
[7] pry(main)>
@tlehman
tlehman / st2_packageman.py
Created July 11, 2012 16:14
Sublime Text 2 Package manager install
import urllib2,os; pf='Package Control.sublime-package'; ipp=sublime.installed_packages_path(); os.makedirs(ipp) if not os.path.exists(ipp) else None; urllib2.install_opener(urllib2.build_opener(urllib2.ProxyHandler())); open(os.path.join(ipp,pf),'wb').write(urllib2.urlopen('http://sublime.wbond.net/'+pf.replace(' ','%20')).read()); print 'Please restart Sublime Text to finish installation'
@tlehman
tlehman / gist:3108748
Created July 14, 2012 01:43
dyld error
~/git/KAI/kittelson.com (master)> rake spec
Resolved collector.newrelic.com to 204.93.223.153
/Users/tobi/.rvm/rubies/ruby-1.9.3-p125/bin/ruby -S rspec ./spec/helpers/application_helper_spec.rb ./spec/lib/searchable_spec.rb ./spec/mailers/website_mailer_spec.rb ./spec/models/announcement_spec.rb ./spec/models/candidate_spec.rb ./spec/models/employee_spec.rb ./spec/models/next_step_spec.rb ./spec/models/office_spec.rb ./spec/models/page_spec.rb ./spec/models/photo_spec.rb ./spec/models/project_spec.rb ./spec/models/setting_spec.rb ./spec/models/user_session_spec.rb ./spec/models/user_spec.rb ./spec/requests/admin_spec.rb ./spec/requests/candidates_spec.rb ./spec/requests/comment_spec.rb ./spec/requests/search_spec.rb
Resolved collector.newrelic.com to 204.93.223.153
...dyld: Library not loaded: /usr/local/lib/libtiff.3.dylib
Referenced from: /usr/local/bin/identify
Reason: image not found
dyld: Library not loaded: /usr/local/lib/libtiff.3.dylib
Referenced from: /usr/local/bin/identify
Reason: image not
@tlehman
tlehman / tagspamcomments.rb
Created July 27, 2012 18:44
Tag spam comments
# tag_spam_comments_in looks at a database and tags the records of
# the 'comments' table that are most likely to be spam.
# NOTE: This is meant to be run on the same system as the database
#
# Dependencies:
# gems: [sequel, spellchecker, mysql2]
# apps: [aspell, mysql]
# NOTE: aspell must have the 'en' dictionary installed
require 'rubygems'
require 'sequel'
@tlehman
tlehman / disquscomments.rb
Created July 30, 2012 21:07
Disqus comment xml output
require 'sequel'
require 'builder'
def export_comments_to_wxr(dbinfo)
db = Sequel.connect("mysql2://#{dbinfo[:user]}:#{dbinfo[:pass]}@localhost/#{dbinfo[:dbname]}")
comments = db[:posts].graph(:comments, :post_id=>:id).filter(:spam=>0).to_a
posts = db[:posts].to_a
xml = Builder::XmlMarkup.new(:target => STDOUT, :indent => 2)
xml.rss :version=>"2.0", "xmlns:content" => "http://purl.org/rss/1.0/modules/content/",
@tlehman
tlehman / upload_subscribers.rb
Created August 2, 2012 23:37
Upload subscribers
require 'csv'
require 'sequel'
def get_subscribers(filename)
subscribers = []
CSV.foreach(File.expand_path(filename)) do |row|
subscriber = {}
subscriber[:name] = "#{row[0]} #{row[1]}"
subscriber[:company] = row[2]
subscriber[:email] = row[3]
@tlehman
tlehman / perform_deliver_file.rb
Created August 3, 2012 22:34
ActionMailer method perform_delivery_file
class ActionMailer::Base
def perform_delivery_file(mail)
File.open("#{RAILS_ROOT}/tmp/mails/#{mail.to}.html", 'a') { |f| f.write(mail) }
end
end
config.action_mailer.delivery_method = :file
@tlehman
tlehman / GetDotNetVersions.cs
Created August 7, 2012 22:02
Get DotNet Versions
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;
namespace GetDotNetVersions
{
class Program
{
@tlehman
tlehman / get-dotnet-versions.bat
Created August 14, 2012 22:07
Get DotNet Versions (independent of .NET)
REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP"
@tlehman
tlehman / blob-in-to-mm.py
Created August 16, 2012 19:34
Convert inches cubed to milimeters cubed (for use in excel)
def blob_in_to_mm(s):
return reduce(lambda l,r: l+" x "+r, map(str, map(lambda x: x*25.4, map(float, s.split(" x ")))), "")[3:-1]