Skip to content

Instantly share code, notes, and snippets.

View willhyper's full-sized avatar

Chao-Wei Chen willhyper

View GitHub Profile
@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',
# 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 / 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"):
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
import smtplib
import email.utils
from email.mime.text import MIMEText
subject = 'subject'
body = '''body
'''
sender = ('Chen,Chao-Wei', 'willhyper@gmail.com')
@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)
@willhyper
willhyper / ref.cpp
Last active May 13, 2019 21:51
pass by reference and variants
#include <iostream>
using namespace std;
void setByValue(int x) { x = 5; }
void setByReference(int &x) { x = 7; }
void setByPointer(int *x) { *x = 8; }
int main()
{
int x = 0;
@willhyper
willhyper / Program.cs
Created May 10, 2019 00:18
pythonnet 2.4.0 overloads functions with ref arguments
// say this code is compiled to test.dll
using System;
namespace Test
{
public class Class1
{
public static void SetByRef(ref Int32 x)
@willhyper
willhyper / test_unittest.py
Created November 8, 2018 20:46
pytest and unitest are not compatiable
#!/usr/bin/env python3 -m pytest -v test_unittest.py
import unittest
import pytest
xy1 = (1, 2)
xy2 = (3, 4)
@pytest.fixture(scope="class", params=[xy1, xy2])
@willhyper
willhyper / test_fixture.py
Created November 8, 2018 20:42
parameterize fixture template
#!/usr/bin/env python3 -m pytest -v test_fixture.py
import pytest
xy = [(1, 2), (3, 4)]
@pytest.mark.parametrize('x,y', xy)
def test_fixture(x, y):
print('access fixture attributes', x, y)