This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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(): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x = 1 | |
some_loop_or_iterator { | |
x = 0 | |
x = x + 1 | |
} | |
x # what is the value of x? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
line_endings1 = /\r\n|\n\r|\n|\r/ | |
line_endings2 = /\r?\n|\n?\r/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class String | |
def list_of_matching_indexes_for substring | |
array = [] | |
self.scan substring do |letter| | |
array << $~.offset(0).first | |
end | |
array | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Element | |
include DataMapper::Resource | |
property :id, Serial | |
property :name, String | |
end | |
class Composition | |
include DataMapper::Resource | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |