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
def to_hash | |
hash = {} | |
@reports.each do |report| | |
hash.merge! report.to_hash | |
end | |
hash | |
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
def to_hash | |
@reports.inject({}) do |report_hash, report| | |
report_hash.merge report.to_hash | |
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
var changeTitle = function() { | |
var artistName = $("#trackInfo .artistSummary").text(); | |
var trackTitle = $("#trackInfo .songTitle").text(); | |
$("title").text(trackTitle + " by " + artistName + " - Pandora"); | |
} | |
changeTitle(); | |
setInterval(changeTitle, 5000); |
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 User < ActiveRecord::Base | |
include Tire::Model::Search | |
include Tire::Model::Callbacks | |
attr_accessible :name, :email, :company | |
#... | |
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
settings analysis: { | |
filter: { | |
ngram_filter: { | |
type: "nGram", | |
min_gram: 3, | |
max_gram: 8 | |
} | |
}, | |
analyzer: { | |
ngram_analyzer: { |
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
# config/elastic_search.rb | |
ElasticSearchSettingsForUser = YAML.load_file('config/elastic_search_user.yml').with_indifferent_access | |
# user.rb | |
class User < ActiveRecord::Base | |
settings ElasticSearchSettingsForUser do | |
mapping do | |
[:name, :email, :company].each do |attribute| | |
indexes attribute, type: 'string', analyzer: 'ngram_analyzer' | |
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
>> module M | |
>> def foo | |
>> self.class::FOO | |
>> end | |
>> end | |
=> nil | |
>> class A; FOO = 1; extend M; end | |
=> A | |
>> class B; FOO = 42; extend M; end | |
=> B |
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
require 'rubygems' | |
require 'sinatra' | |
require 'serialport' | |
port_str = "/dev/tty.usbmodemfa131" | |
baud_rate = 9600 | |
data_bits = 8 | |
stop_bits = 1 | |
parity = SerialPort::NONE |
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
var width = 400; | |
var height = 300; | |
var len = 20; | |
var rand_data = function() { | |
return d3.range(len).map(function() { return 1 + Math.random() }); | |
} | |
var stack = d3.select("#chart"). | |
append("svg:svg"). |
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
# Like this: | |
# | |
# params.allow_nested( | |
# user: must( | |
# name: must, | |
# age: maybe, | |
# article: must( | |
# title: must, | |
# publish_at: maybe | |
# ), |
OlderNewer