Skip to content

Instantly share code, notes, and snippets.

View brandonhilkert's full-sized avatar

Brandon Hilkert brandonhilkert

View GitHub Profile
class EmployerManager
attr_accessor :name, :increment_count, :industry, :linkedin_id
def initialize(name, increment_count = false)
@name, @increment_count = name, increment_count
@industry = nil
@linkedin_id = nil
end
def find_or_create
class PostsController < ActionController::Base
def create
Post.create(post_params)
end
def update
Post.find(params[:id]).update_attributes!(post_params)
end
private
@brandonhilkert
brandonhilkert / mongo.rb
Created March 6, 2012 14:32
How to delete whole object from embedded doc
# I have the following:
# User (Doc) => goal_matches (Array) => Goal Match (Embedded Doc)
# Goal Match looks like this:
key :user_id, ObjectId
key :matches, Array
key :weight, Integer
key :matched_employers, Array
@brandonhilkert
brandonhilkert / spec_helper.rb
Created March 8, 2012 16:49
Spec helper for rspec testing
require 'spork'
Spork.prefork do
# Loading more in this block will cause your tests to run faster. However,
# if you change any configuration or code from libraries loaded here, you'll
# need to restart spork for it take effect.
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
@brandonhilkert
brandonhilkert / gist:2022924
Created March 12, 2012 15:53
Mongo query comparison
# Imagine we have something like:
class User
include MongoMapper::Document
key :first_name, String
key :last_name, String
key :connections, Array
key :interests, Array
key :skills, Array
class PhotoUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
storage :fog
process :resize_to_fit => [200, 200]
version :normal do
process :resize_to_fill => [100, 100]
end
@brandonhilkert
brandonhilkert / hack.sh
Created March 31, 2012 12:10
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
##################
# INSTALL STATSD
##################
sudo apt-get install git-core python-software-properties build-essential
sudo apt-get -y install python-software-properties debhelper
sudo apt-add-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get -y install nodejs npm
@brandonhilkert
brandonhilkert / gist:3012335
Created June 28, 2012 16:33
HStore rake db:test:prepare error
$ rake db:test:prepare --trace
** Invoke db:test:prepare (first_time)
** Invoke db:abort_if_pending_migrations (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:abort_if_pending_migrations
** Execute db:test:prepare
** Invoke db:test:load (first_time)
** Invoke db:test:purge (first_time)
** Invoke environment
irb(main):011:0> UserMailer.methods.include?(:delay)
=> true
irb(main):012:0> UserMailer.delay.new_message(11)
TypeError: can't dump anonymous class Class
from /Users/bhilkert/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:211:in `visit_Class'
from /Users/bhilkert/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:63:in `accept'
from /Users/bhilkert/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:246:in `block in visit_Array'
from /Users/bhilkert/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:246:in `each'
from /Users/bhilkert/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:246:in `visit_Array'
from /Users/bhilkert/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/psych/visitors/yaml_tree.rb:63:in `accept'