Skip to content

Instantly share code, notes, and snippets.

require_relative "../../../acceptance_helper.rb"
# require File.expand_path("../../../../acceptance_helper", __FILE__)
describe "api/v1/colours" do
before do
@data = {
url: "http://illustrationage.files.wordpress.com/2013/08/breaking-bad-walter-white-darth-heisenberg-pj-mcquade-9.jpg",
filename: "breaking-bad-walter-white-darth-heisenberg-pj-mcquade-9.jpg"
}
end
@phawk
phawk / remove-old-git-branches.sh
Created September 25, 2013 14:40
Removes git branches already merged into master
# Remove git branches from stuff
function rmb {
current_branch=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
if [ "$current_branch" != "master" ]; then
echo "WARNING: You are on branch $current_branch, NOT master."
fi
echo "Fetching merged branches..."
git remote prune origin
remote_branches=$(git branch -r --merged | grep -v '/master$' | grep -v "/$current_branch$")
local_branches=$(git branch --merged | grep -v 'master$' | grep -v "$current_branch$")
@phawk
phawk / cors.rb
Created April 24, 2013 09:14
Quick and dirty cors implementation for a rails controller.
before_filter :cors_preflight_check
after_filter :cors_set_access_control_headers
# For all responses in this controller, return the CORS access control headers.
def cors_set_access_control_headers
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'POST, GET, OPTIONS'
headers['Access-Control-Max-Age'] = "1728000"
end
test('should have a getFullName() method', function() {
expect(typeof this.user.getFullName).to.equal('function');
});
(function(global, moduleName, undefined) {
var Rect = function() {
// Create an HTML Element
this._el = global.document.createElement('div');
this._el.style.position = 'absolute';
// Call the constructor
this.init.apply(this, arguments);
};
var rect1 = new Rect();
rect1.color('blue'); // any CSS colour value
rect1.position(100, 200); // x, y
rect1.size(300, 150); // width, height
rect1.show(); // Shows the rectangle on screen (appends it to body)
rect1.hide(); // Detatches the rectabgle from the DOM
// I would also love a shorthand way of specifying the arguments in the
// constructor, at least the width, height and colour.
@phawk
phawk / module-loading.js
Last active February 11, 2024 22:57
Defining AMD modules / libraries as AMD, Common JS and browser globals This is a quick way of defining a JS module that will load in any of three environments and allow you to pass in dependencies.
(function (global, $, name, definition) {
// Checks what environment we are in and loads accordingly
if (typeof define === "function" && define.amd) {
// With AMD we require the module with its name rather than passing the variable directly
define(["jquery"], definition); // AMD
}
else if (typeof module !== "undefined" && module.exports) {
// CommonJS will need to require the node module for jQuery
$ = require("jquery");
module.exports = definition($); // CommonJS
var app = app || { views: {} };
app.views.MyView = Backbone.View.extend({
initialize: function() {
app.events.bind("some-event", this.render, this);
},
events: {
"click .reload": "render"
var app = app || {};
app.views = app.views || {};
app.views.MyView = Backbone.View.extend({
render: function() {
// Use a handlebars template or similar here
var html = "Some html template content here";
this.$el.html(html);
}
@phawk
phawk / events.js
Created December 9, 2012 19:46
Backbone evented object
var app = app || {};
app.events = _.extend({}, Backbone.Events);
new Backbone.View({
events: app.events
});
// Trigger events
app.events.trigger("some-module:some-event", some, params)