Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Hasnain Bukhari BukhariH

🎯
Focusing
Block or report user

Report or block BukhariH

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@BukhariH
BukhariH / BigDecimal_Tolerance.java
Created Aug 17, 2018
Checks if a BigDecimal is with in a tolerance value
View BigDecimal_Tolerance.java
private static boolean isWithinTolerance(BigDecimal amount, BigDecimal tolerance) {
return (amount.compareTo(tolerance.negate()) > 0 && amount.compareTo(tolerance) < 0)
|| amount.abs().compareTo(tolerance) == 0;
}
@BukhariH
BukhariH / MomentBetweenDates.js
Created Jun 6, 2018
Get dates between two moment objects
View MomentBetweenDates.js
enumerateDaysBetweenDates = (startDate, endDate) => {
const now = startDate.clone().startOf("day");
const dates = [];
while (now.isSameOrBefore(endDate.startOf("day"))) {
dates.push(now.format("YYYY-MM-DD"));
now.add(1, "days");
}
return dates;
};
@BukhariH
BukhariH / MomentBetweenDatesjs
Created Jun 6, 2018
Get dates between two moment objects
View MomentBetweenDatesjs
enumerateDaysBetweenDates = (startDate, endDate) => {
const now = startDate.clone().startOf("day");
const dates = [];
while (now.isSameOrBefore(endDate.startOf("day"))) {
dates.push(now.format("YYYY-MM-DD"));
now.add(1, "days");
}
return dates;
};
View SimpleLogger.js
const logger = (() => {
let log = "";
return {
add: msg => log += msg + "\n",
show: () => console.log(log)
}
})();
View Unique Values Only Array.js
// Turns [1,2,2,2] into [1,2]
const arr = [1,2,2,2]
[...new Set(arr)]
View keybase.md

Keybase proof

I hereby claim:

  • I am bukharih on github.
  • I am bukharih (https://keybase.io/bukharih) on keybase.
  • I have a public key whose fingerprint is 5C4D 1BD3 7DEA 43CA D54C 633C E04C F879 7C01 7AE5

To claim this, I am signing this object:

@BukhariH
BukhariH / Delete All Node Modules.sh
Created Oct 9, 2017
Delete All Node Modules via Term
View Delete All Node Modules.sh
find . -name "node_modules" -exec rm -rf '{}' +
View Merge Last Two Commits.sh
git reset --soft "HEAD^"
git commit --amend
@BukhariH
BukhariH / uniqueProperties.js
Last active Sep 6, 2017
Get unique properties from JSON object
View uniqueProperties.js
// Turn const ARRAY = [{type: "FOO", content: "Test 0"}, {type: "BAR", content: "Test 1"}, {type: "FOO", content: "Test 2"}]
// Into ["FOO", "BAR"]
// Using getUniqueProperties(ARRAY, 'type')
getUniqueProperties = (array, property)=>{
return [...new Set(array.map(elem => elem[property]))]
}
@BukhariH
BukhariH / reduceArrayToObj.js
Last active Jul 12, 2017
Turn an Array of Objects into an Object using Reduce
View reduceArrayToObj.js
// change array & property to relevant values
const reducedObj = array.reduce(function(accum, item) {
accum[item.property] = item;
return accum;
}, {})
You can’t perform that action at this time.