Skip to content

Instantly share code, notes, and snippets.

View zihengCat's full-sized avatar

ziheng zihengCat

View GitHub Profile
@zihengCat
zihengCat / snakeCoin.py
Created March 3, 2018 07:14
A simple blockchain example in Python.
import hashlib as hasher
import datetime as date
class Block:
def __init__(self, index, timestamp, data, previous_hash):
self.index = index
self.timestamp = timestamp
self.data = data
self.previous_hash = previous_hash
self.hash = self.hash_block()
def hash_block(self):
@zihengCat
zihengCat / dos2unix.c
Last active September 9, 2017 01:15
Text file format convert
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[]) {
FILE *fp;
if (argc != 2 ||
(fp = fopen(argv[1], "r")) == NULL) {
perror("File opening failed");
return EXIT_FAILURE;
@zihengCat
zihengCat / get_utf8_size.c
Last active January 30, 2018 19:00
UTF-8 (ANSI C)
int get_utf8_size(const unsigned char *p_input) {
unsigned char c = *p_input; /* get UTF-8 first Byte */
/*
* 0xxxxxxx --> 1
* 10xxxxxx --> -1 (invalid)
* 110xxxxx --> 2
* 1110xxxx --> 3
* 11110xxx --> 4
* 111110xx --> 5