Skip to content

Instantly share code, notes, and snippets.

View matthewlehner's full-sized avatar
👻

Matthew Lehner matthewlehner

👻
View GitHub Profile
@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 / 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 / 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 / application.rb
Created October 26, 2015 19:22
SystemJS config for sprockets-es6
config.assets.configure do |env|
env.register_transformer 'text/ecmascript-6',
'application/javascript',
Sprockets::ES6.new('modules' => 'system',
'moduleIds' => true)
end
@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 / 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
});
def upload(filename, file_location)
bucket = AWS::S3::Bucket.new(ENV["AWS_BUCKET_NAME"])
key = "uploads/#{SecureRandom.uuid}/#{filename}"
content_type = MIME::Types.type_for(filename).first.to_s
presigned_post = bucket.presigned_post(key: key, content_type: content_type)
url = presigned_post.url.to_s
fields = presigned_post.fields
`curl -i -v -X POST -F "AWSAccessKeyId=#{fields['AWSAccessKeyId']}" -F "key=#{fields['key']}" -F "policy=#{fields['policy']}" -F "signature=#{fields['signature']}" -F "Content-Type=#{content_type}" -F "file=@#{file_location + filename}" '#{url}'`
end
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.0/handlebars.js"></script>
<script src="http://builds.emberjs.com/canary/ember.prod.js"></script>
</head>
@matthewlehner
matthewlehner / heroku_pg_pull.sh
Last active January 4, 2016 10:49
zsh (maybe bash too?) scripts for pulling and pushing Heroku dbs
# Postgres equivalent to heroku db:pull.
# Pulls latest heroku pgbackups dump into local database
#
# Usage:
#
# $ heroku_pg_pull [appname] [local database name]
#
function heroku_pg_pull(){
echo "! WARNING: Data in the local database '$2' will be destroyed."
echo " Type '$2' to overwrite data in local database '$2'"
@matthewlehner
matthewlehner / reducer_spec.js
Created January 7, 2016 18:44
Writing tests for redux reducers
import { expect } from "chai";
import reducer from "../../src/reducers/workspace";
import { EDIT_ITEM } from "../../src/actions/workspace";
describe("workspace reducer", () => {
it("handles EDIT_ITEM", () => {
const initialState = {};
const action = {
type: EDIT_ITEM,
itemIndex: 1