Skip to content

Instantly share code, notes, and snippets.

View hayesr's full-sized avatar

Eric Hayes hayesr

View GitHub Profile
# Monitor HTTP requests being made from your machine with a one-liner..
# Replace "en1" below with your network interface's name (usually en0 or en1)
sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E "Host\: .*|GET \/.*"
# OR.. to be able to use as "httpdump" from anywhere, drop this into ~/.bash_profile:
# (again replace "en1" with correct network interface name)
alias httpdump="sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E "Host\: .*|GET \/.*""
# All the above tested only on OS X.
// Provides a device_scale class on iOS devices for scaling user
// interface elements relative to the current zoom factor.
//
// http://37signals.com/svn/posts/2407-device-scale-user-interface-elements-in-ios-mobile-safari
// Copyright (c) 2010 37signals.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@hayesr
hayesr / mongoid version diff
Created June 23, 2012 18:21 — forked from beanieboi/mongoid version diff
shows the diff between two versions when you use Mongoid::Versioning
def compare_to(version)
reject_fields = ["_id", "updated_at", "version"]
diff_array = self.versions[version-1].attributes.to_hash.to_a - self.attributes.to_hash.to_a
diff_array.delete_if {|f| reject_fields.include?(f.first) }
Hash[diff_array]
end
@hayesr
hayesr / vm-ubuntu-rails.sh
Last active December 13, 2015 23:29
Fresh Ubuntu to Rails ready, on VirtualBox
# Virtual Box Instructions
# --------------------------------
# 1. Install VirtualBox Oracle VM VirtualBox Extension Pack.
# 2. Install deps for Guest Additions
sudo apt-get install dkms build-essential linux-headers-$(uname -r)
# 3. Install Guest Additions (from CD)
sh ./VBoxLinuxAdditions.run
@hayesr
hayesr / _hmt_fixture_bug.rb
Created August 23, 2015 04:28
Timestamp columns are not auto populated for hm:t join tables
ENV['FIXTURES_DIR'] = "./"
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
function preresolve(dq)
if dq.qname:equal("www.google.com") then
dq:addAnswer(pdns.CNAME, "forcesafesearch.google.com.")
dq.rcode = 0
dq.followupFunction="followCNAMERecords" -- this makes PowerDNS lookup your CNAME
return true;
end
return false;
end
@hayesr
hayesr / application_helper.rb
Last active July 8, 2016 14:56
Simple Presenter System
module ApplicationHelper
def present(object, klass = nil)
klass ||= "#{object.class}Presenter".constantize
presenter = klass.new(object, self)
yield presenter if block_given?
presenter
end
end
@hayesr
hayesr / find_actions_without_params.rb
Last active March 22, 2017 04:54
Find action lines in controller tests without params keyword (for Rails 5)
/(?:get|put|post|patch)\s+:\w+,\s+(?!params).+/
@hayesr
hayesr / image-to-color.md
Last active July 15, 2017 18:47
Extract colors from an image using ImageMagick
@hayesr
hayesr / rails-jsonb-queries.rb
Last active December 13, 2018 15:12 — forked from mankind/rails-jsonb-queries
Rails-5 Postgres 9.6+ JSONB queries
# http://stackoverflow.com/questions/22667401/postgres-json-data-type-rails-query
# http://stackoverflow.com/questions/40702813/query-on-postgres-json-array-field-in-rails
# payload: [{"kind"=>"person"}]
Segment.where("payload @> ?", [{kind: "person"}].to_json)
# data: {"interest"=>["music", "movies", "programming"]}
Segment.where("data @> ?", {"interest": ["music", "movies", "programming"]}.to_json)
Segment.where("data #>> '{interest, 1}' = 'movies' ")
Segment.where("jsonb_array_length(data->'interest') > 1")