Skip to content

Instantly share code, notes, and snippets.

View nordinrahman's full-sized avatar

Nordin Rahman nordinrahman

View GitHub Profile
@nordinrahman
nordinrahman / GetPermutations.cs
Created November 16, 2023 13:41
Get permutation of array, and take out only array with specified length
IEnumerable<IList<Type>> GetPermutations(IList<Type> arraySource, int takeArrayLength)
{
// Short circuit process if take array length is 0
if (takeArrayLength == 0)
{
yield return Array.Empty<Type>();
yield break;
}
var uniqueValues = new List<string>();
@nordinrahman
nordinrahman / nord-bash-cookbook.sh
Last active June 30, 2022 09:07
Nord's bash script cook book
# Copyright 2022 Nordin Rahman
# [@nordinrahman](https://twitter.com/nordinrahman)
# [@nordinrahman](https://www.facebook.com/nordinrahman)
# [@nordinrahman](https://www.linkedin.com/in/nordinrahman))
# find files with pattern "*.cs" on current directory and sub directories recursively, then emit relative path to each found file, one file per line
# Use `find` command
# `.` refers to current directory
# `-name` is options flag to denote file name pattern
# `"*.cs"` wild card patterns to match files we are looking for
@nordinrahman
nordinrahman / git-delete-merged-local-branches.sh
Created February 22, 2022 08:05
Nordin's Bash Scripting Cook Book
# git - list local branches except current branch and main/develop
# First, make sure we are on main/develop branch first
# This is to get all local branches excep current branch and main/develop without indentation
git br | grep -E "^ " | grep -Ev "^\\*" | sed s/^\ \ //g | grep -Ev "^(main|develop)$"
# delete all local branches as originally listed above
for BRANCH_NAME in $(git br | grep -E "^ " | grep -Ev "^\\*" | sed s/^\ \ //g | grep -Ev "^(main|develop)$")
do
@nordinrahman
nordinrahman / .gitconfig
Last active June 2, 2022 06:30
Git Config File template
[user]
email = YOUREMAIL@EXAMPLE.COM
name = YOURNAME
[core]
autocrlf = true
editor = \"C:/Program Files/Notepad2/Notepad2.exe\"
pager = diff-so-fancy | less --tabs=4 -RFX
[diff]
algorithm = histogram
[i18n]
@nordinrahman
nordinrahman / MongoEvalExtensions.cs
Last active July 2, 2018 01:34 — forked from jamesikanos/MongoEvalExtensions.cs
MongoClient C# Eval Implementation
public static class MongoClientExtensions
{
/// <summary>
/// Evaluates the specified javascript within a MongoDb database
/// </summary>
/// <param name="database">MongoDb Database to execute the javascript</param>
/// <param name="javascript">Javascript to execute</param>
/// <returns>A BsonValue result</returns>
public static async Task<BsonValue> EvalAsync(this IMongoDatabase database, string javascript)
{
@nordinrahman
nordinrahman / show-indexes.js
Last active July 1, 2018 15:12 — forked from ixti/show-indexes.js
Small script that extracts all non-default indexes from MongoDB
rs.slaveOk();
db.getCollectionNames().forEach(function(coll) {
db[coll].getIndexes().forEach(function(index) {
if ("_id_" !== index.name) {
print("db." + coll + ".createIndex(" + tojson(index.key) + ")");
}
});
});
@nordinrahman
nordinrahman / InstallARR.ps1
Created February 22, 2018 04:17
Powershell scripts to install ARR and UrlRequest
New-Item c:/temp/msi -ItemType Directory
Invoke-WebRequest 'http://download.microsoft.com/download/C/F/F/CFF3A0B8-99D4-41A2-AE1A-496C08BEB904/WebPlatformInstaller_amd64_en-US.msi' -OutFile c:/temp/msi/WebPlatformInstaller_amd64_en-US.msi
Start-Process 'c:/temp/msi/WebPlatformInstaller_amd64_en-US.msi' '/qn' -PassThru | Wait-Process
cd 'C:/Program Files/Microsoft/Web Platform Installer'; .\WebpiCmd.exe /Install /Products:'UrlRewrite2,ARRv3_0' /AcceptEULA /Log:c:/temp/msi/WebpiCmd.log
@nordinrahman
nordinrahman / GetGuidCompactBase64.cs
Created July 27, 2017 09:09
Get new compact and url friendly base64 representation of new guid
public string GetUniqueId()
{
return Convert.ToBase64String(Guid.NewGuid().ToByteArray())
.Replace('+', '-')
.Replace('/', '_')
.TrimEnd('=');
}
private static Action Act(Action action)
{
return () =>
{
try
{
action();
}
catch (TargetInvocationException ex)
@nordinrahman
nordinrahman / ReinitWebpack.cmd
Last active July 3, 2017 01:50
Reinit webpack
del /f /s /q node_modules > nul && rmdir /s /q node_modules && npm install && webpack --config webpack.config.vendor.js && webpack