Skip to content

Instantly share code, notes, and snippets.

@moneill
moneill / gist:13ff4140b372407af7aa
Created October 8, 2014 21:37
Sample Kibana Dashboard
{
"title": "Logstash Search",
"services": {
"query": {
"list": {
"0": {
"query": "*",
"alias": "",
"color": "#7EB26D",
"id": 0,
@moneill
moneill / gist:3311159
Created August 10, 2012 04:55
History API
$(document).ready(function(){
$("input#search").bindWithDelay("keyup", function() {
term = $(this).val();
form = $(this).parent();
action = form.attr('action') + "?" + form.find('input[name!=utf8]').serialize();
if(term == '' || term.length >= 2){
$.get(action, null, null, 'script');
history.replaceState(null, "", action);
}
@moneill
moneill / gist:2597984
Created May 4, 2012 21:55
Soundex test
irb(main):016:0> Person.where("soundex(first_name) LIKE soundex(?)", "%trinitya%")
Person Load (16.9ms) SELECT `people`.* FROM `people` WHERE (soundex(first_name) LIKE soundex('%trinitya%'))
=> [#<Person id: 5, first_name: "Trinity", middle_name: nil, last_name: "Kuvalis", age: 22, email: "samir_wilderman@oconner.com", phone: "509-938-1572 x4260", address_1: "28790 Minerva Highway", address_2: nil, state: "PW", zip: 66274, contact_preference: nil, comments: "Natus porro aut itaque placeat sunt. Odio quas omni...", sources_of_interest: nil, other_sources_of_interest: nil, mailing_subscriptions: nil, lumbar_puncture: nil, study_partner: nil, study_partner_relationship: nil, adc_comments: "Sed porro blanditiis nemo. Sed facilis ea. Ea quis ...", created_at: "2012-05-04 19:53:05", updated_at: "2012-05-04 19:53:05", city: "East Clarissaburgh", active: true>]
irb(main):017:0> Person.where("soundex(first_name) LIKE soundex(?)", "%trinityaa%")
Person Load (0.4ms) SELECT `people`.* FROM `people` WHERE (soundex(
irb(main):005:0> Person.search("Trinity")
Person Load (0.4ms) SELECT `people`.* FROM `people` WHERE (last_name LIKE '%Trinity%' OR first_name LIKE '%Trinity%' OR id = 'Trinity' OR email LIKE '%Trinity%')
=> [#<Person id: 5, first_name: "Trinity", middle_name: nil, last_name: "Kuvalis", age: 22, email: "samir_wilderman@oconner.com", phone: "509-938-1572 x4260", address_1: "28790 Minerva Highway", address_2: nil, state: "PW", zip: 66274, contact_preference: nil, comments: "Natus porro aut itaque placeat sunt. Odio quas omni...", sources_of_interest: nil, other_sources_of_interest: nil, mailing_subscriptions: nil, lumbar_puncture: nil, study_partner: nil, study_partner_relationship: nil, adc_comments: "Sed porro blanditiis nemo. Sed facilis ea. Ea quis ...", created_at: "2012-05-04 19:53:05", updated_at: "2012-05-04 19:53:05", city: "East Clarissaburgh", active: true>]
config.action_mailer.delivery_method = :sendmail
config.action_mailer.sendmail_settings = {
:openssl_verify_mode => 'none'
}
@moneill
moneill / gist:2569262
Created May 1, 2012 16:13
User factory
FactoryGirl.define do
factory :user do
first_name { Faker::Name.first_name }
last_name { Faker::Name.last_name }
email { Faker::Internet.email }
password 'password'
end
end
@moneill
moneill / gist:2202537
Created March 26, 2012 02:37
Server load oh noes
==> Output of top:
top - 21:34:56 up 127 days, 18:56, 2 users, load average: 5.36, 5.71, 5.73
Tasks: 184 total, 7 running, 176 sleeping, 1 stopped, 0 zombie
Cpu(s): 98.3%us, 1.7%sy, 0.0%ni, 0.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
Mem: 4050600k total, 3793036k used, 257564k free, 525688k buffers
Swap: 2096440k total, 564808k used, 1531632k free, 1518568k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
29524 strokecd 25 0 763m 55m 2876 R 49.2 1.4 351:20.02 ruby
@moneill
moneill / gist:2176375
Created March 23, 2012 23:33
Redir with mock, boo
it "should redirect to the movie index when no similar movies exist" do
@movie = mock('Movie')
@movie.stub(:id).and_return(1)
Movie.should_receive('find_similar').with(@movie.id).and_return(nil)
get 'similar', {:id => @movie.id}
response.should redirect_to(movies_path)
end
@moneill
moneill / gist:2175337
Created March 23, 2012 21:39
Moar movies
require 'spec_helper'
describe MoviesController do
before :each do
@movie = Movie.create(:title => 'American Graffiti', :rating => 'R', :release_date => "1973-08-11", :director => "George Lucas")
end
describe 'Find similar movies' do
it "has a route defined to show similar movies" do
get 'similar', {:id => @movie.id}
@moneill
moneill / gist:2175333
Created March 23, 2012 21:38
Moar similar movie stuff
require 'spec_helper'
describe MoviesController do
before :each do
@movie = Movie.create(:title => 'American Graffiti', :rating => 'R', :release_date => "1973-08-11", :director => "George Lucas")
end
describe 'Find similar movies' do
it "has a route defined to show similar movies" do
get 'similar', {:id => @movie.id}