Skip to content

Instantly share code, notes, and snippets.

View letsbreelhere's full-sized avatar

Bree Elle Gardner letsbreelhere

  • Academia, Inc.
  • Oakland, CA
View GitHub Profile
@letsbreelhere
letsbreelhere / gist:1938258
Created February 29, 2012 05:40
Imperative to_hash
def to_hash
hash = {}
@reports.each do |report|
hash.merge! report.to_hash
end
hash
end
@letsbreelhere
letsbreelhere / gist:1938271
Created February 29, 2012 05:43
Functional to_hash
def to_hash
@reports.inject({}) do |report_hash, report|
report_hash.merge report.to_hash
end
end
@letsbreelhere
letsbreelhere / pandora.com.js
Created April 7, 2012 22:59
Set pandora title to track info
var changeTitle = function() {
var artistName = $("#trackInfo .artistSummary").text();
var trackTitle = $("#trackInfo .songTitle").text();
$("title").text(trackTitle + " by " + artistName + " - Pandora");
}
changeTitle();
setInterval(changeTitle, 5000);
@letsbreelhere
letsbreelhere / user.rb
Created June 8, 2012 20:08
tire gem user.rb
class User < ActiveRecord::Base
include Tire::Model::Search
include Tire::Model::Callbacks
attr_accessible :name, :email, :company
#...
end
@letsbreelhere
letsbreelhere / ngram_config.rb
Created June 8, 2012 20:14
tire ngram analyzer
settings analysis: {
filter: {
ngram_filter: {
type: "nGram",
min_gram: 3,
max_gram: 8
}
},
analyzer: {
ngram_analyzer: {
# 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
>> 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
require 'rubygems'
require 'sinatra'
require 'serialport'
port_str = "/dev/tty.usbmodemfa131"
baud_rate = 9600
data_bits = 8
stop_bits = 1
parity = SerialPort::NONE
@letsbreelhere
letsbreelhere / gist:3708825
Created September 12, 2012 18:22
d3 stacked line graph
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").
@letsbreelhere
letsbreelhere / gist:960a5e74cf391405869f
Last active August 29, 2015 14:04
Sketch of nested strong Rails params
# Like this:
#
# params.allow_nested(
# user: must(
# name: must,
# age: maybe,
# article: must(
# title: must,
# publish_at: maybe
# ),