Skip to content

Instantly share code, notes, and snippets.

View invisiblefunnel's full-sized avatar

Danny Whalen invisiblefunnel

View GitHub Profile
diff --git a/db/schema.rb b/db/schema.rb
index 81ac000..6680ff5 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -53,13 +53,6 @@ ActiveRecord::Schema.define(version: 20131105015734) do
t.string "call_source"
end
- create_table "most_recent_outcome_choices", id: false, force: true do |t|
- t.integer "id"
# https://github.com/rails/rails/blob/e20dd73df42d63b206d221e2258cc6dc7b1e6068/activesupport/lib/active_support/core_ext/object/try.rb
class Object
def try(*a, &b)
if a.empty? && block_given?
yield self
else
public_send(*a, &b) if respond_to?(a.first)
end
end
@invisiblefunnel
invisiblefunnel / assert-env.rb
Created November 18, 2013 19:56
Consistent means of indicating environment variables required during runtime
def ENV.assert(key)
ENV[key] or raise "missing required ENV value for key: #{key}"
end
@invisiblefunnel
invisiblefunnel / Rakefile
Created November 19, 2013 20:57
Run RSpec suite as default rake task
task :default do
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
Rake::Task[:spec].invoke
end
@invisiblefunnel
invisiblefunnel / requester_spec.rb
Created November 19, 2013 23:46
Infinite redirects with FakeWeb
require 'spec_helper'
describe Requester do
let(:requester) do
Class.new{ include Requester }.new
end
describe ".get" do
it "limits the number of redirects to follow" do
uri = 'http://www.example.com/_status'
def timeout(seconds = nil)
timer_thread = Thread.start(Thread.current, Time.now) { |app_thread, start|
sleep(seconds)
app_thread.raise 'Execution timed out'
}
yield
ensure
timer_thread.kill
timer_thread.join
@invisiblefunnel
invisiblefunnel / background_mailer.rb
Created December 9, 2013 02:18
Mailers with Sidekiq
require 'devise/mailer'
#
# General mailer proxy class to send emails in the background w/ Sidekiq
#
class BackgroundMailer
def self.reset_password_instructions(record, token, opts={})
new(Devise::Mailer, :reset_password_instructions, record, token, opts)
end
def initialize(mailer_klass, method, *args)
@invisiblefunnel
invisiblefunnel / foo.rb
Last active December 31, 2015 04:59
Show Code Climate issue
# The following is recognized as removing Topic::Error and adding Topic::Topic::Error.
# Changing from this:
module Topic
class Error < StandardError; end
end
# to this:
@invisiblefunnel
invisiblefunnel / rename.rake
Last active April 23, 2019 06:31
Rake task for renaming a Rails app
desc "Rename this application"
task :rename, [:name] => :environment do |t, args|
files = Dir.glob(%w(rb yml).map{ |ext| Rails.root.join("**/*.#{ext}") } + %w(Rakefile))
before = Rails.application.class.name.split('::').first
after = args.name or raise "Pass a new name as an argument: $ rake rename[MyCivicApp]"
files.each do |file|
# Swap in the new name
renamed = File.read(file).gsub(/#{before}/, after).gsub(/#{before.underscore}/, after.underscore)
# Write the updated contents
We can make this file beautiful and searchable if this error is corrected: Illegal quoting in line 2.
id label prediction negative_probability neutral_probability positive_probability text
0-1391107570 positive 0.172 0.294 0.534 Overheard: @dget browsing Google font pairings. "Something tells me you don't always want Creepster." #cfa2014
1-1391109571 neutral 0.022 0.936 0.042 Hard not to think of http://t.co/fPn9J4HXLL while practicing app demos. (cc @dget, @mollyampersand) #cfa2014
2-1391109768 neutral 0.023 0.906 0.071 RT @fureigh: Hard not to think of http://t.co/fPn9J4HXLL while practicing app demos. (cc @dget, @mollyampersand) #cfa2014
3-1391110031 neutral 0.041 0.844 0.115 It's safe for work, I swear: http://t.co/j2gkzlaroF #catsforamerica #cfa2014 (cc @_jden)
4-1391110164 neutral 0.037 0.703 0.26 *giggle* RT @fureigh: It's safe for work, I swear: http://t.co/H7yga8fFHX #catsforamerica #cfa2014 (cc @_jden)
5-1391110333 neutral 0.378 0.501 0.121 @fureigh @_jden OH GOD #CFA2014 IS GOING DOWN THE @MAXOGDEN PATH #teamcorgi
6-1391111279 neutral 0.046 0.741 0.213 Streetreel, the 1st CfA app project pit