Skip to content

Instantly share code, notes, and snippets.

View robrasmussen's full-sized avatar

Robert Rasmussen robrasmussen

View GitHub Profile
@robrasmussen
robrasmussen / gist:25e296e9cf83af01ade8
Created April 28, 2015 21:13
Unify UserAgent for API and webviews.
// Make webviews share the same User-Agent as the API client.
NSUserDefaults.standardUserDefaults().registerDefaults(["UserAgent": Alamofire.Manager.defaultHTTPHeaders["User-Agent"]!])
@robrasmussen
robrasmussen / gist:230711013c095e9ab9ed
Created April 23, 2015 14:56
Spirograph playground based on Erica Sadun's
import UIKit
import Foundation
import XCPlayground
struct SpirographGenerator : GeneratorType {
var pointOffset, dTheta, dR, minorRadius, majorRadius : Double
var theta = 0.0
typealias Element = CGPoint

Keybase proof

I hereby claim:

  • I am robrasmussen on github.
  • I am robrasmussen (https://keybase.io/robrasmussen) on keybase.
  • I have a public key whose fingerprint is 1743 BA64 EE52 7FAD 139A FC72 1055 8CB5 62AE B568

To claim this, I am signing this object:

@robrasmussen
robrasmussen / AppDelegate.swift
Last active December 24, 2015 02:32
Example for how to set up a UIAppearance proxy specific to one controller in Swift
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
UIButton.appearanceProxyIn(ViewController).backgroundColor = UIColor.redColor()
UIButton.appearanceProxyIn(ViewController).tintColor = UIColor.yellowColor()
@robrasmussen
robrasmussen / playlist_101x.rb
Created November 30, 2012 18:35
Show # of plays by artist on 101x
require 'nokogiri'
require 'open-uri'
puts Nokogiri::HTML(open("http://www.101x.com/broadcasthistory.aspx")).xpath("//td[@class='broadcast txtMini']/span").inject(Hash.new(0)) {|memo,song_node| memo[song_node.text.strip.split(" - ").last] += 1; memo }.to_a.sort_by {|x| x.last }.reverse.collect {|x| x.reverse.join(" - ") }
@robrasmussen
robrasmussen / gist:3715461
Created September 13, 2012 16:17
thread dump in config.threadsafe! mode
Thread 3831: (state = BLOCKED)
- java.util.Collections$SynchronizedCollection.contains(java.lang.Object) @bci=6, line=1620 (Compiled frame)
- org.jruby.runtime.load.LoadService.featureAlreadyLoaded(org.jruby.RubyString) @bci=63, line=467 (Compiled frame)
- org.jruby.runtime.load.LoadService.require(java.lang.String) @bci=53, line=373 (Compiled frame)
- org.jruby.runtime.load.LoadService.lockAndRequire(java.lang.String) @bci=60, line=304 (Compiled frame)
- org.jruby.RubyKernel$6.load(org.jruby.Ruby) @bci=8, line=198 (Compiled frame)
- org.jruby.RubyModule$Autoload.getConstant(org.jruby.runtime.ThreadContext) @bci=45, line=3590 (Compiled frame)
- org.jruby.RubyModule.getAutoloadConstant(org.jruby.Ruby, java.lang.String) @bci=25, line=3420 (Compiled frame)
- org.jruby.RubyModule.resolveUndefConstant(org.jruby.Ruby, java.lang.String) @bci=3, line=2974 (Compiled frame)
- org.jruby.parser.StaticScope.getConstantInner(org.jruby.Ruby, java.lang.String, org.jruby.RubyModule) @bci=29, line=191 (Compiled frame)
@robrasmussen
robrasmussen / gist:3715398
Created September 13, 2012 16:09
Performance improvement for JRuby under Rails 3.2.x
# Put this at the bottom of config/boot.rb
# Defeat autoloading
require 'active_support/notifications/instrumenter'
require 'active_support/notifications'
require 'active_support/core_ext/string/output_safety'
require 'active_support/multibyte/unicode'
require 'active_support/concern'
require 'active_record/relation/finder_methods'
require 'active_record/relation/predicate_builder'
@robrasmussen
robrasmussen / gist:3715360
Created September 13, 2012 16:04
Fix for thread-safety bug in ActiveRecord::ConnectionAdapters::ConnectionPool
module ActiveRecord
module ConnectionAdapters
class ConnectionPool
def release_connection_with_synchronization(with_id = current_connection_id)
synchronize do
release_connection_without_synchronization(with_id)
end
end
alias_method_chain :release_connection, :synchronization
16:02:45,177 ERROR [org.torquebox.core.runtime] (http-localhost-127.0.0.1-8080-2) Error during execution: require %q(rack)
Rack::Builder.new{(
require %q(org/torquebox/web/rails/rackup)
run TorqueBox::Rails.app
)}.to_app: org.jruby.exceptions.RaiseException: (NoMethodError) undefined method `cattr_accessor' for ActionController::Dispatcher:Class
at #<Class:0x4d6e7b>.Dispatcher(/Users/robert/.rvm/gems/jruby-1.6.5.1@community19/gems/actionpack-2.3.11/lib/action_controller/dispatcher.rb:69) at Module.ActionController(/Users/robert/.rvm/gems/jruby-1.6.5.1@community19/gems/actionpack-2.3.11/lib/action_controller/dispatcher.rb:4) at #<Class:0x15f11e7>.(root)(/Users/robert/.rvm/gems/jruby-1.6.5.1@community19/gems/actionpack-2.3.11/lib/action_controller/dispatcher.rb:1) at org.jruby.RubyKernel.require(org/jruby/RubyKernel.java:1047) [jruby.jar:]
at #<Class:0x15f11e7>.(root)(/Users/robert/.rvm/gems/jruby-1.6.5.1@community19/gems/actionpack-2.3.11/lib/action_controller/dispatcher.rb:18) at org.jruby.RubyKernel.requi
12:54:20,115 INFO [org.torquebox.core.runtime] (Thread-2 (HornetQ-client-global-threads-774148213)) Created ruby runtime (ruby_version: RUBY1_9, compile_mode: JIT, app: frontend_02_13_2012_jruby, context: messaging) in 12.57s
12:54:20,550 ERROR [stderr] (Thread-2 (HornetQ-client-global-threads-774148213)) FutureResponder#respond: An error occured:
12:54:20,550 ERROR [stderr] (Thread-2 (HornetQ-client-global-threads-774148213)) uninitialized constant ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::PGconn
12:54:20,550 ERROR [stderr] (Thread-2 (HornetQ-client-global-threads-774148213)) /usr/local/jruby/lib/ruby/gems/1.8/gems/activesupport-2.3.11/lib/active_support/dependencies.rb:131:in `const_missing'
12:54:20,551 ERROR [stderr] (Thread-2 (HornetQ-client-global-threads-774148213)) /usr/local/jruby/lib/ruby/gems/1.8/gems/activerecord-2.3.11/lib/active_record/connection_adapters/postgresql_adapter.rb:941:in `connect'
12:54:20,551 ERROR [stderr] (Thread-2 (HornetQ-client-global-threads-774148213)) /usr/loca