Skip to content

Instantly share code, notes, and snippets.

View matthewlehner's full-sized avatar
👻

Matthew Lehner matthewlehner

👻
View GitHub Profile
@matthewlehner
matthewlehner / deviceorientation-log.js
Created June 12, 2013 19:55
Experiments with deviceorientation.
window.addEventListener('deviceorientation', function(eventData) {
// The compass direction - will return a value between 0 and 360
eventData.alpha
// Side to side value - will return a value between -180 and 180
eventData.beta
// Front to back value - will return a value between -90 and 90
eventData.gamma
});
@matthewlehner
matthewlehner / index.html
Last active December 18, 2015 09:39
A CodePen by Matthew Lehner.
<div id='background'>
<div id='foreground'>
Here we have a foreground object.
</div>
</div>
@matthewlehner
matthewlehner / Guardfile
Created September 15, 2012 01:49
Rails 3 guard-livereload guard
# This assumes you use sass requires for css, not sprockets.
guard 'livereload' do
watch(%r{app/.+\.(erb|haml)})
watch(%r{app/helpers/.+\.rb})
watch(%r{app/assets/stylesheets/(.+\.css).*$}) { |m| "assets/#{m[1]}" }
watch(%r{app/assets/javascripts/(.+\.js).*$}) { |m| "assets/#{m[1]}" }
watch(%r{(app|vendor)/assets/.+\.(sass|scss)}) { '/assets/all/application.css' }
watch(%r{public/.+\.(css|js|html)})
watch(%r{config/locales/.+\.yml})
@matthewlehner
matthewlehner / google_maps_images_helper.rb
Created August 30, 2012 01:11
Google Maps Images API view helper method for Rails
def map_image(lat, lng, options = {})
options[:zoom] ||= '14'
options[:dimensions] ||= '125x125'
options[:sensor] ||= false
options[:scale] ||= '1' # Pixel density, '2' for Retina.
options[:marker_size] ||= 'small'
options[:alt] ||= ''
url = "http://maps.googleapis.com/maps/api/staticmap?size=#{options[:dimensions]}&zoom=#{options[:zoom]}&sensor=#{options[:sensor]}&markers=size:#{options[:marker_size]}|#{lat},#{lng}"
@matthewlehner
matthewlehner / compass-retina-sprites.scss
Created August 1, 2012 20:50 — forked from thulstrup/compass-retina-sprites.scss
Using Compass to generate normal and retina sprite maps
$sprites: sprite-map("sprites/*.png");
$sprites-retina: sprite-map("sprites-retina/*.png");
@mixin sprite-background($name) {
background-image: sprite-url($sprites);
background-position: sprite-position($sprites, $name);
background-repeat: no-repeat;
display: block;
height: image-height(sprite-file($sprites, $name));
width: image-width(sprite-file($sprites, $name));
@matthewlehner
matthewlehner / gist:3185769
Created July 27, 2012 01:59
patient post help
post: ->
patientJSON = @toJSON()
patientJSON['responses'] = {}
for response in @responses().all()
patientJSON['responses'][response.question_id] = response.toJSON()['answer']
# looks weird, cause a Question has a 'question' attribute.
patientJSON['responses'][response.question_id]['question'] = response.question.question
$.post 'http://thenumbercreative.com/regurgitate_data', patientJSON
@matthewlehner
matthewlehner / autopgsqlbackup
Created July 11, 2012 16:10
Auto PostgreSQL backup script.
#!/bin/bash
#
# PostgreSQL Backup Script Ver 1.0
# http://autopgsqlbackup.frozenpc.net
# Copyright (c) 2005 Aaron Axelsen <axelseaa@amadmax.com>
#
# This script is based of the AutoMySQLBackup Script Ver 2.2
# It can be found at http://sourceforge.net/projects/automysqlbackup/
#
# The PostgreSQL changes are based on a patch agaisnt AutoMySQLBackup 1.9
@matthewlehner
matthewlehner / user.rb
Created May 30, 2012 17:47 — forked from andresgutgon/user.rb
Migrate Authlogic SHA512 Passwords to BCryt
# Because we have some old legacy users in the database, we need to
# override #has_secure_passwords' method for checking if a password is valid.
# We first ask if the password is valid, and if it throws an InvalidHash
# exception, we know that we're dealing with a legacy user, so we check the
# password against the SHA1 algorithm that was used to hash the password in
# the old database.
#SOURCES OF SOLUTION:
# http://stackoverflow.com/questions/6113375/converting-existing-password-hash-to-devise
# https://github.com/binarylogic/authlogic/blob/master/lib/authlogic/crypto_providers/sha512.rb
@matthewlehner
matthewlehner / nesting.coffee
Created March 7, 2012 00:41 — forked from lagartoflojo/nesting.coffee
Helper function for nesting Backbone collections (CoffeeScript version)
Backbone.Model::nestCollection = (attributeName, nestedCollection) ->
#setup nested references
for item, i in nestedCollection
@attributes[attributeName][i] = nestedCollection.at(i).attributes
#create empty arrays if none
nestedCollection.bind 'add', (initiative) =>
if !@get(attributeName)
@attributes[attributeName] = []
@get(attributeName).push(initiative.attributes)
@matthewlehner
matthewlehner / nesting.js
Created March 7, 2012 00:39 — forked from geddski/nesting.js
helper function for nesting backbone collections.
function nestCollection(model, attributeName, nestedCollection) {
//setup nested references
for (var i = 0; i < nestedCollection.length; i++) {
model.attributes[attributeName][i] = nestedCollection.at(i).attributes;
}
//create empty arrays if none
nestedCollection.bind('add', function (initiative) {
if (!model.get(attributeName)) {
model.attributes[attributeName] = [];