Skip to content

Instantly share code, notes, and snippets.

Avatar

Rakesh Pai rakeshpai

View GitHub Profile
@rakeshpai
rakeshpai / bitflipper.js
Created Jul 9, 2016
Code to randomly turn on or off an LED. With an extremely useful HTTP API. Uses Espruino, running on an ESP8266 (ESP-03).
View bitflipper.js
var wifi = require("Wifi"),
ledPin = D14,
buttonPin = D0,
ssid = "...",
password = "...";
var led = (function() {
var pulseIntervalHandle,
@rakeshpai
rakeshpai / gulpfile.js
Last active Oct 13, 2015
Browserify + Uglify + Espruino using Gulp
View gulpfile.js
var gulp = require("gulp"),
browserify = require("browserify"),
source = require("vinyl-source-stream"),
buffer = require("vinyl-buffer"),
uglify = require("gulp-uglify"),
through = require("through2"),
port = "/dev/cu.wchusbserial410",
espruino = require("node-espruino").espruino({comPort: port});
View primes.js
var primes = [2];
var n = 3; // The number we are testing. Will be incremented.
function checkNextNumber() {
// It's sufficient to check if there are any prime factors up to sqrt(n)
n++;
var limitForChecking = Math.floor(Math.sqrt(n));
@rakeshpai
rakeshpai / index.html
Created Feb 20, 2013
Opera .stack / .stacktrace madness
View index.html
<!doctype html>
<title>Stackgen</title>
<script src="stackgen.js"></script>
<script>
try {
stackgen();
} catch(e) {
ex = e;
throw e;
@rakeshpai
rakeshpai / foo.js
Created Jan 19, 2013
Code to replicate a potential bug with Firefox when using the crossorigin attribute on script tags. When using crossorigin="anonymous", if the server doesn't set access-control headers, Firefox doesn't evaluate the external script, even though it's downloaded. Thus, alert(foo) breaks with a ReferenceError if the server doesn't send the access-co…
View foo.js
window.foo = 3;
@rakeshpai
rakeshpai / errorception-meta.html
Created Nov 23, 2012
Sending meta information to Errorception
View errorception-meta.html
<script>
_errs.meta = {
email: "email@domain.com",
sessionId: 4138727492,
lovesCats: true
};
</script>
@rakeshpai
rakeshpai / gist:4134122
Created Nov 23, 2012
Closure compiler optimizations
View gist:4134122
// Original
var getElementsByTagName = "getElementsByTagName";
var links = document[getElementsByTagName]("link"),
anchors = document[getElementsByTagName]("a"),
iframeContents = "...<script>var whatever = document." + getElementsByTagName + "('whatever');</script>...";
// becomes
@rakeshpai
rakeshpai / gist:2867569
Created Jun 4, 2012
Email by @Airtel_Presence
View gist:2867569
Dear Mr Pai,
Thank you for writing to airtel.
This is with reference to your e-mail dated 04th June 2012, wherein; you
highlighted your concern regarding website blocking for your airtel
account number 15793484.
We regret for the inconvenience caused to you.
@rakeshpai
rakeshpai / beacon.inlined.js
Created Apr 3, 2012
Trying out with contents inlined
View beacon.inlined.js
var _errs=["##EC##"];
window.onerror=function(){_errs.push(arguments)};
(function(f,n){function r(d,a){d=d.contentWindow||d.contentDocument;d.document&&(d=d.document);d.open();d.write(a);d.close()}function s(d,a){a=(""+a).replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/'/g,"&quot;");return"<input type='hidden' name='"+d+"' value='"+a+"' />"}function o(d){l&&clearTimeout(l);l=setTimeout(t,200);d._when=p;q.push(d);try{if("ot"==m){for(var a,h=d.callee,e=/function\s*([\w\-$]+)?\s*\(/i,c=[],b,k;h&&10>c.length;)b=e.test(h.toString())?RegExp.$1||"{anonymous}":"{anonymous}",
k=Array.prototype.slice.call(h.arguments||[]),c[c.length]=b+"("+i(k)+")",h=h.caller;a=c.join("\n");d._stack=a}}catch(g){}}function t(){var d=[],a,b,e,c,f=0,k,g=function(a,c){d.push(s(a+f,c))};try{for(;a=q.shift();){b=k=a.m||a[0]||a;e=a.u||a[1];c=a.l||a[2];if(!(k&&k instanceof Error)&&b&&"string"==typeof b&&e&&c&&("Error loading script"===b&&/Firefox/.test(navigator.userAgent)||/originalCreateNotification/.test(b)?f--:(g("type","onerr"),g("mes
@rakeshpai
rakeshpai / _errsAsAnApi.html
Created Jan 16, 2012
Errorception populating the queue before it's ready to flush
View _errsAsAnApi.html
<script>
var _errs = [];
window.onerror = function() { _errs.push(arguments); }
// <snip> Load our JS asynchronously, after page load, to process the _errs "queue"
</script>