Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View erickhun's full-sized avatar
❤️

Eric Khun erickhun

❤️
View GitHub Profile
@erickhun
erickhun / line-chats-count-per-month.py
Created August 13, 2021 09:42
Line messenger chat: Count number of message per month
import re
textfile = open("./line-chat.txt", 'r')
reg_date = re.compile("\w{3}\.,\s\d{1,2}\/(\d{1,2}\/\d{4})")
reg_hour = re.compile("\d{2}:\d{2}\t")
mapSenders = {}
for line in textfile:
matches_date = reg_date.findall(line)
@erickhun
erickhun / taiwan-gold-card-status-check.sh
Created June 18, 2021 07:51
Get notified when your Taiwan Gold Card Application status changes
#!/bin/bash
LAST_DUMP_FILE=./last_dump
DATE=`date +%Y-%m-%d_%H-%M`
FILENAME="dump_"${DATE}
EMAIL='xxx@gmail.com'
function check_status () {
## Each curl is specific to a given user. You can get the proper curl via the Chrome dev tool in network tabs -> copy -> copy curl
@erickhun
erickhun / youbikes-count.sh
Last active September 30, 2020 12:28
Number of YouBike in Taipei, Taiwan
# As for 30th september 2020, the city open API gives us:
# Number of YouBike docks in Taipei (does not reflect the number of YouBikes)
curl -sS 'https://ptx.transportdata.tw/MOTC/v2/Bike/Station/Taipei?$format=JSON' | jq -r '[.[].BikesCapacity] | add '
# 16192 docks
# Number of YouBike Stations in Taipei
$ curl -sS 'https://ptx.transportdata.tw/MOTC/v2/Bike/Station/Taipei?$format=JSON' | jq -r ' . | length '
# 399 stations
@erickhun
erickhun / geth-restart.sh
Created March 11, 2018 09:45
Kill geth when it is stuck
# This bash script check if your geth is stuck in the same block number every X seconds
FIRST_TIME=true
NB_SECONDS_CHECK=300 #5 minutes
while true
do
JSON_RPC=$(curl -H "Content-Type: application/json" -X POST --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":83}' http://0.0.0.0:8080)
NEW_BLOCK_NB=$(echo $JSON_RPC | python -c 'import json,sys;obj=json.load(sys.stdin);print int(obj["result"], 0)')
@erickhun
erickhun / read_elasticmq_queues.py
Last active February 21, 2018 12:46
List all your sqs/elastimq queues
import boto3
elasticmq_host = 'http://0.0.0.0:9324'
ressource = boto3.resource('sqs',
endpoint_url=elasticmq_host,
region_name='elasticmq',
aws_secret_access_key='x',
aws_access_key_id='x',
use_ssl=False)
client = ressource.meta.client
@erickhun
erickhun / tickets.sh
Last active September 30, 2020 12:31
Check Taipei Universiade Tickets
#!/bin/bash
# Usage : This will check against `page_url` every 180 seconds, put it in a screen or tmux session :
# $ while true; do sh ticket.sh; sleep 180; done
#
page_url='https://tickets.2017.taipei/ticket/area/17_TPE_18/2952'
email='xxx@gmail.com'
#Let's check the length return of the event page
import urllib
import urllib2
import json
import time
import hmac,hashlib
def createTimeStamp(datestr, format="%Y-%m-%d %H:%M:%S"):
return time.mktime(time.strptime(datestr, format))
class poloniex:
@erickhun
erickhun / gist:4e7a362b94bf5394531b
Created November 19, 2014 08:55
Go Tour Excercice : Picture with Slices
package main
import "code.google.com/p/go-tour/pic"
func Pic(dx, dy int) [][]uint8 {
picture := make([][]uint8, dy)
for y := range picture {
picture[y] = make([]uint8, dx) // Allocate 2nd slice dimensions
for x := range picture[y] {
@erickhun
erickhun / gist:25539167b081f206d363
Last active August 29, 2015 14:09
Go Tour Excercice : WordCount with map
package main
import (
"code.google.com/p/go-tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
map_result := make(map[string]int)
splitted := strings.Fields(s)