Skip to content

Instantly share code, notes, and snippets.

def alert_user(alert = "")
voice = NSSpeechSynthesizer.alloc.initWithVoice("com.apple.speech.synthesis.voice.Victoria")
voice.startSpeakingString(alert)
end
@joshmcarthur
joshmcarthur / gist:3441540
Created August 23, 2012 20:49
Apache Configuration to load fonts in IE9
<FilesMatch "\.(ttf|otf|woff)$">
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
</FilesMatch>
CSV.foreach(path, headers: true, header_converters: :symbol) do |row|
User.create(row.to_hash)
end
@joshmcarthur
joshmcarthur / date_time_extension_spec.rb
Last active December 11, 2015 12:28
A code snippet to add #beginning_of_financial_year and #end_of_financial_year methods to Rails' DateTime class.
# spec/extensions/date_time_spec.rb
# PS: I know this spec code isn't particularly DRY or nice.
require 'spec_helper'
describe DateTime do
describe "#beginning_of_financial_year" do
subject do
DateTime.now.beginning_of_financial_year
@joshmcarthur
joshmcarthur / validate.rb
Last active December 14, 2015 08:48
Quick demo of validating an XML document against a schema
require 'nokogiri'
# Public: Find the absolute path to a file
#
# This method finds a file that is relative to the
# location of the script, expanding anything that
# needs expanding (~, etc.)
#
# filename - the filename to find
@joshmcarthur
joshmcarthur / remove_duplicates.rb
Created March 20, 2013 22:17
Remove all instances of duplicates from an array (this may not be the best way)
@duplicate_pharmacists = @pharmacists - @pharmacists.reject { |pharmacist| @pharmacists.select { |p| p.email == pharmacist.email }.size > 1 }
@pharmacists -= @duplicate_pharmacists
@joshmcarthur
joshmcarthur / config
Created April 5, 2013 02:36
~/.bundle/config
---
BUNDLE_PATH: .bundle
@joshmcarthur
joshmcarthur / .zshrc
Created April 16, 2013 01:05
Add an alias to return your current local IP address
# Macbook Pro users - en0 is ethernet, so you should use en1
alias ip="ipconfig getifaddr en0"
@joshmcarthur
joshmcarthur / default.rb
Created May 21, 2013 04:17
Installing packages with Chef
%w(memcached redis-server htop fail2ban).each do |required_package|
package required_package do
action :install
end
end
@joshmcarthur
joshmcarthur / default.rb
Created May 21, 2013 04:18
Overriding node attributes in Chef 11
node.override['firewall']['rules'] = [
{"http" => {"port" => 80}},
{"https" => {"port" => 443}},
{"ssh" => {"port" => 22}}
]