Skip to content

Instantly share code, notes, and snippets.

View yock's full-sized avatar

Michael Yockey yock

View GitHub Profile
def score(dice)
return 0 if dice.empty?
counts = Hash.new(0)
dice.each do |die|
counts[die] += 1
end
a_set = (counts.select {|k, v| v > 2})
set = a_set[0][0] if a_set.empty? == false
counts[set] -= 3 if set != nil
def is_anagram?(words)
one, two = words.split ", "
two_arr = two.split ""
one.chars do |o|
two_arr.delete(o) { return false }
end
true
end
puts is_anagram? "word, wrod" # => True
@yock
yock / burn.sh
Created March 13, 2011 01:24
Script to burn a seamless audio CD from a directory of mp3 and/or mp4 files
#!/bin/bash
function append_filename {
echo -en >> $TOCFILE "TRACK AUDIO\nFILE \"$WAV\" 0\n"
}
MP3DIR=$1
TOCFILE="cd_$$.toc"
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
require 'net/ftp'
require 'time'
metar_uri = 'tgftp.nws.noaa.gov'
metar_base = '/data/observations/metar/stations/'
metar_station = ARGV[0]
metar_file = metar_station + '.TXT'
metar_data = Array.new
@yock
yock / gist:1090422
Created July 18, 2011 19:32
Vendor-supplied (before)
protected String getUserIdFromPrincipal( Principal prin ) {
try {
if ( prin == null ) {
return "";
}
String decodedPrin = URLDecoder.decode( prin.toString(), "UTF-8" );
// Not in CN=xyz format? Then just return full name up to first space, if any.
@yock
yock / gist:1090437
Created July 18, 2011 19:37
Refactored (after)
protected String getUserIdFromPrincipal(Principal prin) {
if (prin == null) {
throw new IllegalArgumentException(
"User principal must not be null.");
}
logger.debug("URL encoded principal: " + prin);
String strPrincipal = null;
try {
strPrincipal = URLDecoder.decode(prin.getName(), UTF_8);
package com.cinfin.sharedsvcs.ems.payload;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.zip.*;
/**
* Singleton class for performing compression/decompression operations on
* payload byte arrays.
*
for (Iterator<String> iterator = o.iterator(); iterator.hasNext();) {
iterator.next();
iterator.remove()
}
@yock
yock / factories.rb
Created May 2, 2013 14:32
Nested factories in FactoryGirl
FactoryGirl.define do
factory :user do
name "#{Faker::Name.first_name} #{Faker::Name.last_name}"
email Faker::Internet.email
username Faker::Internet.user_name
password 'password'
stripe_customer_id 'cus_1'
factory :deactivated_user do
deactivated true
@yock
yock / factory.rb
Last active December 19, 2015 14:19
FactoryGirl traits
FactoryGirl.define do
factory :user do
name 'Test User'
email 'fake@example.com'
trait :admin do
# Setting name here isn't required. Given to show override.
name 'Test Admin'
admin true
end