Skip to content

Instantly share code, notes, and snippets.

@jagsbyteinception
jagsbyteinception / utility functions.js
Last active January 13, 2023 12:19
utility functions in javascript
Math.round(sclCriterias.rate * 1e2) / 1e2; //round to 2 decimal places
const data = Object.fromEntries(new FormData(event.currentTarget)) //create JSON object from form entries
function Get-SQLTable
{
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[string] $SourceSQLInstance,
[Parameter(Mandatory=$true)]
[string] $SourceDatabase,
@jagsbyteinception
jagsbyteinception / CalculateTimeDifference.cs
Last active July 23, 2021 16:00
find business hours between 2 datetime exclude option sat, sun and holidays. pass business hours
public static double CalculateTimeDifference(DateTime startDate, DateTime endDate, Boolean excludeSat, Boolean excludeSun, List<DateTime> excludeDates, string businessStartTime, string businessEndTime)
{
//find working hours in a day
var tsBusinessStartTime = TimeSpan.Parse(businessStartTime);
var tsBusinessEndTime = TimeSpan.Parse(businessEndTime);
var businessHours = (tsBusinessEndTime - tsBusinessStartTime).TotalHours;
Console.WriteLine(businessHours);
if (startDate.TimeOfDay < tsBusinessStartTime) //email received before business hr
//https://community.dynamics.com/crm/f/microsoft-dynamics-crm-forum/258887/sending-unique-email-via-web-api-crm/728165
/*
otherlinks: https://community.dynamics.com/365/f/dynamics-365-general-forum/359828/execute-sendemailfromtemplate-web-api-action-from-js
*/
//-- /api/data/v8.2/emails
//Method: POST
{
//common state for different inputs
function RegisterYourCatForm() {
const [values, setValues] = useState({
name: '', color: '', age: '', habits: ''
});
const set = name => {
return ({ target: { value } }) => {
setValues(oldValues => ({...oldValues, [name]: value }));
}
.flip-card-inner {
transition: transform 0.6s;
transform-style: preserve-3d;
}
/* Do an horizontal flip when you move the mouse over the flip box container */
.flip-card:hover .flip-card-inner {
transform: rotateY(180deg);
}
@jagsbyteinception
jagsbyteinception / node.js
Created May 21, 2020 21:21
nodejs - non promise function to promise (support await)
async function asyncGetUserInfo(req) {
return new Promise((resolve) => {
if(!req.cookies.session){
return resolve(null);
}
var data = {'sessionToken': req.cookies.session};
hubsoft.getUserInfo(data, function (err, result) {
utils.cleanupObject(result);
if (!!result && (!result.out.errors || !result.out.errors.ErrorDTO || !result.out.errors.ErrorDTO.length)) {
resolve(result.out);
@jagsbyteinception
jagsbyteinception / node.js
Created May 21, 2020 21:20
nodejs - await async in loop
res.write('start');
var files = searchRecursive(config.app.publicPath, '.scss');
//foreach is not promise-aware. so use map
//map return promises
var promises = await files.map(async(scss)=>{
var css = scss.replace('.scss','.min.css');
var map = scss.replace('.scss','.min.css.map');
var result = await sassAsyncRender(scss,css,map);
res.write(JSON.stringify({result}));
@jagsbyteinception
jagsbyteinception / node.js
Created May 21, 2020 21:18
nodejs - recursively search directory for file type or extension
var searchRecursive = function(dir, pattern) {
var results = [];
fs.readdirSync(dir).forEach(function (dirInner) {
// Obtain absolute path
dirInner = path.resolve(dir, dirInner);
var stat = fs.statSync(dirInner);
// If path is a directory, scan it and combine results
if (stat.isDirectory()) {
results = results.concat(searchRecursive(dirInner, pattern));
}