Skip to content

Instantly share code, notes, and snippets.

View nickhoffman's full-sized avatar

Nick Hoffman nickhoffman

  • Toronto, Canada
View GitHub Profile
@nickhoffman
nickhoffman / setup-statsd.sh
Created April 19, 2011 16:16 — forked from collegeman/setup-statsd.sh
Turn an Ubuntu 10.04 linode into a StatsD/Graphite server
# install git
sudo apt-get install g++ curl libssl-dev apache2-utils
sudo apt-get install git-core
# download the Node source, compile and install it
git clone https://github.com/joyent/node.git
cd node
./configure
make
sudo make install
# install the Node package manager for later use
@nickhoffman
nickhoffman / DB stuff
Created June 8, 2011 14:30
pcalendar joins stuff
rails g scaffold user name:string
rails g scaffold prediction title:string
rails g scaffold position believes_it:boolean
rails g migration position_belongs_to_user
#class PositionBelongsToUser < ActiveRecord::Migration
# def self.up
# add_column :positions, :user_id, :integer
# end
#
@nickhoffman
nickhoffman / changed_specs.rb
Created August 27, 2011 19:21
A rake task for running all of the spec files that've been modified.
RSpec::Core::RakeTask.new('spec:changed') do |t|
changed_files = `git status -s | grep '^ M spec/' | grep '_spec.rb$'`.split "\n"
changed_files.each {|file| file.sub! /\A M /, '' }
puts
puts "Found #{changed_files.count} changed spec file(s):"
changed_files.each {|file| puts " #{file}"}
puts
@nickhoffman
nickhoffman / spreadsheet_importer.rb
Created August 29, 2011 15:32
Why does this error occur in the spec?: undefined method `each_pair'
$ bundle exec rspec --fail-fast -b spec/models/spreadsheet_importer_spec.rb
No examples were matched by {:focus=>true}, running all
F
Failures:
1) SpreadsheetImporter instance variables has a reader for @catalog
Failure/Error: @importer = SpreadsheetImporter.new @catalog, @excel, @photos_dir
NoMethodError:
undefined method `each_pair' for #<Catalog:0xb0475bc>
class SessionsController < Devise::SessionsController
def create
if request.xhr?
resource = warden.authenticate! :scope => resource_name
if resource.nil?
render :json => {
:status => 'fail',
:data => {
:cause => 'invalid',
class ProductHaveCell < Cell::Rails
def description(have)
condition = have.condition
desc = "#{have.quantity}x #{condition.name}"
if have.sealed
desc += ' ' + I18n.t('words.Sealed').downcase
elsif have.packaging
desc += ' ' + I18n.t('phrases.product_haves.with_packaging')
end
@nickhoffman
nickhoffman / gist:1282105
Created October 12, 2011 18:32 — forked from clintongormley/gist:961303
Ngram example
###################
# CREATE THE INDEX:
###################
curl -XPUT 'http://127.0.0.1:9200/test/?pretty=1' -d '
{
"settings" : {
"analysis" : {
"filter" : {
"edge_ngram" : {
"side" : "front",
@nickhoffman
nickhoffman / gist:1283380
Created October 13, 2011 04:30
Why does a search for a misspelling ("optius" instead of "optimus") find no documents?
echo 'Delete the index.'
curl -X DELETE 'http://localhost:9200/test_products/?pretty=true'
echo; echo
echo 'Create the index. Copied directly from https://gist.github.com/961303 .'
curl -X PUT 'http://localhost:9200/test_products/?pretty=true' -d '
{
"settings" : {
"analysis" : {
// curl -X GET 'localhost:9200/development_products/_search?pretty=true' -d '
{
explain: true,
query: {
dis_max: {
queries: [
{ field: { "name": "grmlock" } },
{ field: { "catalog.name": "grmlock" } },
{ field: { "items.name": "grmlock" } },
{ field: { "properties.character": "grmlock" } },
@nickhoffman
nickhoffman / app--helpers--application_helper.rb
Created October 18, 2011 15:20
pjax is awesome, but causes code within #content_for not to be rendered. Here's a solution.
module ApplicationHelper
def content_for_or_pjax(name, &block)
request.headers['X-PJAX'] ? capture(&block) : content_for(name, &block)
end
end