This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Player { | |
constructor() { | |
this._health = 20 | |
} | |
playTurn(warrior) { | |
considerMovement(warrior) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl -O http://sphinxsearch.com/files/sphinx-0.9.8-rc2.tar.gz | |
tar -zxvf sphinx-0.9.8-rc2.tar.gz | |
cd sphinx-0.9.8-rc2 | |
./configure | |
make | |
sudo make install | |
bundle exec rake thinking_sphinx:configure | |
bundle exec rake thinking_sphinx:index | |
bundle exec rake thinking_sphinx:start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@object = "{'source': 'Direct', 'details': 'Unknown', 'vdate': 1333236870729}" | |
Rails 3.2.15 | |
> ActiveSupport::JSON.decode(@object) | |
# => {"details"=>"Unknown", "vdate"=>1333236870729, "source"=>"Direct"} | |
Rails 3.2.16 | |
> ActiveSupport::JSON.decode(@object) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
headlines = ["one","two","three","flee"] | |
#enumerables have a method #to_phrase.rhyme_key which gives a key based on pronunciation. | |
So headlines.map(&:to_phrase.rhyme_key) => 1,2,3,3 (for example) | |
#Now I want to filter out all the strings that don't have rhyme_key counterparts, | |
essentially leaving ["three","flee"] in the convoluted example above. I tried the code below, | |
but that just stores the rhyme_key values in the headlines array which is useless to me because | |
the original string literals get replaced with the values. How do I check against the values via | |
the methods without replacing the original strings? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ArticlesController < ApplicationController | |
def index | |
@articles = Article.all | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class World | |
attr_accessor :cells | |
def initialize | |
@cells = [] | |
end | |
def push_cell cell | |
@cells = @cells << cell | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Discussion < ActiveRecord::Base | |
scope :with_includes, -> { includes(:comments, :category) } | |
scope :by_recency, -> { order('created_at DESC') } | |
scope :visible, -> { where(hidden: false) } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# We create a new class with some sane defaults | |
class Garden | |
def initialize(args={}) | |
@trees = args[:trees] || 15 | |
@perimiter = args[:perimiter] || 'fence' | |
@lawn = args[:lawn] || 'grass' | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Find your tour ID | |
tour = Tour.find(xxx) | |
Cache::Tour.new(tour).delete | |
# This clears memcache for all regions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ErrorsController < ApplicationController | |
def not_found | |
# Will render the app/views/errors/not_found.html.erb template | |
def not_found | |
respond_to do |format| | |
format.html { render template: 'errors/not_found', layout: 'layouts/application', status: 404 } | |
# Below is to ensure rails doesn't 500 when someone requests /blahblahblah.js or any other non-html format. | |
format.all { render nothing: true, status: 404 } | |
end | |
end |
NewerOlder