Skip to content

Instantly share code, notes, and snippets.

Avatar

Asim Mittal asimmittal

View GitHub Profile
@asimmittal
asimmittal / xlsToJson.js
Last active Mar 28, 2018
A gist to turn my excel template into JSON
View xlsToJson.js
var Excel = require("exceljs");
var fs = require("fs");
function churnString(valString, dataType){
let valNum = parseFloat(valString);
let percentageTypes = [
'natWageGrowth', 'natEmpGrowth', 'natTurnoverRate', 'wgJobHolders', 'wgJobSwitchers', 'wgEntrants',
'wgValue', 'wgHolders', 'wgSwitchers', 'wgEntrants','empGrowth','turnover'
];
View scrapeUsingJQuery.js
console.log("---> Running");
const curl = require("curl");
const jsdom = require("jsdom");
const url = "http://www.imdb.com/list/ls004489992/";
curl.get(url, null, (err,resp,body)=>{
if(resp.statusCode == 200){
parseData(body);
}
View injectUpdateAndDelete.js
//create a global variable that will point to the tooltip in the DOM
var tipObj = null;
//offset along x and y in px
var offset = {
x: 20,
y: 20
};
/********************************************************************
View basicGoogleMap.html
<body onload="initialize()">
<script type="text/javascript" src="https://maps.google.com/maps/api/js?sensor=false"></script>
<div id="map" style="width:900px; height: 600px;">
</div>
</body>
View googleMapWithPolygon.js
/********************************************************************
* initialize()
* setup the google map, draw the polygon on it, set event handlers
********************************************************************/
function initialize() {
//create the google map
var map = new google.maps.Map(document.getElementById("map"), {
zoom: 4,
center: new google.maps.LatLng(22.7964, 79.8456),
mapTypeId: google.maps.MapTypeId.HYBRID
View promiseChain.js
/*
* ajaxGET
* -- Custom wrapper around the Jquery GET method
* -- when the request is complete, it returns the response using
* the 'finish' callback
*/
var ajaxGET = function(url, finish){
$.get(url).done(function(data){
finish(data);
});
View basicPromise.js
var promise = new Promise(function(resolve,reject){
/*
* Do things here (synchronous or asynchronous)
* some examples:
* -- run loops
* -- perform ajax requests
* -- count sheep!
*/
View jqueryGetGoogle.js
$.get("http://google.com",function(googPageHtml){
console.log("-->",googPageHtml)
});
@asimmittal
asimmittal / sequentialLoad.js
Created Mar 8, 2017
Sequentially load JS files
View sequentialLoad.js
(function(){
//three JS files that need to be loaded one after the other
var libs = [
'https://code.jquery.com/jquery-3.1.1.min.js',
'https://cdnjs.cloudflare.com/ajax/libs/jquery-easing/1.4.1/jquery.easing.min.js',
'https://cdnjs.cloudflare.com/ajax/libs/underscore.string/3.3.4/underscore.string.js'
];
var injectLibFromStack = function(){
View phoneField_5.js
/*******************************************************
* setupPhoneFields
* Now let's rig up all the fields with the specified
* 'className' to work like phone number input fields
*******************************************************/
function setupPhoneFields(className){
var lstPhoneFields = document.getElementsByClassName(className);
for(var i=0; i < lstPhoneFields.length; i++){
var input = lstPhoneFields[i];