Skip to content

Instantly share code, notes, and snippets.

View jineeshjohn's full-sized avatar

Jineesh jineeshjohn

View GitHub Profile
@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: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: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: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:6020639
Created July 17, 2013 13:40
Ant script to merge multiple files with a custom separator
<project default="theMerger" basedir=".">
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
<target name="theloop">
<foreach target="theSeparator" param="theFile">
<path id="someId">
<fileset dir="${basedir}/dd" includes="**/*.js"/>
</path>
</foreach>
</target>
@jineeshjohn
jineeshjohn / gist:5917312
Created July 3, 2013 11:57
Defer method implementation to have async functionality
Function.prototype.defer = function(t,args){
var __method = this;
var timeout = t*1000;
window.setTimeout(function() {
return __method.call(__method, args);
}, timeout);
};
function foo(args){
console.log("ss:" , args.a);
@jineeshjohn
jineeshjohn / gist:5424891
Last active December 16, 2015 11:08
A sample to test the promise pattern
/**
1) doing things in sequence
$(btn).click(function(){
getTwitterHandle(function(){
getTweets(function(){
});
});
@jineeshjohn
jineeshjohn / gist:5141841
Created March 12, 2013 10:27
Configuration to gzip apache server.
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
compression="on"
compressionMinSize="2048"
noCompressionUserAgents="gozilla, traviata"
compressableMimeType="text/html,text/xml,text/css,text/javascript,application/javascript,application/x-javascript"
/>
@jineeshjohn
jineeshjohn / gist:5098412
Created March 6, 2013 10:32
String into a javascript function call. Better way to create instance for dynamic class names
var Y = (function(){
return {
Car:function(model){
this.model = model;
this.applyBreak = function(){
alert("done break!!");
}
}
}
@jineeshjohn
jineeshjohn / gist:4482957
Created January 8, 2013 11:01
HTML5 default template
<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Sample Document</title>
<script></script>
</head>
<body>
...