Skip to content

Instantly share code, notes, and snippets.

View sjltaylor's full-sized avatar
🏡
wfh

Sam Taylor sjltaylor

🏡
wfh
View GitHub Profile
@sjltaylor
sjltaylor / console output
Created May 26, 2015 13:36
Returning a reference to a local object is a mistake.
> make mistake && ./mistake
c++ -Wall -Wextra -std=c++14 -O0 mistake.cpp -o mistake
mistake.cpp:8:10: warning: reference to stack memory associated with local variable 's' returned [-Wreturn-stack-address]
return s;
^
1 warning generated.
This is a mista��8
function trip (s) {
if ('tripIntervalId' in window) {
clearInterval(window.tripIntervalId);
}
var filters = ['invert(100%)', 'none']
var counter = 0;
function swap() {
@sjltaylor
sjltaylor / diff-api-sample
Created April 10, 2013 13:34
diff api sample
[
{
add: {uri: ..., ...}
},
{
modify: {uri:..., ...}
},
{
delete: {uri: ...}
},
#!/usr/bin/env ruby
#
# An example hook script to check the commit log message.
# Called by "git commit" with one argument, the name of the file
# that has the commit message. The hook should exit with non-zero
# status after issuing an appropriate message if it wants to stop the
# commit. The hook is allowed to edit the commit message file.
#
commit_msg = File.read(ARGV[0])
@sjltaylor
sjltaylor / bamboo js views
Created June 18, 2012 10:26
Views, service-location, declarative dsl
// Setup
var app
View.handlerFor = function(view){
new Handler(app, view.models)
}
View
.domEvent('form', 'click', 'submitted', function(e){ return e.clientX; })
@sjltaylor
sjltaylor / view_example.js
Created June 8, 2012 15:57 — forked from markevans/view_example.js
Example use of a view, using the class stuff
define(['view'], function(View){
return View.sub('ItemView', function(){
this.domEvent('click', 'button', 'selected')
})
})
@sjltaylor
sjltaylor / gist:1713820
Created January 31, 2012 23:34
My rspec fantasy
# Here is a normal set of specs...
describe 'some normal rspec' do
describe 'doing something with a Product and Users' do
before :each do
# setup etc
# preconditions could go here
@sjltaylor
sjltaylor / blobject_config.rb
Created September 30, 2011 17:20
Blobject for configuration
MyApplication::Config = ->(config_path) do
if Rails.env.development?
require 'rb-fsevent'
fsevent = FSEvent.new
fsevent.watch config_path do
suppress_warnings do
MyApplication::Config = Blobject.read(config_path)
end
@sjltaylor
sjltaylor / blobject_controller.rb
Created September 30, 2011 17:19
Using blobject in a controller
class MyController < ApplicationController
def params
@blobject_params ||= Blobject.new(super)
end
def create
model = find_model
@sjltaylor
sjltaylor / rspec-spies-etc.rb
Created September 28, 2011 09:54
Why I need an act method etc. in rspec spies
# new DSL:
# 'act': specifies the action under test as a block
# 'result': the return result from 'act'
describe MyClass do
subject { MyClass.new }
describe '#method' do
act { subject.method }