Skip to content

Instantly share code, notes, and snippets.

View farithadnan's full-sized avatar
:bowtie:
Exorcising

Farith farithadnan

:bowtie:
Exorcising
  • MZM Sdn. Bhd.
  • Malaysia
  • 01:54 (UTC +08:00)
View GitHub Profile
@farithadnan
farithadnan / number-to-english.js
Last active October 30, 2024 05:14
Number to English Function
function numToEng(num) {
if (num < 1 || num > 999) {
throw new Error("Number must be between 1 and 999");
}
let ones = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine"];
let teens = ["eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen"];
let tens = ["ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"];
if (num < 10) return ones[num - 1];
@farithadnan
farithadnan / pre-request.js
Created October 7, 2024 04:33
Postman Script (Pre-request)
pm.test("Check for collection's variables..", function () {
let vars = ['client_id', 'client_secret', 'grant_type'];
vars.forEach(function (item, index, array) {
console.log(item, index);
pm.expect(pm.collectionVariables.get(item), item + " variable not set").to.not.be.undefined;
pm.expect(pm.collectionVariables.get(item), item + " variable not set").to.not.be.empty;
});
if ((!pm.collectionVariables.get("access_token") && pm.collectionVariables.get("IS_TESTING"))
|| Date.now() > new Date(pm.collectionVariables.get("expires_in") * 1000)) {
@farithadnan
farithadnan / timezone_kl.cs
Created March 18, 2024 02:06
Get a current datetime for Kuala Lumpur (Malaysia)
namespace test_datetime
{
internal class Program
{
private static TimeZoneInfo Kuala_Lumpur_Standard_Time = TimeZoneInfo.FindSystemTimeZoneById("Singapore Standard Time");
static void Main(string[] args)
{
DateTime datetime_kuala_lumpur = TimeZoneInfo.ConvertTime(DateTime.UtcNow, Kuala_Lumpur_Standard_Time);
Console.WriteLine("Kuala Lumpur Now: " + datetime_kuala_lumpur);
Console.WriteLine("Kuala Lumpur + 1 Hour: " + datetime_kuala_lumpur.AddHours(1));
@farithadnan
farithadnan / emoji.css
Created December 22, 2023 01:47
Rotating and Shrinking Emoji
.rotating-emoji {
display: inline-block;
transition: transform 0.3s ease-in-out;
}
.rotating-emoji:hover {
animation: rotateAndShrink 2s ease-in-out infinite;
transform: scale(0.8);
}
@farithadnan
farithadnan / image2text.cs
Last active September 21, 2023 04:50
How to use extract text from multiple image using Tesseract OCR in C#?
/// <summary>
/// Method to extract text from an image.
/// </summary>
/// <param name="imagePaths">A path to entire images.</param>
/// <returns>Returns a list of strings.</returns>
private static List<List<string>> ExtractTextFromImage(List<string> imagePaths)
{
List<List<string>> allTexts = new();
// Initialize the Tesseract engine
@farithadnan
farithadnan / gist:cfc963678c329bd9a1342aef7c4615a3
Created January 26, 2022 08:23 — forked from chad3814/gist:2924672
deleting array items in javascript with forEach() and splice()
// This is from my comment here: http://wolfram.kriesing.de/blog/index.php/2008/javascript-remove-element-from-array/comment-page-2#comment-466561
/*
* How to delete items from an Array in JavaScript, an exhaustive guide
*/
// DON'T use the delete operator, it leaves a hole in the array:
var arr = [4, 5, 6];
delete arr[1]; // arr now: [4, undefined, 6]
@farithadnan
farithadnan / patchingAsDefault.js
Created December 7, 2021 04:28
Patching form group value into an Array
// Patch value to default
displayData: string[];
patchCreateAsDefault(mainControl: FormGroup): void {
// Check if the formgroup is valid or not first
if (mainControl.valid) {
// Get raw value of formgroup, for nested form
const formObj = mainControl.getRawValue();
@farithadnan
farithadnan / loop.js
Created October 12, 2021 06:10
Loop for formArray
// Check whether the serial length is equal with the quantity
for (const control of this.productForm.controls) {
if (control.get('serialLengthCheck').value !== control.get('quantity').value) {
console.log('Total of Serial Must be Equal with Quantity!');
}
}
@farithadnan
farithadnan / validity.js
Created October 12, 2021 05:55
validate the form validity
// Check Validation status inside FormGroup/FromArray
const invalidControls: string[] = [];
const recursiveFunc = (form: FormGroup|FormArray) => {
Object.keys(form.controls).forEach(field => {
const control = form.get(field);
if (control.invalid) { invalidControls.push(field); }
if (control instanceof FormGroup) {
recursiveFunc(control);
} else if (control instanceof FormArray) {
recursiveFunc(control);
@farithadnan
farithadnan / NoScrolling.js
Created October 12, 2021 03:29
Preventing scrolling when Input's focus is triggerred
// To prevent page scrolling whenever the input's focus is triggered
this.productNameInput.nativeElement.focus({
preventScroll: true
});
// Souces: https://newbedev.com/focus-to-input-without-scrolling