Skip to content

Instantly share code, notes, and snippets.

View HYChou0515's full-sized avatar
🏝️
Relax

HYChou HYChou0515

🏝️
Relax
  • tsmc
  • Taiwan
View GitHub Profile
@HYChou0515
HYChou0515 / SpringMVCWebConfig.java
Last active December 27, 2017 03:36 — forked from AWolf81/SpringMVCWebConfig.java
Spring boot configuration file (annotation-based) - configures localization
package mongodbdemo.config;
import java.util.Locale;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
@HYChou0515
HYChou0515 / uniqueSort.scala
Created March 7, 2018 03:33
unique sort using scala
//unique sort using scala
object Main extends App {
val array=Array(5,4,7,6,5,5,4,3,3,3,2,5,5,1,2)
util.Sorting.quickSort(array)
val newArray = array.foldRight(List.empty[Int]){
case (a, b) =>
if (!b.isEmpty && b(0) == a)
b
else
a :: b
@HYChou0515
HYChou0515 / simpleNeuron.m
Last active March 9, 2018 13:32
Simple Hebbian Network
% train neurons
nr_class=3;
A=im2bin(imread('A.bmp'));
B=im2bin(imread('B.bmp'));
C=im2bin(imread('C.bmp'));
trainIms=cat(3,A,B,C);
@HYChou0515
HYChou0515 / test.java
Last active March 8, 2018 03:39
Will the method change the primitive, instance
public class Main {
public static void main(String[] args) {
int[] array=new int[3];
array[0]=0;
array[1]=3;
array[2]=6;
printarray(array);
something1(array); //not change
printarray(array);
something2(array); //change
#include<stdio.h>
#include<string.h>
int* longestPrefixSufix(char* s);
int main(void) {
int N;
scanf("%d", &N);
for(int n = 0; n < N; n++){
char s[100000];
@HYChou0515
HYChou0515 / Gmail_API_for_Python.md
Last active August 22, 2021 02:01
A simple gmail API for python

Usage:

  1. Create your public key
  2. pub_key=encrypt.encrypt(pass_word)
  3. save pub_key to the file gmail.pub
  4. Replace 'sample@gmail.com' in mail.py with your own gmail address
  5. Run send_mail.py, here you have two choices:
  • $./send_mail.py then type your password
  • $ echo "your_password" | ./send_mail.py for Unix-like system.

Example:

  1. Download as zip and extract
@HYChou0515
HYChou0515 / data2qrcode.py
Last active August 25, 2019 12:44
This script effectively encodes and transforms data to QR code.
#!/usr/bin/env python
import bz2
import qrcode
"""
This program effectively encodes and transforms data to QR code.
Encoding work flow:
ascii string --to-byte-array-->--bz2-compress--> byte array (bit256 array)
--to-int--> large int --re-partition-by-45--> bit45 array --using-D--> encoded array
@HYChou0515
HYChou0515 / polling_cpu.sh
Created September 6, 2019 13:17
A simple cpu tracker
#!/bin/bash
# This script check average cpu usage and send an email if the usage is low.
# A use case is to make better usage of a sharing machine.
# This script needs send_mail.py at https://gist.github.com/HYChou0515/fc152ce932024b29092be234863928ba#file-send_mail-py
function cpu_usage()
{
top -bn2 | grep "Cpu(s)" | tail -1 | \
sed "s/.*, *\([0-9]*\)[0-9.]*%* id.*/\1/" | \
awk '{print 100 - $1}'
@HYChou0515
HYChou0515 / loan.py
Last active July 18, 2020 03:50
Calculate loan
def loan2(R, M=[55000], L=8500000, F=3000000, P=12, verbose=0):
# R is a list of rate of each year
# M is a list of month pay-back of each year
# P is period per year
R = [1.0 * r for r in R]
M = [1.0 * m for m in M]
L = L * 1.0
F = F * 1.0
P = P * 1.0
principal = L-F
@HYChou0515
HYChou0515 / linesearch.py
Last active February 13, 2021 02:12
Line search, searching for zero point of a increasing function.
# Given func() and cond(), assume there is a number A such that
# cond(func(x)) == 0 if x < A
# == 1 if x >= A
# line search will find the number A according to func() and cond().
# Starting from point=x0 with step=s0, the searching has two phases:
# 1) expanding and 2) concentrating.
#
# 1) Expanding
# In the expanding phase, if cond(func(x0)) == 0,
# then we take larger and larger steps toward positive,