Skip to content

Instantly share code, notes, and snippets.

@anandnalya
anandnalya / app_1.js
Created March 19, 2012 07:32
Building a Single Page Webapp with jQuery
$(document).ready(function() {
// convert all a/href to a#href
$("body").delegate("a", "click", function(){
var href = $(this).attr("href"); // modify the selector here to change the scope of intercpetion
// Push this URL "state" onto the history hash.
$.bbq.pushState(href,2);
// Prevent the default click behavior.
@anandnalya
anandnalya / role.css
Created November 16, 2011 06:45
Role based views using CSS
.role_admin, .role_user, .role_guest{
display:none;
}
@anandnalya
anandnalya / S4WordCount-conf.xml
Created September 5, 2011 08:36
A basic WordReceiver, SentenceReceiver application in Yahoo S4
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="wordCatcher" class="test.s4.WordReceiverPE">
<property name="dispatcher" ref="dispatcher"/>
<property name="keys">
@anandnalya
anandnalya / tournament.py
Created August 26, 2011 09:53
An algorithm to find second largest element in a list in n + log n - 2 comparisions
# Finding the second best player in a knockout tournament
defeatedListMap = {}
def fillMap(x,y):
if x in defeatedListMap:
defeatedListMap[x].add(y)
else:
defeatedListMap[x] = set([y])
@anandnalya
anandnalya / file.html
Created August 4, 2011 03:35
Embedding flash object in Facebook Apps (FBML)
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<object type="application/x-shockwave-flash" data="foo.swf" width="300" height="300">
<param name="movie" value="foo.swf">
<param name="quality" value="high">
<param name="scale" value="noscale">
<param name="salign" value="LT">
@anandnalya
anandnalya / glassfish
Created August 4, 2011 03:28
Running Glassfish as a service on CentOS
#!/bin/bash
#
# glassfish: Startup script for Glassfish Application Server.
#
# chkconfig: 3 80 05
# description: Startup script for domain1 of Glassfish Application Server.
GLASSFISH_HOME=/home/glassfish/glassfish;
export GLASSFISH_HOME
@anandnalya
anandnalya / httpd.conf
Created August 4, 2011 03:18
Minifying Javascript/css without changing file references in your source
#enable rewriting
RewriteEngine on
RewriteRule /(.*)\.js /$1-min.js
RewriteRule /(.*)\.css /$1-min.css
@anandnalya
anandnalya / humanizeTimeDifference.py
Created August 4, 2011 03:13
Humanizing the time difference ( in django )
from django import template
register = template.Library()
MOMENT = 120 # duration in seconds within which the time difference
# will be rendered as 'a moment ago'
@register.filter
def naturalTimeDifference(value):
"""
@anandnalya
anandnalya / gist:1124420
Created August 4, 2011 03:05
‘protected’ implementation in Actionscript 3 is BROKEN
public class BaseClass{
public function modifyProperty(property:String, value:Object):void{
this[property] = value;
}
}
public class SubClass extends SubClass{
protected var count:int;
}
@anandnalya
anandnalya / gist:1124413
Created August 4, 2011 03:01
My first Scheme program
(define (sumLargeSquare a b c)
(cond ((and (&lt; a b) (&lt; a c)) (+ (* b b) (* c c)))
((and (&lt; b a) (&lt; b c)) (+ (* a a) (* c c)))
(else (+ (* a a) (* b b))))
)