Skip to content

Instantly share code, notes, and snippets.

Jack Tang jackhftang

Block or report user

Report or block jackhftang

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View 17 media intervew.md

17 Media interview

question 1

In this problem we consider binary trees, represented by pointer data structures.

A binary tree is either an empty tree or a node (called the root) consisting of a single integer value and two further binary trees, called the left subtree and the right subtree. For example, the figure below shows a binary tree consisting of six nodes. Its root contains the value 5, and the roots of its left and right subtrees have the values 3 and 10, respectively. The right subtree of the node containing the value 10, as well as the left and right subtrees of the nodes containing the values 1, 20 and 21, are empty trees.

A binary tree can be given using a pointer data structure. Assume that the following declarations ar

View fletcher.nim
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 / index.php
Last active Sep 26, 2019
LDAP PHP Change Password Page (modified). Original can be found at https://gist.github.com/mattrude/657334
View index.php
<?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
View generateStringMap.php
package util
import (
"time"
)
<?php
$className = "StringMap";
$arr = [
"Bool" => "bool",
View Problem.txt
There is a colony of 8 cells arranged in a straight line where each day every cell competes with its adjacent cells(neighbour). Each day, for each cell, if its neighbours are both active or both inactive, the cell becomes inactive the next day,. otherwise itbecomes active the next day.
Assumptions: The two cells on the ends have single adjacent cell, so the other adjacent cell can be assumsed to be always inactive. Even after updating the cell state. consider its pervious state for updating the state of other cells. Update the cell informationof allcells simultaneously.
Write a fuction cellCompete which takes takes one 8 element array of integers cells representing the current state of 8 cells and one integer days representing te number of days to simulate. An integer value of 1 represents an active cell and value of 0 represents an inactive cell.
@jackhftang
jackhftang / tweetnacl.c
Last active Feb 8, 2019
A memory-reduced version of scalarmult(), marginally be able to run on arduino uno (2K bytes memroy). Original [tweetnacl](https://tweetnacl.cr.yp.to/20140427/tweetnacl.c)
View tweetnacl.c
#define FOR(i, n) for (i = 0;i < n;++i)
#define sv static void
typedef unsigned char u8;
typedef unsigned long u32;
typedef unsigned long long u64;
typedef long long i64;
typedef i64 gf[16]; // 1024-bit = 128 bytes
static const gf _121665 = {0xDB41, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
@jackhftang
jackhftang / lamport_timestamp.js
Last active Jan 20, 2019
Verification on causuality provided by Lamport timestamp
View lamport_timestamp.js
const cluster = require('cluster')
const N = 8
if(cluster.isMaster){
let workers = {}
let globals = []
for(let i=0; i<N; i++) workers[i] = cluster.fork({id: i});
cluster.on('message', (worker, {message, timestamp, to}) => {
globals.push({timestamp, message})
globals.sort(function(x,y){
View heartbeat.js
const cluster = require('cluster');
const minions = ['alpha', 'beta'];
const tHeartBeat = 1000
const tCheck = 1000
const tTimeout = 3000
if (cluster.isMaster) {
for (let id of minions) cluster.fork({id});
let lastHeartbeat = {}
View keybase.md

Keybase proof

I hereby claim:

  • I am jackhftang on github.
  • I am jackhftang (https://keybase.io/jackhftang) on keybase.
  • I have a public key whose fingerprint is 8C74 60F5 FC28 D7A2 89CA 10E0 02FE BC30 FFA2 E954

To claim this, I am signing this object:

@jackhftang
jackhftang / register.php
Last active Feb 16, 2019
The infamous php if hell refactoring
View register.php
<?php
function register()
{
if (empty($_POST)) {
return register_form();
}
if (($msg = validate($_POST)) !== null) {
$_SESSION['msg'] = $msg;
You can’t perform that action at this time.