Skip to content

Instantly share code, notes, and snippets.

View shubhamjain's full-sized avatar

Shubham Jain shubhamjain

View GitHub Profile
@shubhamjain
shubhamjain / Human readable time format in Javascript.
Last active August 29, 2015 13:57
This function takes milliseconds as input and converts it into human readable form. Useful in showing time elapsed or ETA.
/**
* This function takes milliseconds as input and converts it into "D H M S ms" format.
*
* @author Shubham Jain <shubham.jain.1@gmail.com>
* @license MIT License
*/
function timeFormat( miliseconds )
{
formatArr = {
"d": 24 * 60 * 60 * 1000,
@shubhamjain
shubhamjain / SMQT.js
Created July 2, 2014 19:00
Successive Mean Quantization Transform
function addUp(a, b, c)
{
catArr = b.concat(c);
for(i = 0; i < catArr.length ; i++)
a[i] += catArr[i];
return a;
}

Sublime Text 2 – Useful Shortcuts (PC)

Loosely ordered with the commands I use most towards the top. Sublime also offer full documentation.

Editing

Ctrl+C copy current line (if no selection)
Ctrl+X cut current line (if no selection)
Ctrl+⇧+K delete line
Ctrl+↩ insert line after
@shubhamjain
shubhamjain / social.js
Created May 18, 2016 19:06
Social Share Tracking With GA
// Track Facebook Likes
var fbCallback = function() {
FB.Event.subscribe('edge.create', function(targetUrl) {
ga('send', 'social', 'facebook', 'like', targetUrl);
});
}
if( window.fbAsyncInit ) {
fbCallback();
} else {
window.fbAsyncInit = fbCallback;
@shubhamjain
shubhamjain / formula.js
Created April 12, 2019 15:13
Google Sheets custom formula to check for primality
/**
* @customfunction
*/
function ISPRIME(number) {
for (var i = 2; i <= Math.sqrt (number); i++) {
if(number % i === 0) {
return false;
}
}
@shubhamjain
shubhamjain / Binary File reader in PHP
Last active July 23, 2020 09:07
This class is a better replacement for PHP unpack(). Unlike unpack, which creates a very large associative array, this class reads data in blocks defined by a map. Additionally blocks of Dynamic size can also be used with special constants.
<?php
/**
* A simple class to read variable byte length binary data.
* This is basically is a better replacement for unpack() function
* which creates a very large associative array.
*
* @author Shubham Jain <shubham.jain.1@gmail.com>
* @example https://github.com/shubhamjain/PHP-ID3
* @license MIT License
@shubhamjain
shubhamjain / covid.md
Last active November 2, 2020 21:19
Questions about Covid
  1. Why was most of Europe relatively calm for five months and then, faced a second wave all of a sudden?
  2. How has Japan been able to minimize the impact of Covid-19 despite doing relatively nothing? Is it masks?
  3. How was Pakistan able to peak so quickly (https://prnt.sc/vb1ao0), despite taking few measures to curb the spread? Pakistan demographic is young but is comparable to that of India's.
  4. Why is second-wave so far less deadly than the first in Europe? Yes, we are testing more but the difference in mortality rate is huge.
  5. On the other hand, the second wave (https://prnt.sc/vb1bzh) in Iran is as deadly as the first. What explains it?
  6. Why did India fail so badly at curbing the virus, despite having one of the strictest lockdown? Was compliance at fault?
  7. Why, in India, the deaths so heavily skewed towards relatively younger age? <60 age-group deaths contribute 50% to overall deaths (https://twitter.com/MoHFW_INDIA/status/1300969939298263041). This is in stark contrast with somewhere like Italy
@shubhamjain
shubhamjain / centroids.json
Created April 6, 2021 12:10
JSON list of countries (ISO Abbreviations) and their respective centroids
{
"AD": [42.546245, 1.601554],
"AE": [23.424076, 53.847818],
"AF": [33.93911, 67.709953],
"AG": [17.060816, -61.796428],
"AI": [18.220554, -63.068615],
"AL": [41.153332, 20.168331],
"AM": [40.069099, 45.038189],
"AN": [12.226079, -69.060087],
"AO": [-11.202692, 17.873887],
/9j/2wCEAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDIBCQkJDAsMGA0NGDIhHCEyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMv/AABEIAGQAZAMBIgACEQEDEQH/xAGiAAABBQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgsQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29/j5+gEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoLEQACAQIEBAMEBwUEBAABAncAAQIDEQQFITEGEkFRB2FxEyIygQgUQpGhscEJIzNS8BVictEKFiQ04SXxFxgZGiYnKCkqNTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqCg4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2dri4+Tl5ufo6ery8/T19vf4+fr/2gAMAwEAAhEDEQA/APFMU4DJp22lr2jz7jdopwqS2gNzdRQDgyOqZ+pxQ6qsjqjblDEAnuM8GhbibGgVIg5poFSIMGqIvqdv8T1xrWnnHXTbb/0WK4cCu9+KS41jTD66Zbf+gCuEArHC/wAJGmJ/isAKfikAqwYgLVJRnJYq36EV0bHMyECnAUoFKBTJbDFGKdijFUK5RKUmypyhHUU0rWSNuYsaSNl955xiCOSX8Qpx+uKpKvGPSrtpKsNvd5A3
@shubhamjain
shubhamjain / IndianCities.json
Created June 30, 2014 08:30
Indian States and their Cities
{
"AP":[
"Adilabad",
"Anantapur",
"Chittoor",
"Kakinada",
"Guntur",
"Hyderabad",
"Karimnagar",
"Khammam",