Skip to content

Instantly share code, notes, and snippets.

View hrchu's full-sized avatar
:octocat:
Have an Octotastic day!

petertc hrchu

:octocat:
Have an Octotastic day!
View GitHub Profile
@hrchu
hrchu / tx_sales_chart.py
Created August 6, 2024 07:38
pycon tw 2024 tx sales trend
import matplotlib.pyplot as plt
from statsmodels.tsa.holtwinters import ExponentialSmoothing
import numpy as np
# 1. 數據準備
# 2024年銷售數據(從第8天開始)
sales_data_2024 = [34, 66, 68, 70, 73, 75, 79, 83, 88, 92, 94, 98, 102, 109, 112, 113, 117, 118, 120, 121, 122, 123, 128, 136, 140]
sales_data_2024.extend([142, 146, 149, 154, 155, 161, 164, 167, 171, 175, 180, 183, 187, 202, 209, 214, 219, 221, 221]) # Aug 8 added
# 2023年銷售數據
@hrchu
hrchu / S3OutpostsBucket.java
Last active May 31, 2024 02:00
Example code of operating S3 on Outposts with AWS Java SDK v2. Checkout AWS offical document for using v1: https://docs.aws.amazon.com/AmazonS3/latest/userguide/S3OutpostsCreateAccessPoint.html
import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3control.S3ControlClient;
import software.amazon.awssdk.services.s3control.model.*;
import java.util.stream.Collectors;
public class S3OutpostsBucket {
public static void main(String[] args) {
// Enable debug-level logging for the AWS Java SDK v2
@hrchu
hrchu / prompt_generate_500_tokens
Created May 15, 2024 03:19
prompts to benchmark GPT token per second
generate 500 token story
@hrchu
hrchu / disable_proxy.sh
Created April 26, 2024 05:01
ubuntu HTTP proxy switch
#!/bin/bash
# Remove proxy settings for various protocols
unset http_proxy
unset https_proxy
unset ftp_proxy
unset rsync_proxy
# Remove proxy for apt (if exists)
sudo rm -f /etc/apt/apt.conf.d/99proxy
@hrchu
hrchu / 1. basic flow with auth code and access token
Last active February 21, 2024 09:27
OAuth 2.0 / OpenID Connect flow diagrams. Build it by http://www.plantuml.com/plantuml/uml/
@startuml
skinparam handwritten true
"You/Browser" -> slack.com: 1. I would like to access my files on Google Drive via your interface.
slack.com -> "You/Browser": 2. You should apply the "Authorization Code" from Google for me first.
"You/Browser" -> account.google.com: 3. I would like to permit slack.com to access my files.
account.google.com -> "You/Browser": 4. Are you sure?
"You/Browser" -> account.google.com: 5. [Y]
account.google.com -> "You/Browser": 6. Okay. Here is the "Authorization Code." Plz give it back to slack.com now.
"You/Browser" -> slack.com: 7. You can do what I asked now (with the Authorization Code which is just received from Google.)
slack.com -> account.google.com: 8. I would like to exchange the "Authorization Code" for the "Access Token."
@hrchu
hrchu / 99-network-tuning.conf
Last active December 11, 2023 23:05 — forked from kgriffs/sysctl.conf
Linux Web Server Kernel Tuning
# Configuration file for runtime kernel parameters.
# See sysctl.conf(5) for more information.
# See also http://www.nateware.com/linux-network-tuning-for-2013.html for
# an explanation about some of these parameters, and instructions for
# a few other tweaks outside this file.
# See evil packets in your logs.
net.ipv4.conf.all.log_martians = 1
@hrchu
hrchu / gist:b53e12389d2e4b0d01ddd29fe4a4d9eb
Last active November 1, 2023 06:16
play solid_oidc_client
In [2]: from solid_oidc_client import SolidOidcClient, MemStore
...: solid_oidc_client = SolidOidcClient(storage=MemStore())
...: import requests
In [4]: issuer = 'https://login.inrupt.com/'
...: redirect_url = 'http://localhost:3333/oauth/callback'
...: solid_oidc_client.register_client(issuer, [redirect_url])
In [5]: login_url = solid_oidc_client.create_login_uri('/', redirect_url)
...: print(login_url)
@hrchu
hrchu / PlayPath.java
Created October 22, 2022 14:57
Relative path handling in Java
package org.example;
import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
public class PlayPath {
@hrchu
hrchu / mhVTL_install_ubuntu.sh
Last active September 19, 2022 19:57
mhVTL install script for Ubuntu 16.04 (tested on the kernel version that less or equal 4.15.0)
#!/bin/sh
# Script to download, compile and install mhvtl
# Tested on ubuntu 16.04
# Origin: http://mhvtl-a-linux-virtual-tape-library.966029.n3.nabble.com/Easy-Install-for-Debian-Ubuntu-td4025413.html
# 03/04/13
# Added libconfig-general-perl (ensures tgt-admin can run)
# 04/04/13
# Added line to append www-data to sudoers automatically
# Added check for sudo/root
# Added copy for tgt-admin in sbin (fixes persistant config in tgt mhvtl-gui)
@hrchu
hrchu / TestGson.java
Last active September 13, 2022 13:17
Convert Json from/to object/tree/inputstream/reader/file with Gson in Java
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import java.io.ByteArrayInputStream;
import java.io.InputStreamReader;
import org.junit.jupiter.api.Test;
/**
* Convert Json from/to object/tree/inputstream/reader/file with Gson in Java
*
* ref https://www.javadoc.io/doc/com.google.code.gson/gson/2.9.0/com.google.gson/com/google/gson/Gson.html