Skip to content

Instantly share code, notes, and snippets.

View shamansir's full-sized avatar

Ulric Wilfred shamansir

View GitHub Profile
@shamansir
shamansir / CS_GUIDE.md
Last active August 29, 2015 14:02
JS Player Code Style Guide
@shamansir
shamansir / arithmetics-parser.pegjs-0-6-2.js
Created September 6, 2014 22:39
Comparison between parser generated with `pegjs` and parser generated with `pegjs-fn` – 2
module.exports = (function(){
/* Generated by PEG.js 0.6.2 (http://pegjs.majda.cz/). */
var result = {
/*
* Parses the input with a generated parser. If the parsing is successfull,
* returns a value explicitly or implicitly specified by the grammar from
* which the parser was generated (see |PEG.buildParser|). If the parsing is
* unsuccessful, throws |PEG.parser.SyntaxError| describing the error.
*/
@shamansir
shamansir / _toolkit.js
Last active August 29, 2015 14:14
RPD Toolkit example
Rpd.channeltype('pd/t-num', {
show: function(t_num) { return t_num ? t_num.value : '?'; }
});
Rpd.channeltype('pd/spinner', {
adapt: function(val) {
return { value: val, time: Date.now() };
}
});
@shamansir
shamansir / spread.js
Last active August 29, 2015 14:15
Spread-Repeat
function numIter(max) {
return function(signal) {
if (signal) {
var value = 0;
return signal.takeWhile(function() { return value < max; })
.map(function() { console.log('iter('+max+')', value); return value++; })
} else {
return Kefir.fromBinder(function(emitter) {
var value = 0;
@shamansir
shamansir / _.md
Last active August 29, 2015 14:18
Tributary inlet
// allows to check if the spy was called with specified arguments in exact order,
// like:
// ```
// var spy = createSpy('foo');
// spy('a', { prop: 'foo' });
// spy('b', { prop: 'bar' });
// spy('c', { prop: 'baz' });
// spy('d', { prop: 'fuz' });
// expect(spy).toHaveBeenCalledInOrder() {[
@shamansir
shamansir / rrect.js
Last active August 29, 2015 14:28
SVG generate partially rounded rectangle path
// based on http://bl.ocks.org/mbostock/3468167
function roundedRect(x, y, width, height, rtl, rtr, rbr, rbl) {
return "M" + x + "," + y
+ (rtl ? ("v" + rtl
+ "a" + rtl + "," + rtl + " 0 0 1 " + rtl + "," + -rtl) : "")
+ "h" + (width - (rtl ? rtl : 0) - (rtr ? rtr : 0))
+ (rtr ? ("a" + rtr + "," + rtr + " 0 0 1 " + rtr + "," + rtr) : "")
+ "v" + (height - (rtr ? rtr : 0) - (rbr ? rbr : 0))
+ (rbr ? ("a" + rbr + "," + rbr + " 0 0 1 " + -rbr + "," + rbr) : "")
@shamansir
shamansir / three-snippets-example.js
Created July 31, 2011 19:10
Three tiny snippets that [may be] make JS simple: each, assert, class (+ tests for them)
var Base = class_({
_init: function(a, b) {
this.a = a;
this.b = b;
},
someMethod: function(a) {
this.a = a;
},
@shamansir
shamansir / jquery.java
Created October 19, 2011 19:31
How to implement JQuery-like class in Java
// How to make JQuery-like function in Java
// shamansir.github.com (c)
public interface ProvidesElements {
public Elements[] get();
}
public class JQ implements ProvidesElements {
@shamansir
shamansir / gist:1365475
Created November 14, 2011 22:51
SVG Paths parser
// === PATHS ===================================================================
// M<X> <Y> - move to
// L<X> <Y> - line to
// C<X1> <Y1> <X2> <Y2> <X3> <Y3> - curve to
// Z - close path
// lowercase marker means relative coord
// Example: "M0 10 L20 20 C10 20 15 30 10 9 Z"
// all commands: