Skip to content

Instantly share code, notes, and snippets.

Avatar

Joël Quenneville JoelQ

  • Thoughtbot
  • Boston
View GitHub Profile
@JoelQ
JoelQ / dir.rb
Last active Aug 29, 2015
__dir__ and others
View dir.rb
# all outputs should be the same
puts __dir__
puts File.expand_path(__dir__)
puts File.expand_path File.dirname(__FILE__)
puts File.expand_path("../", __FILE__)
@JoelQ
JoelQ / dir_comparison.rb
Created Jan 8, 2015
__dir__ comparison
View dir_comparison.rb
puts "__dir__ is the same as File.expand_path(__dir__)"
puts __dir__ == File.expand_path(__dir__)
puts "__dir__ is the same as File.expand_path( File.dirname(__FILE__) )"
puts __dir__ == File.expand_path( File.dirname(__FILE__) )
puts "__dir__ is the same as File.expand_path('../', __FILE__)"
puts __dir__ == File.expand_path("../", __FILE__)
# Script Output:
View .bash_profile
# Show branch in status line
PS1='[\w]$ '
#PS1="\u$ \w: "
alias ll="ls -lahG"
alias subl='open -a "Sublime Text 2"'
# Git bash completion
if [ -f `brew --prefix`/etc/bash_completion ]; then
. `brew --prefix`/etc/bash_completion
@JoelQ
JoelQ / before.rb
Last active Dec 11, 2015
Example refactoring using Introduce Explaining Variable
View before.rb
def convert_to_media(link)
if URI.split(link)[5].end_with? 'png', 'gif', 'jpeg'
"<img src=\"#{link}\" />"
elsif URI.split(link)[2].include?("youtube") && URI.split(link)[7] && URI.split(link)[7].include?('v=')
video_id = URI.split(link)[7][2..-1]
"<iframe width=\"560\" height=\"315\" src=\"http://www.youtube.com/embed/#{video_id}\" frameborder=\"0\" allowfullscreen></iframe>"
elsif URI.split(link)[2].include? "youtu.be"
video_id = URI.split(link)[5].gsub('/', '')
"<iframe width=\"560\" height=\"315\" src=\"http://www.youtube.com/embed/#{video_id}\" frameborder=\"0\" allowfullscreen></iframe>"
else
@JoelQ
JoelQ / before.rb
Last active Dec 11, 2015
Example refactoring for Extract Method
View before.rb
require 'uri'
class MediaParser
def initialize(text)
@text = text
@links = URI.extract @text
end
def parse_links
@JoelQ
JoelQ / before.rb
Created Jan 15, 2013
Example refactoring for RenameMethod
View before.rb
require 'uri'
class MediaParser
def initialize(text)
@text = text
@links = URI.extract @text
end
def parse_links
@JoelQ
JoelQ / before.rb
Last active Dec 11, 2015
Refactoring example for Extract Class
View before.rb
require 'uri'
class MediaParser
def initialize(text)
@text = text
@links = URI.extract @text
end
def parse_links
@JoelQ
JoelQ / before.rb
Last active Dec 11, 2015
Refactoring example for Replace Conditional with Polymorphism
View before.rb
require 'uri'
class MediaParser
def initialize(text)
@text = text
@links = URI.extract @text
end
def parse_links
View 1-documentation.md

Ruby docs for Array#uniq

From the docs:

uniq → new_ary uniq { |item| ... } → new_ary Returns a new array by removing duplicate values in self.

If a block is given, it will use the return value of the block for comparison. It compares values using their hash and eql? methods for efficiency.

View intro_to_elm_slide_notes.md

What is Elm

Pure Functions

What does that mean?

  • For a given input, you always get the same output
  • The output cannot depend on any external factors (e.g. File on disk, some external variable)