Skip to content

Instantly share code, notes, and snippets.

View jackhftang's full-sized avatar

Jack Tang jackhftang

View GitHub Profile
@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",
@jackhftang
jackhftang / index.php
Last active May 25, 2024 03:24
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 <[email protected]>
*
* 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
@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
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 / 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
#!/usr/bin/env -S deno run --allow-env --allow-ffi
import { DB } from "https://deno.land/x/sqlite/mod.ts";
const schema = `
CREATE TABLE IF NOT EXISTS User (
id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT
);
CREATE TABLE IF NOT EXISTS Wallet (
# https://arxiv.org/abs/2503.16306
from collections import Counter, defaultdict
from itertools import product, repeat
from math import prod
a = [1,1,4,4,5,6]
b = [0,1,2,6,6,6]
def p(n):
# prob that P(sum_a < sum_b) > P(sum_a > sum_b) after n times
/* r2dec pseudo code output (r2 5.5.0) */
/* check-list @ 0x401000 */
#include <stdint.h>
uint64_t entry0 (void) {
int64_t var_400h;
int64_t var_3ffh;
int64_t var_3feh;
int64_t var_3fdh;
int64_t var_3fch;