Skip to content

Instantly share code, notes, and snippets.

View wendeehsu's full-sized avatar
🇹🇼
Fighting 💨

wendeehsu

🇹🇼
Fighting 💨
View GitHub Profile
@wendeehsu
wendeehsu / load_images.py
Last active September 11, 2020 11:28
load image and split into arrays
from os import listdir
from numpy import asarray
from numpy import vstack
from keras.preprocessing.image import img_to_array
from keras.preprocessing.image import load_img
from numpy import savez_compressed
def load_images(path, size=(256,512)):
src_list = list()
tar_list = list()
'use strict';
const line = require('@line/bot-sdk');
const express = require('express');
const https = require('https');
const fetch = require('node-fetch');
const webHookURL = 'https://your-slack-incoming-webhook-url';
require('dotenv').config();
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/sophie
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyRequests on
ProxyPreserveHost on
<Location /callback>
@wendeehsu
wendeehsu / server.cpp
Created December 20, 2020 07:17
a simple multi-threaded server
#include <iostream> //cout
#include <string.h> //strlen
#include <string> //string
#include <sys/socket.h> //socket
#include <arpa/inet.h> //inet_addr
#include <netdb.h> //hostent
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
@wendeehsu
wendeehsu / default
Created January 26, 2021 03:28
nginx config for routing HTTPS(Certbot) to flask app
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name project.site; # managed by Certbot
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
@wendeehsu
wendeehsu / backup.py
Created February 11, 2021 06:04
dump database and upload to GCS
import os
from google.cloud import storage
from datetime import datetime
# backup database
date = datetime.now().strftime("%Y-%m-%d")
base_dir = "/var/www/sophie/"
folder_name = "backup/"
filename = date + ".sql"
from PIL import Image
import PIL
import os
foldernum = 0
dir_name = "./HOPE圖庫"
for folder in os.listdir(dir_name):
if folder[-1] != 'g':
for file in os.listdir(dir_name+"/"+folder):
if file[-1] == 'g': // only handle jpg/png files
const channelToken = 'your_messaging_api_channel_token';
// `e` is the data provided by Line
function doPost(e) {
var value = JSON.parse(e.postData.contents);
try {
var events = value.events;
if (events != null) {
for (var i in events) {
var event = events[i];
function replyMsg(userId, replyToken, userMsg) {
var msg = "";
if (userMsg == "打卡提醒") { // "Remind me to punch."
if (checkUser(userId) == -1) {
addUser(userId);
msg = "那我以後9:00和18:00會提醒你喔~"; // "I'll remind you at 9:00 and 18:00 in the future."
} else {
msg = "你已經在提醒名單中了:)"; // "You're already on the remind list."
}
} else if (userMsg == "取消提醒") { // "Stop reminding me."
var app = SpreadsheetApp.openById("your-sheet-id");
var remindSheet = app.getSheets()[0]; // Get's the fisrt table in the sheet
function checkUser(userId) {
var lastRow = remindSheet.getLastRow(); // the index of the last row
var inDB = -1;
if (lastRow > 0) {
var ids = remindSheet.getSheetValues(1,1,lastRow,1);