Skip to content

Instantly share code, notes, and snippets.

@stengland
stengland / event.rb
Created November 29, 2009 22:23
Multi Param Atrributes for MongoMapper
class Event
include MongoMapper::Document
plugin MultiParameterAttributes
key :name, String, :required => true
key :start_date, Date, :required => true
key :start_time, Time, :required => true
end
@stengland
stengland / search.rb
Created January 24, 2011 12:41
Simple Mongo Mapper search using a map reduce for relevance ordering
module Noodall
module Search
STOPWORDS = ["about", "above", "above", "across", "after", "afterwards", "again", "against", "all", "almost", "alone", "along", "already", "also", "although", "always", "among", "amongst", "amoungst", "amount", "and", "another", "any", "anyhow", "anyone", "anything", "anyway", "anywhere", "are", "around", "back", "became", "because", "become", "becomes", "becoming", "been", "before", "beforehand", "behind", "being", "below", "beside", "besides", "between", "beyond", "bill", "both", "bottom", "but", "call", "can", "cannot", "cant", "con", "could", "couldnt", "cry", "describe", "detail", "done", "down", "due", "during", "each", "eight", "either", "eleven", "else", "elsewhere", "empty", "enough", "etc", "even", "ever", "every", "everyone", "everything", "everywhere", "except", "few", "fifteen", "fify", "fill", "find", "fire", "first", "five", "for", "former", "formerly", "forty", "found", "four", "from", "front", "full", "further", "get", "give", "had", "has", "hasnt", "have",
@stengland
stengland / alias_test.rb
Created May 3, 2011 15:54
alias_attribute fails in mm 0.9
require 'mongo_mapper'
class Yester
include MongoMapper::Document
key :name, String
alias_attribute :foo, :name
alias_method :bar, :name
@stengland
stengland / search.rb
Created June 6, 2011 10:45
Paginated google custom search using HTTParty, Will Paginate and Ostruct
require 'httparty'
require 'will_paginate/collection'
require 'ostruct'
class GoogleCustomSearch
include HTTParty
base_uri 'https://www.googleapis.com/customsearch/v1'
format :json
default_params :cx => 'google-costom-searck-id', :key => 'google-api-key'
@stengland
stengland / test_template.rb
Created August 11, 2011 11:35
test_template
puts "\n========================================================="
puts " Noodall TEMPLATE"
puts "\n========================================================="
require "rails"
require "net/http"
require "net/https"
# Copy a static file from the template into the new application
def copy_static_file(path)
@stengland
stengland / volume.rb
Created April 26, 2012 09:15 — forked from uriel1998/volume.rb
Set pulseaudio volume from the command line using ruby
#!/usr/bin/env ruby
# Changed bit of code toggling mute - was throwing errors for me.
# Added output, so it could be piped to a notify-osd or somesuch if desired.
# Pulseaudio volume control
class Pulse
attr_reader :volumes, :mutes
# Constructor
@stengland
stengland / find_link.rb
Created July 19, 2012 15:34
Find a link with Cabybara Simple Node
@stengland
stengland / .vimrc
Created August 3, 2012 15:24
My Vimux/Turbux set up
if exists('$TMUX')
" Prompt for a command to run
map <Leader>vp :VimuxPromptCommand<CR>
" Run last command executed by VimuxRunCommand
map <Leader>vl :VimuxRunLastCommand<CR>
" Inspect runner pane
map <Leader>vi :VimuxInspectRunner<CR>
@stengland
stengland / gist:3347696
Created August 14, 2012 09:07 — forked from jordelver/gist:3230399
Ruby simple delegator
# Example from http://mikepackdev.com/blog_posts/31-exhibit-vs-presenter
class Decorator < SimpleDelegator
end
class Car
def price
1_000_000
end
end
@stengland
stengland / bbcradio.sh
Last active January 11, 2023 14:53
Play BBC Radio with mpd or mplayer from the command line
#!/bin/bash
play() {
playlist="http://a.files.bbci.co.uk/media/live/manifesto/audio/simulcast/hls/uk/sbr_high/ak/bbc_$1.m3u8"
echo $playlist
if mpc
then
mpc add $playlist
mpc play
else
mplayer $playlist