Skip to content

Instantly share code, notes, and snippets.

View niharsawant's full-sized avatar

Nihar Sawant niharsawant

View GitHub Profile
@niharsawant
niharsawant / local-crawler.js
Created March 22, 2021 05:05
Local directory crawler
const walkSync = require('walk-sync');
const stringify = require('csv-stringify');
var sizeOf = require('image-size');
const fs = require('fs');
const directory = 'path/to/the/directory/you/want/to/crawl';
let dataArr = [];
let paths = walkSync(directory, { globs: ['**/*.gif'], directories: false });
@niharsawant
niharsawant / string_helper.js
Last active December 10, 2015 11:09
Collection of small but useful methods to extend capabilities of String Object.
/*
Note : This gist allows you to add useful helper methods in string object. Add following gist in your source code and by invoking methods like
isURL or isEmail, one can check for url and email respectively.
Credits : Regular expression for url and email validation has been extracted from Jörn Zaefferer's 'jquery-validation' plugin.
*/
String.prototype.isURL = function () {
return /^(https?|s?ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~
@niharsawant
niharsawant / timestamp.js
Last active July 27, 2019 09:34
Get global relative timestamp in Javascript
/*
Note : Always make sure that input given to instance of Date class is in UTC. If Date is in UTC then only
proper relative timestamp can be calculated.
By simply calling getRelativeTimestamp on any date object will convert it to relative timestamp
*/
Date.prototype.getRelativeTimestamp = function () {
var tzoffset = this.getTimezoneOffset() * 60 * 1000; // Calculate timezone offset
var currDate = new Date();
@niharsawant
niharsawant / urlify.js
Last active October 11, 2015 23:37
URL Parser using Javascript
function urlify(input) {
var regex = /(https?:\/\/[^\s]+)/g;
return input.replace(regex, function (url){
// Whitelist for last character of URL (Accept other than Letters, numbers and underscore)
var lastCharRegex = /[^\w]$/;
var lastChar = '';
// Check if URL ends with and special characters (such as , . - ! ? etc)
if(lastCharRegex.test(url)) {
@niharsawant
niharsawant / encapsulation.coffee
Created September 16, 2012 09:37
Encapsulation in Javascript and Coffeescript
class person
constructor : (@name) ->
doPrivateThings = () ->
alert('Psst ' + @name + ' is doing private things.')
#using '=' in function declaration will make it private
goToRestroom : ->
alert(@name + ' is inside restroom.')
doPrivateThings.call(this)
@niharsawant
niharsawant / stl_upload.py
Created April 25, 2012 13:55
STL Upload to Shapeways
import SOAPpy
import base64
SHAPEWAYS_SOAP_URL = "http://www.shapeways.com/modules/shapeways_api/webservice/v1/soap.php"
USERNAME = 'user'
PASSWORD = 'password'
def main():
server = SOAPpy.SOAPProxy(SHAPEWAYS_SOAP_URL)
session = server.login(USERNAME, PASSWORD)