Skip to content

Instantly share code, notes, and snippets.

View jackhftang's full-sized avatar

Jack Tang jackhftang

View GitHub Profile
@jackhftang
jackhftang / http_client_pool.nim
Last active May 12, 2023 17:58
Nim HttpClientPool
import asyncdispatch
import deques
import options
import httpclient
import strformat
export httpclient # for AsyncResponse
#[
Wrapping AsyncHttpClient for pooling and timeout, also see
@jackhftang
jackhftang / permutations.py
Created April 6, 2022 06:56
single yield, fast inner loop version
def permutations(lis):
N = len(lis)
i = 0
c = [*range(0, max(2,N+1))]
while True:
yield lis
i = 1
while c[i] == 0:
c[i] = i
i += 1
@jackhftang
jackhftang / answer1.md
Last active March 3, 2022 06:06
Oursky Developer Pre-Test

Question 1

Write a function that takes two arrays as input, each array contains a list of A-Z; Your program should return True if the 2nd array is a subset of 1st array, or False if not.

For example: isSubset([A,B,C,D,E], [A,E,D]) = true isSubset([A,B,C,D,E], [A,D,Z]) = false isSubset([A,D,E], [A,A,D,E]) = true

'use strict';
const SIZE = 6;
const BASE = SIZE - 1;
const HORI = 0;
const VERT = 1;
const SPACE = '.';
const TARGET = '+';
@jackhftang
jackhftang / index.php
Last active April 26, 2021 07:59
LDAP PHP Change Password Page (modified). Original can be found at https://gist.github.com/mattrude/657334
<?php
/**
* LDAP PHP Change Password Webpage
*
* Copyright (C) 2010 Matt Rude <http://mattrude.com>
* Copyright (C) 2019 Jack Tang <me@jackhftang.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
you are a zoo keeper, You wanna keep animals to be healthy (not overweight) so you apply a diet plan.
Problem:
An animal has intial weight S at the start, For every day, you can choose to lose weight (a[i]) or have food (b[i]) or , but you have to make sure every day animal doesnt exceed T (target weight)
for N days plan, how many possbile combinations can have
condition
・1 ≦ N ≦ 35
・1 ≦ Ai, Bi ≦ 1,000,000,000 (1 ≦ i ≦ N)
・(sum of A_i) < S ≦ T ≦ 1,000,000,000
sample in
2 10 20
@jackhftang
jackhftang / fletcher.nim
Created October 25, 2019 13:35
fletcher
proc fletcher16*(arr: openArray[uint8]): uint16 =
var
c1: int = 0
c2: int = 0
for d in arr:
c1 += d.int
c2 += c1
result = (((c2 mod 255) shl 8) + (c1 mod 255)).uint16
@jackhftang
jackhftang / vnc.sh
Last active September 17, 2019 16:15
bash script for vnc over ssh tunnel
#!/bin/bash
#HOST='tahufa@cube.jackhftang.com'
HOST='me@cube.jackhftang.com'
SOCK='/tmp/ssh_tunnel_vnc_cube.sock'
vncviewer='/Applications/TigerVNC Viewer 1.7.1.app/Contents/MacOS/TigerVNC Viewer'
PORT=${1:-5900}
## open socket
ssh -f -N -C -X -L 5900:127.0.0.1:$PORT -o ExitOnForwardFailure=yes -M -S $SOCK $HOST
#define FAILED(x) (!SUCCEEDED(x))
HRESULT BasicFileOpen()
{
// CoCreate the File Open Dialog object.
IFileDialog *pfd = NULL;
HRESULT hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pfd));
if (FAILED(hr)) return hr;
// Create an event handling object, and hook it up to the dialog.
@jackhftang
jackhftang / generateStringMap.php
Last active April 9, 2019 04:27
Generate a string map in goalng. [WTFPL](http://www.wtfpl.net/txt/copying/)
package util
import (
"time"
)
<?php
$className = "StringMap";
$arr = [
"Bool" => "bool",