Skip to content

Instantly share code, notes, and snippets.

View vikaskanani's full-sized avatar

Vikas Patel vikaskanani

View GitHub Profile
@vikaskanani
vikaskanani / promisify.js
Last active April 29, 2024 06:12
Code to demonstrate promisify any library if they don't return promises.
var client = inbox.createConnection(config);
client.on('connect', function () {
client.openMailbox('INBOX', function (err, info) {
if (err) {
console.error('Box open error', err);
} else {
console.log('Message count in INBOX : ' + info.count);
client.listMessages(0, 1, function (err, messages) {
if (err) {
console.error('Message Listing error', err);
@vikaskanani
vikaskanani / custom-throw.cfml
Created March 7, 2024 06:08
Custom throw in cfml
<cfscript>
try {
throw(
message="MyError",
errorcode="100",
detail="Error Detail"
);
} catch (any e) {
writeOutput("Caught Exception: " & e.message & " with errror code: " & e.errorcode & " and detail: " & e.detail);
}
@vikaskanani
vikaskanani / geocode-circle-overlap.js
Created March 24, 2021 10:00
JavaScript program to check circle overlapping
const MILES2METER = 1609.34;
const METER2MILE = 0.000621371;
// JavaScript program to check circles overlapping
function circle(x1, y1, x2, y2, r1, r2) {
//let distSq = Math.sqrt(((x1 - x2) * (x1 - x2)) + ((y1 - y2) * (y1 - y2)));
let distSq = getDistanceFromLatLonInMile(x1, y1, x2, y2) * MILES2METER;
if ( r1 < r2 ) {
[r1,r2]=[r2,r1];
}
@vikaskanani
vikaskanani / area.js
Created March 22, 2021 11:18
Find area of two intersecting circles
//reference https://en.wikipedia.org/wiki/Lens_(geometry)
function findDelta (d, r, R) {
return (1 / 4) * Math.sqrt((-d + r + R) * (d - r + R) * (d + r - R) * (d + r + R) );
}
function area (d, r, R) {
const delta = findDelta(d, r, R);
const cosLeft = (Math.acos(((d * d) + (r * r) - (R * R)) / (2 * d * r)));
const cosRight = (Math.acos(((d * d) - (r * r) + (R * R)) / (2 * d * R)));
@vikaskanani
vikaskanani / arraySlice.cfm
Created February 7, 2020 11:37
arrayslice should not give error
<cfscript>
myarray = ["one","two","three","TWO","five","Two"];
res = myarray.slice(5,10);
writedump(res);
</cfscript>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
<script src="https://cdn.jsdelivr.net/lodash/4/lodash.min.js"></script>
<title>Filters</title>
<style>
@vikaskanani
vikaskanani / jobServices.cfm
Created May 28, 2019 04:25
Prepare list for photo services
<cfset contractorArray = ["Vikas", "Bharat", "Pritesh", "Ashish"] />
<cfset serviceArray = ["Lawncare", "Snow removal", "Winterization", "Occupancy Check"] />
<cfset jobArray = [
{ "jobNo": "J8235-62", "contractor": "Vikas", "services": ["Lawncare", "Snow removal"] },
{ "jobNo": "J8235-63", "contractor": "Bharat", "services": ["Snow removal", "Winterization"] },
{ "jobNo": "J8235-64", "contractor": "Bharat", "services": ["Lawncare", "Snow removal", "Winterization"] },
{ "jobNo": "J8235-65", "contractor": "Pritesh", "services": ["Winterization", "Occupancy Check"] },
{ "jobNo": "J8235-66", "contractor": "Vikas", "services": ["Snow removal"] },
@vikaskanani
vikaskanani / shiporder.xml
Created April 1, 2019 09:33
XML data file
<?xml version="1.0" encoding="UTF-8"?>
<shiporder orderid="889923"
xmlns="http://webservice.example.com/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://webservice.example.com/ https://gist.githubusercontent.com/vikaskanani/016522bc8969008e5efdf6770effc430/raw/5eec95f8eb34c538f1cfd1e543b22027e021eafa/ShipOrder.xsd">
<orderperson>John Smith</orderperson>
<shipto>
<name>Ola Nordmann</name>
<address>Langgt 23</address>
<city>4000 Stavanger</city>
@vikaskanani
vikaskanani / funRemoveLeadingZeros.sql
Last active January 31, 2019 06:39
SQL function that removes the leading zeros from string
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Vikas Patel
-- Create date: 01/31/2019
-- Description: Remove leading zeros from string
-- =============================================
CREATE FUNCTION dbo.funRemoveLeadingZeros
<cfsavecontent variable="xml_stream"><cfoutput><?xml version="1.0" encoding="UTF-8"?>
<shiporder orderid="889923"
xmlns="http://webservice.example.com/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://webservice.example.com/ https://gist.githubusercontent.com/vikaskanani/016522bc8969008e5efdf6770effc430/raw/5eec95f8eb34c538f1cfd1e543b22027e021eafa/ShipOrder.xsd">
<orderperson>John Smith</orderperson>
<shipto>
<name>Ola Nordmann</name>
<address>Langgt 23</address>
<city>4000 Stavanger</city>