Skip to content

Instantly share code, notes, and snippets.

View jaz303's full-sized avatar

Jason Frame jaz303

  • Glasgow, Scotland, UK
  • 03:50 (UTC +01:00)
View GitHub Profile
// signal is a function that creates an object to which listeners
// can be attached. think of it like an EventEmitter with a single
// event.
var signal = require('signalkit');
function property(value) {
var sig = signal();
var prop = function(newValue) {
if (arguments.length === 0) {
return value;
@jaz303
jaz303 / gist:8364929
Last active January 2, 2016 21:39
Jester partial-application syntax
# Jester Partial Application Syntax
doubles = map .{ s | s * 2 }, [1,2,3]
# => [2,4,6]
# ? in arg list indicates a partial application
# in future might allow a trailing "splat" (e.g. `*?`) to indicate all remaining args have been omitted
# I don't think this precludes using ? as a ternary operator in the future either. Bonus.
doubler = map .{ s | s * 2 }, ?
doubler [1,2,3]

Platforms

Raspberry Pi (Linux)

Huge community support. You'll get Linux working on this no problem, lots of disk images available on the web. If you're looking to integrate with hardware over GPIO, I2C, SPI, RPi is a bit limited out-of-the-box - you'll need to add something like a Gertboard to get access to a bunch of pins.

BeagleBone Black (Linux)

Strong community, but not as strong as RPi. Linux images available. Lots of pins available on the board itself with all standard microcontroller peripherals available (ADC, PWM, GPIO, I2C, SPI). Not sure how well these are all exposed to the operating system, or even what mechanisms are used to access them.

class Foo < ActiveRecord::Base
has_many :foo_bars
has_many :bars, :through => :foo_bars
end
class Bar < ActiveRecord::Base
end
class FooBar < ActiveRecord::Base
belongs_to :foo
@jaz303
jaz303 / gist:7770143
Created December 3, 2013 14:35
iOS auth
#import "MyAppViewController.h"
#import "MyApp.h"
#import "LoginController.h"
@implementation MyAppViewController
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
@jaz303
jaz303 / find_dirty_gits
Created October 21, 2013 19:02
find all dirty git repos under the current working directory
#!/bin/bash
for dir in $(find . -name '.git' -type d)
do
dir=$(dirname $dir)
cd $dir
STATE=""
if [[ -n $(git ls-files --other --exclude-standard 2> /dev/null) ]]; then
@jaz303
jaz303 / gist:6795620
Created October 2, 2013 15:32
Auto-generate retina @2x image selectors from input stylesheet
require 'fastimage'
task :retina do
src = File.read('main.css')
offset = 0
while (ix = src.index("url(", offset)) do
url = src[(ix+4)..(src.index(')', ix)-1)].gsub(/["']/,'')
-- Print anything - including nested tables
function table_print (tt, indent, done)
done = done or {}
indent = indent or 0
if type(tt) == "table" then
for key, value in pairs (tt) do
io.write(string.rep (" ", indent)) -- indent it
if type (value) == "table" and not done [value] then
done [value] = true
io.write(string.format("[%s] => table\n", tostring (key)));
//
// Pattern 1
// Single message handler function
// Pros: task can implement message handling however it likes
// Cons: makes it harder to reason about what messages an object understands
// A possible default implementation
object.send = function(message) {
if (typeof this[message.type] === 'function') {
@jaz303
jaz303 / gist:6351216
Last active December 21, 2015 18:59
simple bfs
for cell in map do
cell.visited = false
end
biome_search_type = 'lake'
contiguous_cells = []
queue = [start_cell]
start_cell.visited = true