Skip to content

Instantly share code, notes, and snippets.

@JoelQ
JoelQ / .bash_profile
Created June 6, 2012 17:41
My 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 December 11, 2015 03:58
Example refactoring using Introduce Explaining Variable
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 January 15, 2013 19:45
Example refactoring for RenameMethod
require 'uri'
class MediaParser
def initialize(text)
@text = text
@links = URI.extract @text
end
def parse_links
@JoelQ
JoelQ / before.rb
Last active December 11, 2015 03:58
Example refactoring for Extract Method
require 'uri'
class MediaParser
def initialize(text)
@text = text
@links = URI.extract @text
end
def parse_links
@JoelQ
JoelQ / before.rb
Last active December 11, 2015 03:59
Refactoring example for Extract Class
require 'uri'
class MediaParser
def initialize(text)
@text = text
@links = URI.extract @text
end
def parse_links
@JoelQ
JoelQ / before.rb
Last active December 11, 2015 04:08
Refactoring example for Replace Conditional with Polymorphism
require 'uri'
class MediaParser
def initialize(text)
@text = text
@links = URI.extract @text
end
def parse_links
@JoelQ
JoelQ / dir.rb
Last active August 29, 2015 14:13
__dir__ and others
# 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 January 8, 2015 16:45
__dir__ comparison
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:
@JoelQ
JoelQ / README.md
Created October 15, 2015 13:50
Using Shell Scripts for a Better User Experience (source for https://robots.thoughtbot.com/improving-user-experience-with-shell-scripts)

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 October 23, 2019 18:10
Gravity and Ball
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 }