Skip to content

Instantly share code, notes, and snippets.

View rakeshpai's full-sized avatar

Rakesh Pai rakeshpai

View GitHub Profile
@rakeshpai
rakeshpai / bitflipper.js
Created July 9, 2016 07:55
Code to randomly turn on or off an LED. With an extremely useful HTTP API. Uses Espruino, running on an ESP8266 (ESP-03).
var wifi = require("Wifi"),
ledPin = D14,
buttonPin = D0,
ssid = "...",
password = "...";
var led = (function() {
var pulseIntervalHandle,
@rakeshpai
rakeshpai / gulpfile.js
Last active October 13, 2015 15:12
Browserify + Uglify + Espruino using Gulp
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});
@rakeshpai
rakeshpai / primes.js
Last active December 22, 2015 21:29
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 February 20, 2013 12:29
Opera .stack / .stacktrace madness
<!doctype html>
<title>Stackgen</title>
<script src="stackgen.js"></script>
<script>
try {
stackgen();
} catch(e) {
ex = e;
throw e;
@rakeshpai
rakeshpai / foo.js
Created January 19, 2013 06:26
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…
window.foo = 3;
@rakeshpai
rakeshpai / errorception-meta.html
Created November 23, 2012 11:41
Sending meta information to Errorception
<script>
_errs.meta = {
email: "[email protected]",
sessionId: 4138727492,
lovesCats: true
};
</script>
@rakeshpai
rakeshpai / gist:4134122
Created November 23, 2012 05:23
Closure compiler optimizations
// 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 June 4, 2012 10:03
Email by @Airtel_Presence
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 April 3, 2012 03:25
Trying out with contents inlined
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 January 16, 2012 20:55
Errorception populating the queue before it's ready to flush
<script>
var _errs = [];
window.onerror = function() { _errs.push(arguments); }
// <snip> Load our JS asynchronously, after page load, to process the _errs "queue"
</script>