Skip to content

Instantly share code, notes, and snippets.

View Breefield's full-sized avatar

Bree Hoffman Breefield

View GitHub Profile
@Breefield
Breefield / hexagon.js
Created August 12, 2012 04:12
Drawing a Hexagon with Paper.js
// Create a Paper.js Path to draw a line into it:
var hexagon = new Path();
// Color our path black
hexagon.strokeColor = 'black';
// How many points do we want our object to have
var points = 6;
// How large should it be
var radius = 60;
// 0 to 2PI is a circle, so divide that by the number of points
@Breefield
Breefield / hexagon-canvas.html
Created August 12, 2012 04:23
Hexagon Canvas
<!DOCTYPE html>
<html lang='en'>
<head>
<title>Hexagon</title>
</head>
<body>
<!-- Create a canvas and give it the attribute "resize" this tells Paper.js the canvas should be the size of the entire browser window -->
<canvas id='background-hexagons' resize></canvas>
// Create a new hexagon with a radius of 100px at Point 200, 200
var hexagon = new Path.RegularPolygon(new Point(200, 200), 6, 100);
@Breefield
Breefield / example.js
Created August 20, 2012 06:24
Call/Apply
// You wrote this line
Function.prototype.call(current[ev], this, arguments);
// This line does what I want, calling the method on the current tool and passing the arguments.
current[ev].apply(this, arguments);
// Not sure what you were aiming for with the other line?
@Breefield
Breefield / phantom.js
Created September 9, 2012 03:40
PhantomJS Custom Headers
var page = require('webpage').create();
// User-Agent is supported through page.settings
page.settings.userAgent = 'Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25';
// This is how you set other header variables
page.customHeaders = {'Referer': 'localhost'};
@Breefield
Breefield / sm.js
Created September 14, 2012 07:30
soundmanager
soundManager.onready(function() {
hyperlips = soundManager.createSound({
id: 'hyperlips',
url: 'cathode_girls.mp3',
autoPlay: true,
volume: 50,
whileplaying: function() {
this.waveform = {points: [], total: 0};
var points = this.waveform.points;
for(var i = 0; i < 256; i++) {
@Breefield
Breefield / onframe.js
Created September 14, 2012 07:31
Every frame
if(typeof hyperlips.waveform == 'undefined') return false;
ctx.strokeStyle = 'rgba(255, 255, 255, 1)';
ctx.lineWidth = 1;
ctx.lineJoin = 'round';
ctx.beginPath();
ctx.moveTo(0, canvas.height - 15);
for(var i = 0; i < hyperlips.waveform.points.length; i++) {
ctx.lineTo((canvas.width / hyperlips.waveform.points.length) * (i + 1), canvas.height - 15 + Math.ceil(hyperlips.waveform.points[i] * 10));
}
ctx.stroke();
@Breefield
Breefield / sm.html
Created September 14, 2012 07:35
Soundmanager
<script type="text/javascript" src="soundmanager/soundmanager2.js"></script>
<script type="text/javascript">
soundManager.url = 'soundmanager/swf/';
soundManager.flashVersion = 9;
soundManager.flash9Options.useWaveformData = true;
soundManager.debugMode = false;
</script>
@Breefield
Breefield / controllers.rb
Created November 21, 2012 21:13
Inherited Controllers
# In API/V1/alerts_controller.rb
module Api
module V1
class AlertsController < Api::V1::BaseController
...
end
end
end
# In API/V1/base_controller.rb
@Breefield
Breefield / dj.rb
Created March 4, 2013 22:56
Way 1
class User < ActiveRecord::Base
after_create :notify_user_created
def notify_user_created
User.delay.async_notify_user_created(self.id)
end
def self.async_notify_user_created(id)
user = User.find(id)
user.do_the_think_you_were_going_to_do