Skip to content

Instantly share code, notes, and snippets.

View shamansir's full-sized avatar

Ulric Wilfred shamansir

View GitHub Profile
@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 / lisp.lang.xml
Created August 23, 2011 07:34
Special highlighting files for gEdit: common lisp, processingJS, pegJS, pegC...
<?xml version="1.0" encoding="UTF-8"?>
<!--
Author: Ma Jiehong <ma.jiehong@gmail.com>
Copyright (C) 2010 Ma Jiehong
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
@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:
@shamansir
shamansir / defers.js
Created February 22, 2012 08:05
Easy Deferrables For JavaScript
/* See also: http://cl.ly/0Q1n1P0R223E1224332M/o */
/* the main trick */
function deferrable(f) {
return function() {
return (function(f, args) {
return function() {
return f.apply(null, args);
};
})(f, arguments);
@shamansir
shamansir / scrollEffect.js
Created June 15, 2012 13:23
Scroll Effects
// http://jsfiddle.net/shaman_sir/SFHuV/7/
function offset(elm) {
var curleft = 0,
curtop = 0;
do {
curleft += elm.offsetLeft;
curtop += elm.offsetTop;
} while (elm && (elm = elm.offsetParent));
return [ curleft, curtop ];
@shamansir
shamansir / gist:3007244
Created June 27, 2012 22:21
Test If Two Rotating Rectangles Intersect (SAT, JS)
// Excerpt from: https://github.com/Animatron/player/blob/master/anm.collisions.js
function edgeTest(p1, p2, p3, r2) {
var rot = [ -(p2[1] - p1[1]),
p2[0] - p1[0] ];
var ref = (rot[0] * (p3[0] - p1[0]) +
rot[1] * (p3[1] - p1[1])) >= 0;
for (var i = 0, il = r2.length; i < il; i+=2) {
$p-base03: #002b36
$p-base02: #073642
$p-base01: #586e75
$p-base00: #657b83
$p-base0: #839496
$p-base1: #93a1a1
$p-base2: #eee8d5
$p-base3: #fdf6e3
$p-yellow: #b58900
$p-orange: #cb4b16
@shamansir
shamansir / 01-intro.md
Created August 2, 2012 06:01
Mastering True JavaScript
We couldn’t find that file to show.
@shamansir
shamansir / jasmine.teamcity_reporter.js
Created August 28, 2012 11:56
All you need to run Jasmine Tests with Phantom at TeamCity
/* source: https://github.com/larrymyers/jasmine-reporters */
/* The MIT License
Copyright (c) 2010 Larry Myers
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell