Skip to content

Instantly share code, notes, and snippets.

View hzhangxyz's full-sized avatar

Hao Zhang(张浩) hzhangxyz

View GitHub Profile
@hzhangxyz
hzhangxyz / index.html
Last active February 22, 2023 01:56
Show all image in a single folder
<div id=container />
<script>
async function getList() {
const resp = await fetch("list.txt", {cache: "no-store"})
const text = await resp.text()
const list = text.split("\n")
return list.filter(name => name.includes(".png"))
}
var container = document.getElementById("container")
var oldList = []
@hzhangxyz
hzhangxyz / main.cpp
Last active September 24, 2019 09:26
use variant like julia union
#include <iostream>
#include <random>
#include <type_traits>
#include <variant>
template <class T> struct replace_void { using type = T; };
template <> struct replace_void<void> { using type = std::monostate; };
template <class T> using replace_void_t = typename replace_void<T>::type;
template <class... Fn> struct overloaded : Fn... {
class metaA(type):
def __new__(cls, n, b, a):
#a["__add__"] = lambda x,y:4
obj = type.__new__(cls, n, b, a)
#obj.__add__ = lambda x,y:4
return obj
def __getattr__(self, name):
if name == "__add__":
return lambda x,y:4
raise AttributeError()
@hzhangxyz
hzhangxyz / currify.c
Created September 21, 2018 13:11
currify
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
typedef int (*SIN)(int);
typedef int (*DOU)(int,int);
int proto(int b){
DOU fun=(DOU)'+';
@hzhangxyz
hzhangxyz / 100.c
Created September 13, 2018 14:59
100.c
#include <stdio.h>
#include <stdlib.h>
#define C10(x) if((x)==num)printf("%s = %d\n",#x,num);
#define C9(x) C10(x##9);C10(x+9);C10(x-9);
#define C8(x) C9(x##8);C9(x+8);C9(x-8);
#define C7(x) C8(x##7);C8(x+7);C8(x-7);
#define C6(x) C7(x##6);C7(x+6);C7(x-6);
#define C5(x) C6(x##5);C6(x+5);C6(x-5);
#define C4(x) C5(x##4);C5(x+4);C5(x-4);
@hzhangxyz
hzhangxyz / custom.cfg
Created August 22, 2018 15:07
boot from iso via grub
menuentry 'ubuntu live' {
set rootuuid=709ba2df-2ded-4a27-83fe-34093fe97ce7
search --no-floppy --fs-uuid --set=root $rootuuid
set isofile='/img/ubuntu-18.04.1-desktop-amd64.iso'
loopback loop $isofile
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile
initrd (loop)/casper/initrd.lz
}
menuentry 'debian live' {
@hzhangxyz
hzhangxyz / cindy_game.py
Created March 6, 2018 06:09
cindy_game.py
import functools
import sympy
from scipy import optimize
n = 3 # n 个人
m = 3 # m 个坑
def sol(n,m):
v = sympy.symbols(" ".join([str(i) for i in range(m)]))
@hzhangxyz
hzhangxyz / main.js
Last active February 9, 2018 12:48
python和js的async
sleep = (ms)=> new Promise(resolve => setTimeout(resolve, ms))
function bsleep(millis){
var date = new Date()
var curDate = null
do {curDate = new Date()}
while(curDate-date < millis)
}
print = console.log
foo = async (i)=>{
#!/usr/bin/env python
import tensorflow as tf
from tensorflow.python import debug as tf_debug
D = 2
t = -0.001
with tf.name_scope("constant"):
function exprst{
taskkill /f /im explorer.exe
taskkill /f /im SynTPEnh.exe
& "explorer.exe"
& "C:\Program Files\Synaptics\SynTP\SynTPEnh.exe"
}
function linux_{
bash -c ("DISPLAY=:0 "+($args -join " "))
}
function linux{