Skip to content

Instantly share code, notes, and snippets.

@stengland
stengland / routes.rb
Created August 2, 2013 17:44
External URLs in rails routes
MyApp::Application.routes.draw do
# External urls
scope host: 'www.example.com' do
get 'thing' => 'dev#null', as: :thing
end
end
# Use thing_url in your veiws (thing_path would not include the host)
# thing_url => "http://www.example.com/thing"
#!/bin/sh
#Wrapper for mpc including host
export MPD_HOST=`cat /etc/mpdhost`
/usr/bin/mpc $@

If tmux fails with the message "open terminal failed: missing or unsuitable terminal: rxvt-unicode-256color".

$ ssh remotemachine mkdir -p .terminfo/r
$ scp /usr/share/terminfo/r/rxvt-unicode* remotemachine:.terminfo/r/
@stengland
stengland / vcr.rb
Created June 24, 2013 11:26
Match VCR request body as xml doc rather than string. Will account for different versions of LibXML outputting slightly different XML (mainly empty tags) even though the xml document is equivalent. Uses http://rubygems.org/gems/equivalent-xml
VCR.configure do |c|
c.register_request_matcher :xml_body do |request_1, request_2|
EquivalentXml.equivalent?(request_1.body, request_2.body)
end
c.ignore_localhost = true
c.cassette_library_dir = Rails.root.join("spec", "support", "vcr_cassettes")
c.hook_into :webmock
c.configure_rspec_metadata!
c.default_cassette_options = { match_requests_on: [:method, :uri, :xml_body] }
# c.debug_logger = File.open("#{Rails.root}/log/vcr.log", 'w')
# ~/.tmuxinator/music.yml
project_name: Musix
project_root: ~/Music
pre: mopidy -q &> ~/.mopidy.log &
tabs:
- interface: ncmpcpp
- radio: bbcradio
- mixer: alsamixer
- mopodiy: tail -f ~/.mopidy.log
def months_til_renewal
months = 0
date_to_check = Date.current
while(date_to_check < current_period_ends_at.to_date) do
date_to_check = date_to_check.next_month
months += 1
end
months
end
@stengland
stengland / README.md
Last active December 16, 2015 20:49 — forked from jordelver/README.md

Usage

Normal

person = Person.new('Jo', 'Bloggs')
    
HumanName.new(person).full_name
> "Joe Bloggs"
def temp_password
@temp_password ||= ((0..9).to_a.sample(2) + ('a'..'z').to_a.sample(6)).shuffle.join
end
@stengland
stengland / export_to_tumblr.rake
Last active December 16, 2015 07:09
Use the tumblr_client Gem to export some posts to Tumblr. I'm using sequel but with a bit of tweking you could use this in a rails app.
require './sequel_config'
require './tumblr_config'
desc 'Export posts to Tumblr'
task :export_to_tumblr do
client = Tumblr::Client.new
Post.order(:published_at).each do |p|
begin
resp = client.text('some_tumblog',{
title: p.title,
@stengland
stengland / markdown.css
Last active December 14, 2015 09:29
Basic styles for a Markdown document
html {
font-size: 14px;
line-height: 1.6;
font-family: helvetica,arial,freesans,clean,sans-serif;
color: black;
}
h1 {
margin: 15px 0;
padding-bottom: 2px;
font-size: 24px;