Skip to content

Instantly share code, notes, and snippets.

View thermistor's full-sized avatar
🏠
Working from home

Weston Triemstra thermistor

🏠
Working from home
View GitHub Profile
// Original code from http://www.blog.highub.com/mobile-2/a-fix-for-iphone-viewport-scale-bug/
var metas = document.getElementsByTagName('meta');
var i;
if (navigator.userAgent.match(/iPhone/i)) {
for (i=0; i<metas.length; i++) {
if (metas[i].name == "viewport") {
metas[i].content = "width=device-width, minimum-scale=1.0, maximum-scale=1.0";
}
}
@paulirish
paulirish / rAF.js
Last active March 22, 2024 00:00
requestAnimationFrame polyfill
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
// MIT license
(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
@coreyhaines
coreyhaines / .rspec
Last active April 11, 2024 00:19
Active Record Spec Helper - Loading just active record
--colour
-I app
@mperham
mperham / after.rb
Created July 4, 2012 19:30
Thread-friendly shared connection
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || ConnectionPool::Wrapper.new(:size => 1) { retrieve_connection }
end
end
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
@rmurphey
rmurphey / gist:3086328
Created July 10, 2012 21:23
What's wrong with Netmag's "Optimize your JavaScript" post

What's wrong with Netmag's "Optimize your JavaScript" post

Update: The original post on Netmag has been updated since this was written.

I tweeted earlier that this should be retracted. Generally, these performance-related articles are essentially little more than linkbait -- there are perhaps an infinite number of things you should do to improve a page's performance before worrying about the purported perf hit of multiplication vs. division -- but this post went further than most in this genre: it offered patently inaccurate and misleading advice.

Here are a few examples, assembled by some people who actually know what they're talking about (largely Rick Waldron and Ben Alman, with some help from myself and several others from the place that shall be unnamed).

Things that are just plain wrong

@lokimeyburg
lokimeyburg / msp_number_generator.rb
Created October 26, 2012 23:43
Generate your own valid Canadian Medical Services Plan number.
def valid_msp_number(msp_number)
weights = [0, 2, 4, 8, 5, 10, 9, 7, 3, 0]
total = 0
weights.to_enum.with_index(1).each do |weight, i|
total = total + msp_number[i-1].to_i * weight.to_i
end
a = total / 11
b = a * 11
c = total - b
result = 11 - c
@maxjustus
maxjustus / bulk_insert.rb
Last active March 14, 2018 17:38
Simple SQL bulk insert in Rails
# Takes a table name, and an array of hashes where keys are column names and values are values.
# Expects hashes to all contain the same keys.
def bulk_insert(table, rows)
columns = rows.first.keys
to_insert = rows.map do |d|
vals = columns.map {|k| d[k] }
ActiveRecord::Base.send(:replace_bind_variables, "(#{vals.length.times.collect {'?'}.join(',')})", vals)
end
@thisisbrians
thisisbrians / jquery-time-zone-select.js
Created February 3, 2013 00:08
Dynamically select a timezone in a Rails time_zone_select based on the browser's timezone using jQuery/JavaScript.
jQuery.fn.selectTimeZone = function() {
var $el = $(this[0]); // our element
var offsetFromGMT = String(- new Date('1/1/2009').getTimezoneOffset() / 60); // using 1/1/2009 so we know DST isn't tripping us up
if (offsetFromGMT[0] != '-') {
offsetFromGMT = '+' + offsetFromGMT; // if it's not negative, prepend a +
}
if (offsetFromGMT.length < 3) {
offsetFromGMT = offsetFromGMT.substr(0, 1) + '0' + offsetFromGMT.substr(1); // add a leading zero if we need it
}
var regEx = new RegExp(offsetFromGMT); // create a RegExp object with our pattern
@kixorz
kixorz / aws_iam_policy.json
Last active April 11, 2022 10:32
Update Route53 DNS records from your EC2 instance using this simple Ruby script. You can call it from rc.local after setting your hostname locally. First parameter is the desired <hostname>.<domain> Domain and other parameters are hardcoded. This script is useful for handling internal DNS changes in your systems after instance changes. Attached …
{
"Statement": [
{
"Action": [
"route53:ChangeResourceRecordSets",
"route53:GetHostedZone",
"route53:ListResourceRecordSets"
],
"Effect": "Allow",
"Resource": [
@passy
passy / yeoman_compass.md
Last active January 7, 2016 19:24
Using Yeoman with Compass Sprites

Yeoman + Compass Sprites

Setup

generator-webapp has support for compass out of the box. However, in order to use one of my favorite features of it — sprites and the image_url helper — you have to make some adjustments to the Gruntfile.

Let's assume you use a SASS stylesheet like this one:

@import "design/*.png"