Skip to content

Instantly share code, notes, and snippets.

View willhyper's full-sized avatar

Chao-Wei Chen willhyper

View GitHub Profile
@willhyper
willhyper / pkg_install.py
Created May 15, 2019 21:04
package dependency install sequence
installed = set()
processing = set()
def install(x):
if x in installed:return
if x in processing: raise Exception("cyclic dependency")
processing.add(x)
dependencies = get_dependencies(x)
import smtplib
import email.utils
from email.mime.text import MIMEText
subject = 'subject'
body = '''body
'''
sender = ('Chen,Chao-Wei', 'willhyper@gmail.com')
import hashlib as hasher
from collections import deque
class Block:
def __init__(self, data: str, previous_hash: str):
self.data = data
self.previous_hash = previous_hash
@property
@willhyper
willhyper / jupyter_upload.py
Created April 19, 2020 20:56
jupyter api to upload file
import os
import base64
import json
import requests
def jupyter_upload(url="http://localhost:8889",
token="280e41422dcdef6fa2ba790279badc019bda0b42f69d53ba",
src="src/test.txt",dst="test2.txt"):
# install opencv https://docs.opencv.org/master/d3/d52/tutorial_windows_install.html#tutorial_windows_install_path
# pip install opencv-python
# https://stackoverflow.com/questions/604749/how-do-i-access-my-webcam-in-python
import cv2
cv2.namedWindow("preview")
vc = cv2.VideoCapture(0)
if vc.isOpened(): # try to get the first frame
@willhyper
willhyper / setup.py
Created May 27, 2020 04:49
python setup.py template
from setuptools import setup
setup(
name='myModuleName',
packages=[
'package.moduleA',
'package.moduleB'
],
version='0.0.0',
description='description',
@willhyper
willhyper / tile_2_x_3.py
Created July 28, 2020 04:32
tile photo 2 by 3
import sys
img_name = sys.argv[1]
import matplotlib.pyplot as plt
import numpy as np
im = plt.imread(img_name)
im23 = np.tile(im, [2,3,1])
plt.imsave("output.jpg", im23)
@willhyper
willhyper / Main.java
Last active August 24, 2020 03:55
calling clojure from java ; jshell
import clojure.java.api.Clojure;
import clojure.lang.IFn;
public class Main{
public static void main(String[] args){
IFn plus = Clojure.var("clojure.core", "+");
var ans = plus.invoke(1, 2);
System.out.println(ans);
}
@willhyper
willhyper / Library.java
Created August 24, 2020 06:40
clojure-java interop. adding off-shored jar
/*
* gradle init
* gradle jar
* cp build/libs/*.jar ../interop-clj/resources
*/
package jlib;
public class Library {
public boolean method1() {
return true;
@willhyper
willhyper / core.clj
Last active August 25, 2020 01:24
lein new app; lein run; lein uberjar; java -jar target/app-0.1.0-SNAPSHOT-standalone.jar
(ns app.core)
(defn -main
"I don't do a whole lot."
[x]
(println x "Hello, World!"))