Skip to content

Instantly share code, notes, and snippets.

View skusunam's full-sized avatar

Srini Reddy skusunam

View GitHub Profile
@skusunam
skusunam / gist:9d3f89912335587b98fc
Created November 1, 2014 10:57
How to use Global Dependencies in AngularJS without breaking DI
var underscore = angular.module(‘underscore’, []);
underscore.factory(‘_’, function() {
return window._; //Underscore must already be loaded on the page
});
var app = angular.module(‘app’, ['underscore']);
app.controller(‘MainCtrl’, ['$scope', '_', function($scope, _) {
@skusunam
skusunam / for_loop.coffee
Created June 3, 2012 04:01
Loops and Comprehensions
#1)
for name in ["Roger", "Roderick", "Brian"]
alert "Release #{name}"
#2) if you need the current iteration index
for name, i in ["Roger the pickpocket", "Roderick the robber"]
alert "#{i} - Release #{name}"
#3) iterate on one line using the postfix form
release prisoner for prisoner in ["Roger", "Roderick", "Brian"]
if true == true
"we are ok"
if true != true then "panic"
#There is no ternary in Coffeescript
# (i > 0) ? "OK" : "Not OK"
if i > 0 then "OK" else "Not OK"
(or)
if i > 0 then "OK"
@skusunam
skusunam / arrays.coffee
Created June 3, 2012 03:03
Object literals & Array definitions & String interpolations
array1 = [1, 2, 3]
array2 = [
1
2
3
]
array3 = [1,2,3,]
@skusunam
skusunam / aliases.coffee
Created June 3, 2012 01:26
functions, aliases and existential operator
@saviour = true
# prototype
User::first = ->@record[0]
# existential operator (?)
praise if brain?
# existential operator (?) in place of || operator
velocity = southern ? 40