Skip to content

Instantly share code, notes, and snippets.

View willhyper's full-sized avatar

Chao-Wei Chen willhyper

View GitHub Profile
@willhyper
willhyper / bias.py
Created November 8, 2018 20:17
the 1 bias in std proved by simulation
'''
when using n samples to estimate population std,
we will put (n-1) in the denominator:
population_std = sqrt( sample_sum_of_err_sq / (n-1))
i.e.,
population_var * (n-1) = sample_sum_of_err_sq
@willhyper
willhyper / click_helloworld.py
Created November 8, 2018 20:14
click hello world
import click
@click.command()
@click.option('-c','--count', default=1, type=int, help="this is count as int")
@click.option('-n','--name', prompt="name please?", help="this is name as str")
def hello(name, count):
"""help message hello somebody"""
for i in range(count):
click.secho(name, fg='green', blink=True, bold=True)
@willhyper
willhyper / ss.py
Created November 8, 2018 20:11
spiral search
import sys
import numpy as np
N = int(sys.argv[1])
def SSN(N : int):
ss = SS()
ss_true = SS_ground_truth()
for i in range(N):
pos = next(ss)
pos_true = next(ss_true)
@willhyper
willhyper / key.py
Created November 8, 2018 20:07
python signal KeyboardInterrupt
import signal
def handler(sig, frame):
print(sig)
raise KeyboardInterrupt
signal.signal(signal.SIGINT, handler) # press Ctrl+C to trigger handler
import sys
if sys.platform == 'win32':
import hashlib as hasher
import datetime as date
# Define what a Snakecoin block is
class Block:
def __init__(self, index, timestamp, data, previous_hash):
self.index = index
self.timestamp = timestamp
self.data = data
self.previous_hash = previous_hash
@willhyper
willhyper / AESCipher.py
Created June 13, 2017 03:06 — forked from mguezuraga/AESCipher.py
Encrypt & Decrypt using PyCrypto AES 256From http://stackoverflow.com/a/12525165/119849
#!/usr/bin/env python
import base64
from Crypto import Random
from Crypto.Cipher import AES
BS = 16
pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS)
unpad = lambda s : s[0:-s[-1]]