Skip to content

Instantly share code, notes, and snippets.

View jineeshjohn's full-sized avatar

Jineesh jineeshjohn

View GitHub Profile
@jineeshjohn
jineeshjohn / gist:6069139
Created July 24, 2013 09:17
Information Hiding and closures
//Information hiding
function User(){
var username = "Jineesh";
this.getName = function(){
return username;
}
}
var u = new User();
u.getName();
@jineeshjohn
jineeshjohn / gist:6256168
Created August 17, 2013 09:56
JavaScript LinkedList Improved
function LinkedList(){
this.head = null; // can be replaced with class or model (to have strong type)
this.tail = null;
var count = 0;
this.AddFirst = function(node){
//Save off the head node so we dont lose it
var temp = this.head;
//Point head to the new node
@jineeshjohn
jineeshjohn / gist:6267081
Created August 19, 2013 09:03
fibonacci in JavaScript with iterative approach
function fibo(n) {
var f = [];
for (var i = 0; i < n; i++ ) {
var item = (i < 2) ? i : f[i-1] + f[i-2];
f.push(item);
}
return f;
}
var fibos = fibo(5);
@jineeshjohn
jineeshjohn / gist:7887948
Created December 10, 2013 09:26
Dom object to string, helps to debug in firebug
var seen = []
JSON.stringify(components[0], function(key, val) {
if (typeof val == "object") {
if (seen.indexOf(val) >= 0)
return
seen.push(val)
}
return val
})
@jineeshjohn
jineeshjohn / gist:10725702
Last active August 29, 2015 13:59
Asynchronous way of executing array of JavaScript functions
function f1(cb){
console.log("I am f1");
cb();
}
function f2(cb){
console.log("I am f2");
cb()
}
function f3(){
console.log("I am f3");
define(function(require){
'use strict';
var React = require('react');
var store = require('./store');
var RegisterForm = require('es6!./registerForm');
var VerifyForm = require('es6!./verifyForm');
var RegisterSuccess = require('es6!./registerSuccess');
var Stepper = require('es6!./stepper');
var responseJson = [
{type: 'input', id: 'key1', styles:{display:'block', color: 'red'}, someprop:'abc', someotherprop:'bcd'},
{type: 'radio', id: 'key2', styles:{display:'inline', color: 'blue'}, someprop:'xyz', someotherprop:'z'}
]
var parseResponse = function(response) {
var result = [];
for (var i=0; i<response.length; i++) {
var resultObj = {
type: response[i].type,
@jineeshjohn
jineeshjohn / sla.js
Last active December 2, 2016 13:40
Single level of abstraction - SLA
var responseJson = [
{type: 'input', id: 'key1', styles:{display:'block', color: 'red'}, someprop:'abc', someotherprop:'bcd'},
{type: 'radio', id: 'key2', styles:{display:'inline', color: 'blue'}, someprop:'xyz', someotherprop:'z'}
]
var parseResponse = function(response) {
var result = [];
for (var i=0; i<response.length; i++) {
var resultObj = {
type: response[i].type,
// Chaining
var lyrics=[
{line:1,words:"Im a lumberjack and Im okay"},
{line:2,words:"I sleep all night and I work all day"},
{line:3,words:"Hes a lumberjack and hes okay"},
{line:4,words:"He sleeps all night and he works all day"}
];
var values = _(lyrics).chain()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.