Skip to content

Instantly share code, notes, and snippets.

View varunkumar's full-sized avatar

Varunkumar Nagarajan varunkumar

View GitHub Profile
#!/bin/bash
# Script for cleaning up node_modules and other tmp files (like core)
# Usage: ./cleanup-space.sh -m +15
# This will cleanup node modules not accessed in the last 15 days
VERSION=0.1.0
# Defaults
CLEANUP_TIME=+15
@varunkumar
varunkumar / Person.js
Last active August 29, 2015 14:05
OOP Template
"use strict"; // strict mode JS
// IIFE
(function () {
const Person = (function () {
// private static
var nextId = 1;
// constructor
var person = function () {
// private members
@varunkumar
varunkumar / normal.js
Last active August 29, 2015 14:05
Strict Mode JavaScript
var lastName = '';
// some code here
// at later point
lastNam = 'Nagarajan'; // value will be assigned to window.lastNam
alert(lastName);
alert(window.lastNam);
@varunkumar
varunkumar / glass.html
Created July 4, 2014 17:32
[wearscript] WearScript - Hello,World
<html style="width:100%; height:100%; overflow:hidden">
<body style="width:100%; height:100%; overflow:hidden; margin:0">
<script>
function main() {
if (WS.scriptVersion(1)) return;
WS.displayWarpView([3.0439236881258753, -0.09811170052611454, -1351.6367347302782, 0.03321587552236447, 3.053154626691264, -40.341560801335376, -0.00010172584427831437, -5.8759263127489935e-05, 1.0]);
WS.cameraOn(.1, 360, 640);
}
window.onload = main;
</script>
@varunkumar
varunkumar / JS gsub
Created January 23, 2014 03:48
JavaScript implementaion of ruby's gsub
gsub = function(source, pattern, replacement) {
var match, result;
if (!((pattern != null) && (replacement != null))) {
return source;
}
result = '';
while (source.length > 0) {
if ((match = source.match(pattern))) {
result += source.slice(0, match.index);
result += (typeof replacement === 'function') ? replacement(match[0]) : replacement;
@varunkumar
varunkumar / cors.html
Last active December 12, 2015 02:49
Testing the behavior of window.onerror in Firefox with and without crossorigin attribute.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>CORS for static resources</title>
</head>
<body>
<img src="http://slides.varunkumar.me/static/images/may2012.jpg" crossorigin="">
<!-- www.varunkumar.me doesn't set CORS headers -->
<!--script src="http://www.varunkumar.me/static/js/calculator.js"></script>
@varunkumar
varunkumar / tweet-notifier.js
Created September 23, 2012 19:50
Arduino tweet notifier
var five = require("johnny-five"),
twitter = require('ntwitter'),
board, lcd, mentions = 0;
board = new five.Board();
board.on("ready", function() {
lcd = new five.LCD({
pins: [ 8, 9, 10, 11, 12, 13 ],
@varunkumar
varunkumar / hello-world.js
Created September 23, 2012 19:45
Johnny-Five getting started!!
var five = require("johnny-five"),
// or "./lib/johnny-five" when running from the source
board = new five.Board();
board.on("ready", function() {
// Create an Led on pin 13 and strobe it on/off
// Optionally set the speed; defaults to 100ms
(new five.Led(13)).strobe();