Skip to content

Instantly share code, notes, and snippets.

View Ending2015a's full-sized avatar
🏠
Working from home

Ending Hsiao Ending2015a

🏠
Working from home
  • NTHU Elsa lab
  • NTHU
View GitHub Profile
@Ending2015a
Ending2015a / block.cpp
Last active December 25, 2023 12:13
a C/C++ example of solving a Bitcoin block #100000
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include "sha256.h"
typedef struct _block
{
unsigned int version;
@Ending2015a
Ending2015a / speak.py
Created September 16, 2018 03:41
A simple text-to-speech script to recite English vocabulary & Chinese definition using Microsoft SAPI
# you should install pypiwin32 first: pip install pypiwin32
import win32com.client
import re
import os
config = {'delimiter':'\n\n', # delimiter between each word
'group': 3,
'pattern': '([^\t]+)\t([^\n]+)\n?([\s\S]*)', # group 0 =Vocab / group 1 =Chinese Definition / group 2 =English Definition
'voice': [1, 0, 1], # the voice, used to each group
'volume': 100,
@Ending2015a
Ending2015a / speak_gtts.py
Last active October 5, 2018 04:14
A simple text-to-speech (tts) script to recite English word, Chinese definition & English definition using gTTS(google text-to-speech)
import gtts
from gtts import gTTS
import re
import os
from pydub import AudioSegment
from tqdm import tqdm, trange
import tempfile
@Ending2015a
Ending2015a / cuda10_colab.sh
Last active April 25, 2024 16:25
Install CUDA 10.0 and nvcc on Google Colaboratory
# install cuda 10.0
!apt-get update;
!wget https://developer.nvidia.com/compute/cuda/10.0/Prod/local_installers/cuda-repo-ubuntu1604-10-0-local-10.0.130-410.48_1.0-1_amd64 -O cuda-repo-ubuntu1604-10-0-local-10.0.130-410.48_1.0-1_amd64.deb
!dpkg -i cuda-repo-ubuntu1604-10-0-local-10.0.130-410.48_1.0-1_amd64.deb
!apt-key add /var/cuda-repo-10-0-local/7fa2af80.pub
!apt-get update
!apt-get -y install gcc-7 g++-7
!apt-get -y install cuda
@Ending2015a
Ending2015a / prime_factorization.py
Created April 16, 2019 02:49
one line prime factorization in python
f = lambda x, j: [j] + f(x/j,j) if x%j==0 else f(x,j+1) if j<x else []
print(*f(int(input()), 2), sep='x')
@Ending2015a
Ending2015a / tf_keyerror.py
Last active November 10, 2019 11:47
The minimal code that would cause an unexpected KeyError in TF2.0
import tensorflow as tf #tf2.0
from collections import OrderedDict
class MyNamedTuple(OrderedDict):
def __iter__(self): # iterate over values to unpack, e.g., arg1, arg2, arg3 = MyNamedTuple(...)
for v in self.values():
yield v
class MyModule(tf.Module):
def __call__(self):
@Ending2015a
Ending2015a / gather.py
Last active March 14, 2020 11:17
My gather
import numpy as np
import tensorflow as tf # 2.0
'''
input = ... # shape (batch, h*w, 19, 2)
indices = ... # shape (h*w)
tf.stack([tf.gather(x, y) for x, y in zip(tf.unstack(input, axis=1), tf.unstack(tf.reshape(indices, [-1, 1]), axis=0))], axis=1)
'''
@Ending2015a
Ending2015a / mnist.py
Last active April 22, 2020 15:18
tensorflow mnist example from https://www.tensorflow.org/overview
import tensorflow as tf
import time
import multiprocessing as mp
mnist = tf.keras.datasets.mnist
(x_train, y_train),(x_test, y_test) = mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0
model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(input_shape=(28, 28)),
#!/bin/bash
set -x
# update package info
sudo apt-get update
# download kernel
KERNEL_VERSION="4.15.1"
LINUX_KERNEL=linux-${KERNEL_VERSION}
LINUX_KERNEL_TAR=${LINUX_KERNEL}.tar.gz
#!/bin/bash
# https://ppt.cc/fgUIKx
sudo apt-get install -y git
if [ ! -f "dmesg-initcall.pl" ] ; then
wget https://raw.githubusercontent.com/tinyclub/tinydraw/master/histogram/examples/linux-boot-graph/dmesg-initcall.pl -O dmesg-initcall.pl
fi
if [ ! -f "bootgraph.pl" ] ; then