Skip to content

Instantly share code, notes, and snippets.

View jjhageman's full-sized avatar

Jeremy Hageman jjhageman

View GitHub Profile
@jjhageman
jjhageman / user_steps.rb
Created September 14, 2009 16:02
Sample Cucumber step file for User models using Authlogic
module UserHelpers
def current_user_session
return @current_user_session if defined?(@current_user_session)
@current_user_session = UserSession.find
end
def current_user
return @current_user if defined?(@current_user)
@current_user = current_user_session && current_user_session.user
end
@jjhageman
jjhageman / item_controller.rb
Last active September 24, 2018 01:33
Controller to handle JSON API POSTs
class Api::ItemsController < ApplicationController
respond_to :json
def create
begin
puts "params: #{params}"
post_data = params[:item_post].is_a?(String) ? JSON.parse(params[:item_post]) : params[:item_post]
user_data = post_data['user'] || {}
item_data = post_data['item'] || {}
@jjhageman
jjhageman / item_image.rb
Created June 3, 2011 20:59
Extracting Geolocation Image Data with Carrierwave and RMagick on Heroku
class ItemImage < ActiveRecord::Base
belongs_to :item
mount_uploader :image, ImageUploader
before_save :extract_geolocation
def extract_geolocation
img = Magick::Image.read(image)[0] rescue nil
@jjhageman
jjhageman / String+Utils.swift
Created September 20, 2017 23:27
Swift 3 snake_case to camelCase
extension String {
var camelCased: String {
let items = self.components(separatedBy: "_")
return items[1...].reduce(items[0].lowercased(), { $0 + $1.capitalized })
}
}