Skip to content

Instantly share code, notes, and snippets.

View rakeshpai's full-sized avatar

Rakesh Pai rakeshpai

View GitHub Profile
@rakeshpai
rakeshpai / gist:1094831
Created July 20, 2011 11:58
Variable shadowing in CoffeeScript, based on assignment scope
func = -> x = "some other string"
x = "some string"
func()
alert(x)
@rakeshpai
rakeshpai / errorception-tracking-script-minified.html
Created August 15, 2011 16:20
Errorception tracking snippet - extra verbosity edition
<script>var _errs=["<application id here>"];(function(a,b){if(b.location.protocol!="https:"){a.onerror=function(a,c,b)
{_errs.push({m:a,u:c,l:b});return!1};var d=function(){var a=b.createElement("script"),
c=b.getElementsByTagName("script")[0];a.src="http://errorception.com/projects/"+_errs[0]+"/beacon.js";c.parentNode.insertBefore(a,c)};
a.addEventListener?a.addEventListener("load",d,!1):a.attachEvent("onload",d)}})(window,document);</script>
@rakeshpai
rakeshpai / self-executing-anonymous-function.js
Created January 9, 2012 08:58
Self-executing anonymous function
(function() {
/* Your code here */
}())
@rakeshpai
rakeshpai / better-self-executing-anon-function.js
Created January 9, 2012 09:02
A better self-executing anonymous function
(function(window, document, undefined) {
/*
Your code here
You can reference window, document and undefined as you normally do
*/
}(window, document))
@rakeshpai
rakeshpai / better-self-exec-anon-function-compressed.js
Created January 9, 2012 09:07
Better anonymous function compressed with Closure Compiler
// Note: Line breaks added for clarity
(function(a, b, c) {
/*
Your code here
Calls to window.whatever will become a.whatever
Similarly, document.whatever will be b.whatever, and c will be undefined
*/
}(window, document))
@rakeshpai
rakeshpai / ncz-loader.html
Created January 11, 2012 14:30
A dynamic script loader by Nicholas Zakas
<script>
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "file.js";
document.body.appendChild(script);
</script>
@rakeshpai
rakeshpai / fb-loader.html
Created January 11, 2012 14:31
Facebook's JS SDK's loader script
<script>
// <snip>
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
@rakeshpai
rakeshpai / ga-loader.html
Created January 11, 2012 14:32
Google Analytics' async loader
<script type="text/javascript">
// <snip>
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
@rakeshpai
rakeshpai / errorception-loader.html
Created January 11, 2012 14:33
Errorception's async loader
<script>
// <snip>
(function (window, document) {
var loader = function () {
var script = document.createElement("script"), tag = document.getElementsByTagName("script")[0];
script.src = "http://errorception.com/projects/" + _errs[0] + "/beacon.js";
tag.parentNode.insertBefore(script, tag);
};
// Wait until window.onload before downloading any more code.
@rakeshpai
rakeshpai / twitter_anywhere_api.html
Created January 16, 2012 20:49
How Twitter's @anywhere API is made available
<script src="http://platform.twitter.com/anywhere.js?id=YOUR_API_KEY&v=1" type="text/javascript"></script>
<script>
// The twttr object is available to use immediately
twttr.anywhere(function() {
// Other code here
});
</script>