Skip to content

Instantly share code, notes, and snippets.

View sri-rang's full-sized avatar

Sri sri-rang

View GitHub Profile
@sri-rang
sri-rang / keybase.md
Created August 4, 2017 08:01
keybase.md

Keybase proof

I hereby claim:

  • I am srirangan on github.
  • I am sri19 (https://keybase.io/sri19) on keybase.
  • I have a public key ASBA4jE2007AhvAb7If04gJsZ3sVz9HhSv6_y36GgBx1Bgo

To claim this, I am signing this object:

evina.on("some-event", function (context) {
console.log("some event happened")
});
evina.trigger("some-event", {hello: "world"});
evina.off("some-event");
<script src="evina.min.js"></script>
@sri-rang
sri-rang / gist:1519452
Created December 25, 2011 15:53
Functional Programming in JavaScript - 9
<div id="redBox1" class="redBox"></div>
<div id="redBox2" class="redBox"></div>
<div id="redBox3" class="redBox"></div>
<div id="greenBox1" class="greenBox"></div>
<div id="greenBox2" class="greenBox"></div>
<div id="greenBox3" class="greenBox"></div>
<script>
(function () {
@sri-rang
sri-rang / gist:1519451
Created December 25, 2011 15:53
Functional Programming in JavaScript - 8
const CIRCLE = "circle";
const SQUARE = "square";
const RECTANGLE = "rectangle";
var getAreaFunction = function (shape) {
return function () {
switch (shape) {
case CIRCLE:
return Math.PI * arguments[0] * arguments[0];
break;
@sri-rang
sri-rang / gist:1519450
Created December 25, 2011 15:51
Functional Programming in JavaScript - 7
const CIRCLE = "circle";
const SQUARE = "square";
const RECTANGLE = "rectangle";
var getAreaFunction = function (shape) {
return function () {
switch (shape) {
case CIRCLE:
return Math.PI * arguments[0] * arguments[0];
break;
@sri-rang
sri-rang / gist:1519449
Created December 25, 2011 15:51
Functional Programming in JavaScript - 6
var forEach = function (list, action) {
for (var i = 0; i < list.length; i++) {
action(list[i]);
}
};
var reduce = function (combine, base, list) {
forEach(list, function (item) {
base = combine(base, item);
});
@sri-rang
sri-rang / gist:1519448
Created December 25, 2011 15:50
Functional Programming in JavaScript - 5
var forEach = function (list, action) {
for (var i = 0; i < list.length; i++) {
action(list[i]);
}
};
var map = function (mappingFunction, list) {
var result = [];
forEach(list, function (item) {
result.push(mappingFunction(item));
@sri-rang
sri-rang / gist:1519447
Created December 25, 2011 15:48
Functional Programming in JavaScript - 4
var forEach = function (list, action) {
for (var i = 0; i < list.length; i++) {
action(list[i]);
}
};
var logItem = function (item) {
console.log(item);
};
@sri-rang
sri-rang / gist:1519445
Created December 25, 2011 15:48
Functional Programming in JavaScript - 3
(function (name) {
console.log(name + " functions can be auto-executed on definition")
})("Anonymous");
console.log("JavaScript provides functional scoping instead of block scoping");
(function () {
if (true) {
var x = true;
console.log("Is 'x' available inside the block? " + x);
}