Skip to content

Instantly share code, notes, and snippets.

View hauntedhost's full-sized avatar
💭
👻

Jules Omlor hauntedhost

💭
👻
View GitHub Profile
# Write a method ordered_vowel_words that takes a string of lowercase words
# and returns a string with just the words containing all their vowels
# (excluding "y") in alphabetical order
def ordered_vowel_words(words)
vowels = %w(a e i o u)
ordered = []
words.split(" ").each do |word|
word_vowels = word.chars.select { |char| vowels.include? char } # amends = ae, complicated = oiae
ordered << word if word_vowels == word_vowels.sort
# Write a function which takes a number N of cats and outputs which cats have
# hats. Initially, none of the cats have hats. You walk down the line of cats,
# stopping at every cat, taking off its hat if it has one or putting on a hat
# if it doesn't have one. On the second round, you only stop at every second
# cat [eg #2, #4, #6], on the third round you stop at every third cat [eg #3,
# #6, #9...]. You continue this until you've done as many round as there are
# cats. Your function should output an array containing booleans indicating
# whether each cat has a hat or not by the end.
def cats_in_hats(num_cats)
# Build a function morse_encode that takes in a word (no numbers or
# punctuation) and outputs the morse code for it. Put two spaces between
# words and one space between letters.
# http://www.w1wc.com/pdf_files/international_morse_code.pdf
def morse_encode(str)
morse_codes = { a: ".-", b: "-...", c: "-.-.", d: "-..", e: ".", f: "..-.",
g: "--.", h: "....", i: "..", j: ".---", k: "-.-", l: ".-..",
m: "--", n: "-.", o: "---", p: ".--.", q: "--.-", r: ".-.",
s: "...", t: "-", u: "..-", v: "...-", w: ".--", x: "-..-",
@hauntedhost
hauntedhost / jasmine-spy-cheatsheet.js
Created October 18, 2013 17:12
jasmine spy cheatsheet
//= require jquery
//= require track-events
describe('TrackEvents', function () {
beforeEach(function () {
loadFixtures('track-events_fixture');
});
it('triggers a Test.fire', function() {
Test = function () { }
// Write a function to get the common letters out of two strings
// commonLetters('hello world', 'hello moon') => should return 'helo'
function commonLetters(str1, str2) {
var map = {},
common = '';
for (var i = 0; i < str1.length; i++) {
var letter = str1[i];
if (letter != ' ') map[letter] = true;
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>MSL</string>
<!-- based on Monokai Soda -->
<key>settings</key>
<array>
<dict>
{
"font_size": 20,
"date_format": "(%Y-%m-%d %H:%M)",
"color_scheme": "Packages/PlainTasks/tasks-monokai.hidden-tmTheme"
}
@hauntedhost
hauntedhost / solarized_dark.terminal
Created May 18, 2013 23:45
solarized_dark.terminal
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ANSIBlackColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OVU5TUkdCXE5TQ29sb3JTcGFjZVYkY2xhc3NPECgw
LjE1NjE5MDIxMDUgMC4wMTk1OTcyNTAxNSAwLjEzOTY3MzE4NjEAEAGAAtIQERITWiRj
bGFzc25hbWVYJGNsYXNzZXNXTlNDb2xvcqISFFhOU09iamVjdF8QD05TS2V5ZWRBcmNo
@hauntedhost
hauntedhost / nearest_larger.rb
Created April 28, 2013 07:41
nearest_larger
def nearest_larger(arr, idx)
diff = 1
loop do
left = idx - diff
right = idx + diff
diff += 1
if (left >= 0) && (arr[left] > arr[idx])
return left
elsif (right < arr.length) && (arr[right] > arr[idx])
@hauntedhost
hauntedhost / nearest_larger.rb
Created April 28, 2013 07:17
nearest_larger
def left_match(arr, idx)
num = arr[idx]
unless idx.zero?
(idx - 1).downto(0) do |i|
return i if arr[i] > num
end
end
nil
end