Skip to content

Instantly share code, notes, and snippets.

View jensendarren's full-sized avatar

Darren Jensen jensendarren

View GitHub Profile

Keybase proof

I hereby claim:

  • I am jensendarren on github.
  • I am jensendarren (https://keybase.io/jensendarren) on keybase.
  • I have a public key ASCUxtscnfGIjSlMCwIboYoEa2sGTmteWlwklL9PgF72xAo

To claim this, I am signing this object:

@jensendarren
jensendarren / bashrc
Created July 27, 2015 01:51
Add git alias to your terminal command set
# Add this to your ~/.bashrc file then run `source ~/.bashrc`
alias gs='git status '
alias ga='git add '
alias gb='git branch '
alias gc='git commit'
alias gd='git diff'
alias gg='git grep -i'
alias go='git checkout '
@jensendarren
jensendarren / gist:e5614e19db0dcf96fa44
Created July 9, 2015 04:16
Git diff which includes new files
if test "$#" = 0; then
(
git diff
git ls-files --others --exclude-standard |
while read -r i; do git diff -- /dev/null "$i"; done
)
else
git diff "$@"
fi
@jensendarren
jensendarren / uri_example.rb
Created January 8, 2015 12:48
An example of using URI in Ruby
require 'uri'
require 'open-uri'
google_url = "http://google.com/"
url = URI.parse(google_url)
# Get the hostname
puts "The hostname is #{url.hostname}"
@jensendarren
jensendarren / optparse_example.rb
Created January 8, 2015 12:48
An example of using OptionParser in Ruby
# Restrict arguments to a specified class.
require 'optparse'
class HelloParser
def self.parse(args)
options = {}
opts = OptionParser.new do |opts|
opts.banner = "Usage: name"
opts.on('-n', '--name NAME', 'The name of the person to say hello to') do |name|
@jensendarren
jensendarren / logger_example_stdout.rb
Created January 8, 2015 12:47
An example of using STDOUT Logger in Ruby
# http://www.ruby-doc.org/stdlib-2.1.0/libdoc/logger/rdoc/Logger.html
require 'logger'
class CoffeeShop
attr_reader :logger
def initialize(name)
@name = name
@menu = []
@logger = Logger.new(STDOUT)
@jensendarren
jensendarren / logger_file_example.rb
Created January 8, 2015 12:47
An example of using a file Logger in Ruby
require 'logger'
class CoffeeShop
attr_reader :std_logger, :file_logger
def initialize(name)
@name = name
@menu = []
@std_logger = Logger.new(STDOUT)
@file_logger = Logger.new('./coffee_shop.log')
@jensendarren
jensendarren / fileutils_example.rb
Created January 8, 2015 12:46
An example of using FileUtils in Ruby
require 'fileutils'
# __FILE__ keyword in ruby
puts "The current ruby file being executed is #{__FILE__}"
# Gets the directory name of the file being executed
current_directory = File.dirname(__FILE__)
puts "The current directory is #{current_directory}"
# expands to reveal the pwd (Present working directory)
@jensendarren
jensendarren / benchmark_example.rb
Last active August 29, 2015 14:13
An example of using Benchmark lib in Ruby
require 'benchmark'
# Compare sorting a Hash with an Array
arr = []
hash = {}
10_000.times.with_index do |i|
ascii_code = rand(255)
random_char = ascii_code.chr
arr << random_char
@jensendarren
jensendarren / obervable_example.rb
Last active June 27, 2018 08:30
Example of using Observable in Ruby
require 'observer'
class CoffeeShop
include Observable
attr_reader :customers
def initialize(name, capacity)
@name = name
@capacity = capacity
@customers = []