Skip to content

Instantly share code, notes, and snippets.

@chrismealy
chrismealy / how-to-squash-commits-in-git.md
Created November 3, 2017 18:09 — forked from patik/how-to-squash-commits-in-git.md
How to squash commits in git

Squashing Git Commits

The easy and flexible way

This method avoids merge conflicts if you have periodically pulled master into your branch. It also gives you the opportunity to squash into more than 1 commit, or to re-arrange your code into completely different commits (e.g. if you ended up working on three different features but the commits were not consecutive).

Note: You cannot use this method if you intend to open a pull request to merge your feature branch. This method requires committing directly to master.

Switch to the master branch and make sure you are up to date:

@chrismealy
chrismealy / gist:29540dfc1dfd62cc7e08846b836e1aad
Created January 17, 2017 06:13 — forked from jordan-brough/gist:1926410
ruby count_by using group_by
# See http://jordan.broughs.net/archives/2012/07/enumerablecount_by-for-ruby
# Ruby >= 1.8.7 (incl 1.9.x)
module Enumerable
def count_by(&block)
Hash[group_by(&block).map { |key,vals| [key, vals.size] }]
end
end
javascript:(function(){var newSS, styles='* { background:white ! important; color: black !important; text-decoration: none !important } :link, :link * { color: #0000EE !important } :visited, :visited * { color: #551A8B !important }'; if(document.createStyleSheet) { document.createStyleSheet("javascript:'"+styles+"'"); } else { newSS=document.createElement('link'); newSS.rel='stylesheet'; newSS.href='data:text/css,'+escape(styles); document.getElementsByTagName("head")[0].appendChild(newSS); } })();
@chrismealy
chrismealy / Gemfile
Created September 13, 2012 19:54
Rails Lightweight Stack. Most of this is detailed on Crafting Rails Applications - http://pragprog.com/book/jvrails/crafting-rails-applications
source :rubygems
# We are not loading Active Record, nor Active Resources etc.
# We can do this in any app by simply replacing the rails gem
# by the parts we want to use.
gem "actionpack", "~> 3.2"
gem "railties", "~> 3.2"
gem "tzinfo"
# Let's use thin
@chrismealy
chrismealy / request_debug_helpers.rb
Created July 18, 2012 23:05 — forked from henrik/request_debug_helpers.rb
show_page debug helper for RSpec request specs that opens or reloads page in Chrome.
module RequestDebugHelpers
DEBUG_URL = "http://example.dev/debug.html"
def show_page
filename = File.join(Rails.root, 'public', 'debug.html')
File.open(filename, 'w') do |f|
f.puts page.body.gsub("</title>", " (#{ current_path })\\0")
end
system "osascript", "-e", <<-OSASCRIPT
@chrismealy
chrismealy / async_job.rb
Created July 17, 2012 13:27
A simple module to add async method to your activerecord or other ruby objects
module Resque
module AsyncJob
@@_queue= :default
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
# Set the default queue. chain method
def queue(new_queue = nil)
@chrismealy
chrismealy / async_resque.rb
Created July 17, 2012 13:22 — forked from michelson/async_resque.rb
Use async methods for Sidekiq & Resque
# -*- encoding : utf-8 -*-
module AsyncResque
extend ActiveSupport::Concern
included do
include Sidekiq::Worker
def perform(*args)
self.class.find(args.first).send(args.last)
end
end
@chrismealy
chrismealy / zip-dirs
Created July 1, 2012 05:28
create a zip file for each directory
find . -mindepth 1 -maxdepth 1 -type d -print0 |xargs -0 -I {} zip -r "{}.zip" "{}"
@chrismealy
chrismealy / gist:2714207
Created May 16, 2012 21:44 — forked from kevindavis/gist:1868651
Bootstrap styling for jQuery UI autocomplete
.ui-autocomplete {
position: absolute;
top: 100%;
left: 0;
z-index: 1000;
float: left;
display: none;
min-width: 160px;
_width: 160px;
padding: 4px 0;
@chrismealy
chrismealy / fztyph.rb
Created May 8, 2012 21:17
feedzirra_typhoeus_example
require 'feedzirra'
require 'typhoeus'
f = Feedzirra::Feed.fetch_and_parse('http://krugman.blogs.nytimes.com/feed/')
urls = f.entries.map &:url
h = Typhoeus::Hydra.new
urls.map do |url|
r = Typhoeus::Request.new(url)
r.on_complete {|rsp| puts rsp.body[400..500] }
h.queue(r)