Skip to content

Instantly share code, notes, and snippets.

View nabeghe's full-sized avatar
🫠

Hadi Akbarzadeh nabeghe

🫠
View GitHub Profile
@nabeghe
nabeghe / nabegheParseIniString.js
Last active February 27, 2024 23:03
Parse Ini String in JavaScript
function nabegheParseIniString(iniString, processSections = true, scannerMode = 'raw', pairSeparator = '=') {
if (typeof iniString === 'string') {
iniString = iniString.trim().split(/\r?\n/).filter(line => line.trim());
}
const result = {};
let category = null;
iniString.forEach(line => {
line = line.trim();
@nabeghe
nabeghe / rndInt.vba
Last active December 6, 2022 13:44
VBA - Random Int
Function RndInt(Min, Max)
RndInt = Int((Max - Min) * Rnd + Min)
End Function
@nabeghe
nabeghe / arrayLength.vba
Created December 6, 2022 13:43
VBA - Array Length
UBound(arr) - LBound(arr) + 1
@nabeghe
nabeghe / randomArrayValue.vba
Created December 6, 2022 13:42
VBA - Random Array Value
Dim Arr() As Variant
Arr = Array(1, 2, 3, 4, 5)
Dim Length As Integer
Length = UBound(Arr) - LBound(Arr) + 1
MsgBox (Arr(Int((Length - 1) * Rnd)))
@nabeghe
nabeghe / vbaDictionary.vba
Last active December 6, 2022 13:41
VBA - Scripting.Dictionary
' go to Tools->References and tick the box for 'Microsoft Scripting Runtime'
Set dict = CreateObject("Scripting.Dictionary")
' OR Dim dict As New Scripting.Dictionary
' Check Exists Then Add
If Not dict.Exists(key) Then
dict.Add key, value
End If
@nabeghe
nabeghe / vbaHashTable.vba
Last active December 6, 2022 13:41
VBA - HashTable (System.Collections.HashTable)
Dim HashTable As Object
Set HashTable = CreateObject("System.Collections.HashTable")
HashTable.Add "Key1", 1
HashTable.Add "Key2", 2
HashTable.Add "Key3", 3
HashTable.Add "Key4", 5
HashTable.Add "Key5", 6
' Read:
MsgBox (HashTable("Key15"))
@nabeghe
nabeghe / vbaCollection.vba
Last active December 6, 2022 13:42
VBA - Collection
Dim collection1 As Collection
Set collection1 = New Collection
collection1.Add "Value1", "Key1"
collection1.Add "Value2", "Key2"
collection1.Add "Value3", "Key3"
' Read:
Range("A1").Value = collection1.Item("Key2")
@nabeghe
nabeghe / lengthOfLastWord.js
Created December 3, 2022 14:16
JavaScript - Length of Last Word by Using the trim and split methods
/**
* @param {string} s
* @return {number}
*/
var lengthOfLastWord = function(s) {
const words = s.trim().split(' ')
return words[words.length - 1].length
};
@nabeghe
nabeghe / longestCommonPrefix.js
Created December 2, 2022 14:28
JavaScript - Find the longest common prefix string amongst an array of strings
/**
* @param {string[]} strs
* @return {string}
*/
var longestCommonPrefix = function(strs) {
let target = 0
let targetLength = 0
for (let i = 0; i < strs.length; i++) {
if (strs[i].length === 0) return ""
if (strs[i].length < targetLength || target === 0) target = i
@nabeghe
nabeghe / isPalindrome.js
Created December 2, 2022 14:03
JavaScript Check Palindrome Number
/**
* @param {number} x
* @return {boolean}
*/
var isPalindrome = function(x) {
const x1 = x.toString()
const x2 = [...x1].reverse().join('')
return x1 === x2
};