Skip to content

Instantly share code, notes, and snippets.

View jeremyf's full-sized avatar

Jeremy Friesen jeremyf

View GitHub Profile
DEFAULT_POWER = 10
def exponent(integer, power: DEFAULT_POWER, **keywords)
integer ** power
end
puts exponent(10, power: 2)
puts exponent(10)
[user]
name = Jeremy Friesen
email = jeremy.n.friesen@gmail.com
[color]
branch = auto
diff = auto
status = auto
[color "branch"]
current = red reverse
local = red bold
# Two spiffy github commands. One is to go to the appropriate branch
# The other is to open up the issues, allowing for passing a param and opening
# the specific issue
[alias]
# Open the current branch on github
hub = "! br=$(git branch --contains HEAD | sed -En \"s/^\\* //p\"); if ! git ls-remote . | grep -q -e \"refs/remotes/.*/${br}\"; then br=\"master\"; fi; open $(git config -l | sed -En \"s%remote.origin.url=git(@|://)(github.com)(:|/)(.+/.+).git%https://\\2/\\4/tree/${br}%p\")"
# Go to the github project's issues
# $ git hub-issue
# => open browser and go to project's issues
class Foo
class << self
def bar; 'class bar'; end
protected :bar
end
def bar; 'instance bar'; end
end
if $0 == __FILE__
begin
@jeremyf
jeremyf / snippet.rb
Created February 12, 2010 22:30
Compare two files
require 'pathname'
# Compares two files for "similar" look, ignoring
# where elements are in the document.
def collect_unique_lines(*args)
dir = Pathname.new(Rails.root.join('tmp'))
contents = File.read(dir.join(args.join('.'))).split("\n")
lines = []
# proposed_lines = []
contents.inject(lines) {|mem,string|
#!bash
#
# bash completion support for core Git.
#
# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
# Distributed under the GNU General Public License, version 2.0.
#
# The contained completion routines provide support for completing:
#
# ~/.gitconfig
[alias]
# Open the current branch on github
hub = "! br=$(git branch --contains HEAD | sed -En \"s/^\\* //p\"); if ! git ls-remote . | grep -q -e \"refs/remotes/.*/${br}\"; then br=\"master\"; fi; open $(git config -l | sed -En \"s%remote.origin.url=git(@|://)(github.com)(:|/)(.+/.+).git%https://\\2/\\4/tree/${br}%p\")"
# Go to the lighthouse project, your config will need to have set the subdomain and project
# If branch begins with a number (0-9), then open that ticket # in Lighthouse
# Otherwise, go to milestones/current
lighthouse = "! ref=\"milestones/current\"; ticket=$(git branch --contains HEAD | sed -En \"s/^\\* //p\" | grep -e \"^[0-9]\" | awk '{print \"tickets/\"$1}'); if [[ -n \"${ticket}\" ]]; then ref=\"${ticket}\"; fi; open https://$(git config lighthouse.subdomain).lighthouseapp.com/projects/$(git config lighthouse.project)/${ref}"
# I need class C to call the foo method for each module included
# that has the method foo. Order does not matter as much as each
# method getting called. alias method chain?
module ChainMethod
def chain_method(method_name)
base_method = instance_method(method_name.to_sym)
chained_method = included_modules.inject([base_method]) do |mem, mod|
if method = (mod.instance_methods.include?(method_name.to_s) ? mod.instance_method(method_name.to_sym) : nil)
mem << method
end
@jeremyf
jeremyf / .gitconfig
Created September 10, 2015 20:20
A git config with lots of things going on
# Sample gitconfig
#
[hub]
protocol = https
[user]
name = Jeremy Friesen
email = jeremy.n.friesen@gmail.com
[credential]
helper = osxkeychain
[github]
@jeremyf
jeremyf / processing_queries.rb
Created September 11, 2015 18:25
farewell-my-arel-friend.rb
# @api public
#
# An ActiveRecord::Relation scope that meets the following criteria:
#
# * Users that are directly associated with the given entity through on or
# more of the given roles
# * Users that are indirectly associated with the given entity by group
# and role.
#
# @param roles [Sipity::Models::Role]