Skip to content

Instantly share code, notes, and snippets.

View coreyward's full-sized avatar

Corey Ward coreyward

View GitHub Profile
@coreyward
coreyward / baseline_tattler.js
Last active August 29, 2015 13:57
Quick and dirty way to find DOM elements that are breaking your vertical baseline grid.
$('div,p,section,header,footer,ul,ol,li').each(function(){
var h, el, baseline;
el = $(this);
height = el.outerHeight();
baseline = 13;
if (Math.round(height) % baseline > 0) {
el.addClass('boink');
console.log( height, this );
@coreyward
coreyward / gist:e34898d09968f5aa4aa6
Created June 30, 2014 21:13
Non-blocking iFrame loads, because Vimeo embeds are slow to load, and iFrames block onLoad firing (and thus negatively impact pageload measurements).
# Non-Blocking iFrames
$ ->
$('iframe[data-src]').each ->
this.setAttribute 'src', this.getAttribute 'data-src'
@coreyward
coreyward / gist:60b7eb23373f40f9ebcb
Created June 30, 2014 21:21
Track outbound link clicks in Google Analytics (Universal / analytics.js) with fallback
# only bind if/when GA loads
ga ->
$('a[href*="//"]').click (e) ->
e.preventDefault()
url = $(this).attr('href')
# define the callback
action = -> document.location = url
# record the click as an event

Keybase proof

I hereby claim:

  • I am coreyward on github.
  • I am coreyward (https://keybase.io/coreyward) on keybase.
  • I have a public key whose fingerprint is 588A B309 8DE7 3379 60A5 6BE5 8095 E17F 15D4 EE89

To claim this, I am signing this object:

@coreyward
coreyward / README
Created October 14, 2010 21:52
Ruby wrapper to `mysqldump`. Intended to make setting up automatic cronjob backups easier by avoiding bash scripting.
Usage:
ruby mysql_backup.rb db:name [user:your_username] \
[password:your_password] \
[host:your_hostname] \
[file:output_file.sql]
Feel free to use, improve, etc. I'm new to Ruby, so excuse anything that makes your palm slap your forehead. ;)
@coreyward
coreyward / check_imap_mail.rb
Created November 27, 2010 19:31
Fetch emails from a Gmail account via IMAP for processing
# Via http://blog.ethanvizitei.com/2008/06/using-ruby-for-imap-with-gmail.html
imap = Net::IMAP.new(@config['server'],@config['port'],true)
imap.login(@config['username'], @config['password'])
imap.select('INBOX')
imap.search(["NOT", "DELETED"]).each do |message_id|
MailFetcher.receive(imap.fetch(message_id, "RFC822")[0].attr["RFC822"])
imap.store(message_id, "+FLAGS", [:Deleted])
end
imap.logout()
@coreyward
coreyward / range.random.rb
Created December 10, 2010 03:14
Easy random numbers (or letters) from a range
class Range
def pick
if min.is_a? Fixnum
rand(count) + min
else
self.to_a[rand(count)]
end
end
alias :random :pick
end
@coreyward
coreyward / Explicit Block vs Symbol#to_proc.rb
Created February 16, 2011 22:17
A quick benchmark to confirm/dispel performance concerns over using `.map(&:to_i)` instead of a literal block (`.map { |x| x.to_i }`).
require 'benchmark'
n = 100000
a = %w{ 1 2 3 4 5 6 7 8 9 0 }
Benchmark.bmbm do |b|
b.report 'Explicit Block' do
n.times do
a.map { |x| x.to_i }
end
@coreyward
coreyward / cloudfiles_test.rb
Created February 23, 2011 01:25
Test cloudfiles gem for thread safety through trial and error...
require 'rubygems'
require 'cloudfiles'
class Hash
def reverse_merge(other_hash)
other_hash.merge(self)
end
end
class Cloud
@coreyward
coreyward / gist:937889
Created April 22, 2011 22:56
Quickly add a git remote mirror
# because I always forget the magic sequence of commands…
ssh host 'git init --bare /var/src/repo.git'
git remote add mirror --mirror host/var/src/repo.git
git push mirror # tada