Skip to content

Instantly share code, notes, and snippets.

@acook
acook / pig_latin.py
Last active December 15, 2015 07:39 — forked from anonymous/gist:5224294
# Defining main variables for translator
pyg = 'ay'
original = raw_input('Enter a word:')
word = original.lower()
first = word [0]
#Beginning of if/else statements
if len(original) > 0 and original.isalpha():
x = 1
some_loop_or_iterator {
x = 0
x = x + 1
}
x # what is the value of x?
class Foo
def whatever
puts 'whatever foo'
end
end
module Fooish
def whatever
raise NotImplementedError, "This is a Fooish method, you need to implement the guts of it in #{self.is_a? Module ? self.name : self.class.name}."
end
@acook
acook / line_regex.rb
Last active December 15, 2015 16:39
line_endings1 = /\r\n|\n\r|\n|\r/
line_endings2 = /\r?\n|\n?\r/
@acook
acook / when_rake_db_seeds_rails.bash
Created April 9, 2013 21:56
`rake db:reset` will call `db:seed` without calling `db:migrate` first, this gets around that.
#!/usr/bin/env bash
# If running `rake db:reset` or `rake db:seed` fails, try this:
rake db:drop db:create db:schema:load db:migrate db:seed
@acook
acook / list_of_matching_indexes.rb
Last active December 16, 2015 03:19
A method to obtain a list of matching indexes for a substring (or regex).
class String
def list_of_matching_indexes_for substring
array = []
self.scan substring do |letter|
array << $~.offset(0).first
end
array
end
end
@contents = Hash.new
@views = Array.new
def content_for identifier, content = nil, &content_block
@contents[identifier] = block_given? ? content_block.call : content
end
def run
return false if @views.empty?
@acook
acook / elemental.rb
Last active December 16, 2015 10:19
class Element
include DataMapper::Resource
property :id, Serial
property :name, String
end
class Composition
include DataMapper::Resource
# This is a mostly idomatic class-based Ruby implementation of
# Labyrinth's version of the Knights and Knaves logic puzzle.
# It's self-resetting once a choice has been made,
# so you only get one shot at it before it rerolls.
class LabyrinthLogic
BOOLS = [true, false]
DOORS = [:left, :right]
def initialize
module PubSub
class << self
def create type, channel, object
channel = channel.to_sym
case type
when :listener
listeners[channel] ||= Array.new
listeners[channel] << object
channels[channel] ||= Array.new