Skip to content

Instantly share code, notes, and snippets.

View nodew's full-sized avatar
:octocat:
Focusing

Qiao Wang nodew

:octocat:
Focusing
View GitHub Profile
@nodew
nodew / merge-files.ps1
Created April 1, 2024 05:51
Merge and separate files with PowerShell scripts.
param(
[Parameter(Mandatory = $true)]
[string]$rootPath = "",
[Parameter(Mandatory = $true)]
[string]$outputFile = "",
[Parameter(Mandatory = $false)]
[string]$filter = "*"
)
using System.Text.RegularExpressions;
namespace ImageHelper.Shared;
public class ImageGrouper
{
private string _parentFolder;
private SearchOption _option;
private readonly List<string> _imageExtensions = new List<string> { ".jpg", ".jpeg", ".png", ".gif" };
@nodew
nodew / docker-run-postgresql.ps1
Last active April 10, 2022 15:22
Run PostgresSQL in docker container
docker volume create pgdata
docker run -d `
--name my_postgres `
-e POSTGRES_USER=postgres `
-e POSTGRES_PASSWORD=myPassword `
-e POSTGRES_DB=postgres `
-e PGDATA=/var/lib/postgresql/data/pgdata `
-v pgdata:/var/lib/postgresql/data/pgdata `
-p 5432:5432 `
postgres:latest
@nodew
nodew / uno xmlns
Created December 18, 2021 08:12
uno xmlns
xmlns:rxuno="using:ReactiveUI.Uno"
xmlns:android="http://uno.ui/android"
xmlns:ios="http://uno.ui/ios"
xmlns:macos="http://uno.ui/macos"
xmlns:wasm="http://uno.ui/wasm"
xmlns:not_win="http://uno.ui/not_win"
xmlns:win="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:not_android="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
@nodew
nodew / clone-d3-packages.js
Created February 11, 2020 10:03
clone all d3 packages to local dev box
const fs = require("fs");
const path = require("path");
const cp = require("child_process");
const clone = (package) => {
if (!fs.existsSync(package)) {
console.log(`Start to clone ${package}`);
cp.execSync(`git clone https://github.com/d3/${package}.git --depth=1`);
}
}
@nodew
nodew / LCS.js
Last active March 11, 2019 12:55
longest common sub series
/**
*
* @param {ArrayLike} sa - series a
* @param {ArrayLike} sb - series b
* @param {boolean} [isContinuous=false] - is sub series continuous
* @returns {Array<Array<any>>} - all longest common series
*/
function longestCommonSeries(sa, sb, isContinuous = false) {
if (sa.length === 0 || sb.length === 0) {
@nodew
nodew / heapSort.js
Created February 28, 2019 05:36
heapSort implementation in javascript
function heapify(array, index, heapSize, cmp) {
let left = 2 * index + 1;
let right = 2 * index + 2;
let largest = index;
if (left < heapSize && cmp(array[left], array[index]) > 0) {
largest = left;
}
if (right < heapSize && cmp(array[right], array[largest]) > 0) {
largest = right;
}
@nodew
nodew / bubbleSort.js
Last active February 27, 2019 05:46
bubbleSort implementation
const defaultCompare = (a, b) => a < b;
const swapArrayItem = (arr, i, j) => {
let tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
};
const bubbleSort = (arr, compare = defaultCompare) => {
let len = arr.length;
@nodew
nodew / kmp.ts
Created February 18, 2019 03:44
Knuth-Morris-Pratt string matcher in TypeScript
function KMPSearch(pattern: string, text: string): number {
if (pattern.length === 0) return 0;
const lsp = generateLSP(pattern);
let j = 0;
for (let i = 0; i < text.length; i++) {
while (j > 0 && text.charAt(i) !== pattern.charAt(j)) {
j = lsp[j - 1];
}
@nodew
nodew / deepEqual.js
Created December 29, 2018 13:44
Test if two variables in JavaScript are deep equal
const baseTypes = [
"[object Number]",
"[object String]",
"[object Undefined]",
"[object Boolean]",
"[object Symbol]",
"[object Function]"
]
function deepEqual(a, b) {
const typeOfA = Object.prototype.toString.call(a);