Skip to content

Instantly share code, notes, and snippets.

Avatar
🤓

Robert Sköld slaskis

🤓
View GitHub Profile
View jsonapi-schema.json
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "JSON API Schema",
"description": "This is a schema for responses in the JSON API format. For more, see http://jsonapi.org",
"oneOf": [
{
"$ref": "#/definitions/success"
},
{
"$ref": "#/definitions/failure"
View queue-emitter.js
var Emitter = require('emitter');
var slice = [].slice;
module.exports = QueueEmitter;
function QueueEmitter(){
if( !(this instanceof QueueEmitter) ){
return new QueueEmitter();
}
this.queued = {};
@slaskis
slaskis / AVector.hx
Created Feb 15, 2014
A quick test with abstract types in haxe. This is really cool
View AVector.hx
abstract AVector(Array<Float>) {
public var x(get, never):Float;
public var y(get, never):Float;
public var z(get, never):Float;
public var length(get, never):Float;
public var lengthSq(get, never):Float;
public inline function new(x:Float, y:Float, z:Float=0.) this = [x, y, z];
@:op(A+B) public static inline function add(a : AVector, b : AVector) : AVector {
return new AVector(a.x+b.x,a.y+b.y,a.z+b.z);
@slaskis
slaskis / dc1.html
Last active Dec 11, 2015
Data Channel Examples
View dc1.html
<!DOCTYPE html>
<html>
<head>
<title>Data Channel Demo 1</title>
<style>
button {
font: 18px sans-serif;
padding: 8px;
}
textarea {
View datachannel.js
(function() {
var
// Configuration:
hostname = window.CHANNEL_HOST || window.location.hostname || 'localhost',
websocketServer = "ws://"+hostname+":8000/",
// For browser compatibility:
PeerConnection = window.PeerConnection
|| window.RTCPeerConnection
View websockserver.go
package main
import (
"fmt"
"net/http"
"code.google.com/p/go.net/websocket"
"strings"
"time"
)
@slaskis
slaskis / test.redis-multi.js
Created Sep 19, 2012
A test for node_redis that shows some inconsistencies.
View test.redis-multi.js
var redis = require('redis')
, client = redis.createClient()
, assert = require('assert');
// redis.debug_mode = true;
client.on("error", function (err) {
console.log("Error " + err);
});
@slaskis
slaskis / test-inheritence.js
Created Feb 8, 2012
Inherit some sweet sweet locals plz
View test-inheritence.js
var express = require('express');
function middleware(req,res,next){
// do real funky stuff here...
// add access to funky stuff in routes
req.funky = function(){return 'funky stuff'}
// add access to funky stuff in views
res.locals.funky = function(){return 'funky stuff'}
View gist:1461303
diff --git a/lib/parser.js b/lib/parser.js
index ca6fe8d..9673efe 100644
--- a/lib/parser.js
+++ b/lib/parser.js
@@ -387,7 +387,7 @@ Parser.prototype = {
if (!this.filename)
throw new Error('the "filename" option is required to extend templates');
- var path = name = this.expect('extends').val.trim()
+ var path = this.expect('extends').val.trim()
View results.json
function (doc){
var object = {'resource':'Post'};
var match = function(){
for( var k in object )
if( object[k] !== doc[k] )
return false;
return true;
};
if( doc.resource === 'Post' && match() ){
emit(doc._id, doc);