Skip to content

Instantly share code, notes, and snippets.

View jamonholmgren's full-sized avatar

Jamon Holmgren jamonholmgren

View GitHub Profile
class FailureApp < Devise::FailureApp
def respond
# We override Devise's handling to throw our own custom errors on AJAX auth failures,
# because Devise provides no easy way to deal with them:
if request.xhr? && (warden_message == :unconfirmed || warden_message == :invalid)
if warden_message == :unconfirmed
flash.now[:alert] = "You need to confirm your account before continuing."
elsif warden_message == :invalid
user = Store::User.where(email: params[:user][:email].to_s).first

Keybase proof

I hereby claim:

  • I am jamonholmgren on github.
  • I am jamon (https://keybase.io/jamon) on keybase.
  • I have a public key whose fingerprint is D738 5A6B BFCE 3E63 A066 7EE4 97DC 65B8 5AAC A688

To claim this, I am signing this object:

@jamonholmgren
jamonholmgren / case-switch-bm.rb
Last active August 29, 2015 13:58
case-switch-bm.rb
require 'benchmark'
def with_if_else(symbol)
if symbol == :success
'alert-success'
elsif symbol == :error
'alert-danger'
elsif symbol == :warn
'alert-warning'
elsif symbol == :info
@jamonholmgren
jamonholmgren / chaining-1.rb
Last active August 29, 2015 13:58
Chaining styles.
school.schools_users
.joins("LEFT JOIN users ON users.id = schools_users.user_id")
.where(self.filters)
.where(self.search_string)
.order(order)
class AppDelegate < PM::Delegate
def on_load(app, options)
open_slide_menu MainScreen.new(nav_bar: true), left: LeftScreen.new(nav_bar: true), right: RightScreen.new(nav_bar: true)
end
# Docs here: http://cocoadocs.org/docsets/MMDrawerController/0.5.3/Classes/MMDrawerController.html
def open_slide_menu(middle_screen, sides={})
middle = middle_screen && middle_screen.navigationController || middle_screen
ESPN_MOCK_RESPONSE = {
"resultsLimit"=>10,
"resultsCount"=>271,
"resultsOffset"=>0,
"timestamp"=>"2014-05-18T01:50:05Z",
"status"=>"success",
"feed"=>[{"id"=>10310,
"source"=>"ESPN.com",
"premium"=>true,
"links"=>{"web"=>{"href"=>"http://insider.espn.go.com/blog/ncbrecruiting/on-the-trail/post?id=10310&ex_cid=espnapi_public"},
class MyObj
def now(&callback)
return callback.call @my_ivar if @my_ivar
Dispatch::Queue.new("a").async do
sleep 0.1 # simulate an http response
Dispatch::Queue.main.sync do
@my_ivar = { result: "real" }
callback.call @my_ivar
end
import UIKit
import ProSwift
class HomeScreen: ProSwiftScreen {
let title = "Home Screen"
func onLoad() {
open(OtherScreen(navBar: true))
}
}
class TeamsScreen < PM::GroupedTableScreen
title "NBA Teams"
def table_data
[{
title: "Atlantic",
cells: [
{ title: "Boston Celtics", action: :select_team, arguments: { team: "Boston Celtics" } },
{ title: "Brooklyn Nets", action: :select_team, arguments: { team: "Brooklyn Nets" } },
{ title: "New York Knicks", action: :select_team, arguments: { team: "New York" } },
class Object
def set_if(prop, val)
send "#{prop}=", val unless val.nil?
end
end
r = Struct.new(:item).new("wat")
r.set_if(:item, "no")
r.item # => "no"
r.set_if(:item, nil)