Skip to content

Instantly share code, notes, and snippets.

View johana-star's full-sized avatar
🕶️

Johana Star johana-star

🕶️
View GitHub Profile
# Default values on hashes… If a default value isn't set in Hash.new, the hash defaults to nil.
1.9.3-p392 :033 > hash1 = Hash.new
=> {}
1.9.3-p392 :034 > hash2 = Hash.new(0)
=> {}
1.9.3-p392 :035 > hash1[:key]
=> nil
1.9.3-p392 :036 > hash2[:key]
=> 0
After playing around in IRB I used the following method chains to answer the questions below. It's a bit verbose, there are shorter ways to solve these problems.
- How many monsters are nocturnal?
$monsters.collect{|monster| monster if monster[:nocturnal]}.compact.count
- What are the names of the monsters that are nocturnal?
$monsters.collect{|monster| monster if monster[:nocturnal]}.compact.map{|monster| monster[:name]}
- How many legs do all our monsters have?
$monsters.collect{|monster| monster[:legs]}.inject(:+)
- What are the 2 most common dangers and vulnerabilities of our monsters?
dangers = $monsters.collect{|monster| monster[:dangers] + monster[:vulnerabilities] }.flatten
class Book
# This defines a method called thing1 at the self (Book) level
class << self
def thing1
"I am thing one."
end
end
# This defines a method called thing2 at the self (Book) level
def self.thing2
@johana-star
johana-star / day_of_the_week_in_month.rb
Last active December 16, 2015 18:09
This took me way longer than I would have preferred to write.
require 'active_support/time'
def Time.month; self.strftime("%_m").to_i; end
def Date.month; self.strftime("%_m").to_i; end
def fridays_in_month(date_or_time)
month = date_or_time.month
current_week = Date.new(date_or_time.year, date_or_time.month).
prev_week(day = :friday).
next_week(day = :friday)
begin
p @user_input.nil? ? 'Your phrase here please:' : "That wasn't a phrase! Try again."
@user_input = gets.strip
end while @user_input == ""
print "Daffy says \"#{@user_input.gsub!(/S/, "Th").gsub!(/s/, "th")}\"!"
@johana-star
johana-star / notes_sandi_metz.md
Last active December 16, 2015 04:49
Notes from meeting Sandi Metz through my book group's Google Hangout on April 13, 2013.

On pairing:

  • Recognize the power differential between knowledge gap
  • Don't let someone type all the time.
  • Don't pair on something that doesn't make sense
  • Pair on stuff to raise the truck factor

"There's something so delightful about working in the secret dark while the world is asleep." Sandi on working in the early morning.

I wasn't a good enough designer to write code that was easily testable, and my tests sucked, so it was like a double whammie.

The tweet was imprecise due to the decontextualization that 140 characters gives. Also, this is just tricky, slippery stuff. I was talking to my counselor about how I define and identify myself within the context of my work and my profession. I said I could lose my job but I would still have my work and that's where a lot of my identity comes in these days.

And he asked: Who would you be without your ability to code, what if you couldn't see, couldn't type... There's a process-driven identity and then there's an identity which is your innate self. I don't tend to think of myself as an ecswhyzee kind of person, but a person who does ecswhyzee.

Eventually I got to saying, well, I approach pairing with humor and lightness, and my counselor helped me extract that perhaps my identity being has humor and lightness…

Does this clarification help? If not, please ask questions so that i can find better language to illuminate this difference.

What's the name (or codename) of your app? What will your app do?

I'm not sure that I want to work on a single app. Current project ideas include:

Kitten of the day! - an app which takes email addresses and sends the compiled list a photo of a kitten every morning.

Background processing - evaluating a collection of data to see if it meets requirements, and recording which combinations meet requirements. A little background: last quarter Cheri and I worked on Slacker Meals, which generated a meal from a database of ingredients. Meals needed to be within certain ranges for protein, calcium, and calories. The naive method we used to generate meals randomly tried ingredients until it found a match. This usually took around a hundred tries. Instead, I would like to take a database, generate possible combinations, and evaluate the combos based on requirements.

When the database changes new combinations which include new ingredients should be evaluated... If the requirements change, the entire d

def create_array(number)
array = []
number.times do |num|
array << "e#{num}".to_s
end
return array
end
def find_combinations(array)
combos = []
➜ C4C git:(security_upgrades) ✗ gem env gempath
/Users/strand/.rvm/gems/ruby-1.9.3-p392:/Users/strand/.rvm/gems/ruby-1.9.3-p392@global
➜ C4C git:(security_upgrades) ✗ echo $PATH
/Users/strand/.rvm/gems/ruby-1.9.3-p392/bin:/Users/strand/.rvm/gems/ruby-1.9.3-p392@global/bin:/Users/strand/.rvm/rubies/ruby-1.9.3-p392/bin:/Users/strand/.rvm/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin