Skip to content

Instantly share code, notes, and snippets.

Avatar

Joël Quenneville JoelQ

  • Thoughtbot
  • Boston
View GitHub Profile
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
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
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
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
@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 README.md

Server scripts

This is the source for the scripts discussed in https://robots.thoughtbot.com/improving-user-experience-with-shell-scripts

Both scripts are in the bin/ directory of the repo that contains all the markdown documents for blog posts. Users run bin/server and everything is automatically set up for them to view a local preview of the blog. bin/server-setup is a dependency of bin/server and is never run directly by users.

Maitre-d is the name of the "blog engine" discussed in the article.

@JoelQ
JoelQ / Ball.elm
Last active Oct 23, 2019
Gravity and Ball
View Ball.elm
import Graphics.Collage exposing (..)
import Graphics.Element exposing (..)
import Color exposing (..)
import Keyboard
import Time
import Debug
-- Model
type alias Model = { x : Float, y : Float, radius: Float }