Skip to content

Instantly share code, notes, and snippets.

@sweemeng
sweemeng / hazewaze_worker.py
Last active March 30, 2019 09:30
Generation CSV file from data for hazewatch KL
import requests
import csv
import dateparser
api_key="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InN3ZWVtZW5nIiwicmVhZF93cml0ZSI6ZmFsc2UsImlhdCI6MTU1MzIxMzkxMn0.PRofXuak0Do6hmn6rdulxmeIIZBV9P0GJbdTPe0IvZU"
dev_url="https://api.favoriot.com/v1/devices"
one_dev_url="https://api.favoriot.com/v1/devices/{dev_id}"
data_url_tmpl="https://api.favoriot.com/v1/devices/{dev_id}/streams"
{"ssid":"eatme", "password":"blergh", "apikey":"WhatKey?Monkey!", "device_id":"SniffSniff"}
@sweemeng
sweemeng / m5stack_network_test.py
Last active March 22, 2019 14:02
just a test for networking
from m5stack import *
from m5ui import *
import urequests
import network
lcd.clear()
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect("blergh", "blergh")
while not wlan.isconnected():
@sweemeng
sweemeng / mstack_hpmhack.py
Last active March 17, 2019 11:18
Just some micropython code to talk to a HPM sensor. Just work in progress
from m5stack import *
from m5ui import *
from machine import UART
import time
import struct
# This is the only UART that works.
uart2 = UART(1, tx=17, rx=16)
uart2.init(9600)
while True:
@sweemeng
sweemeng / food_price_parser.py
Created December 30, 2018 03:46
This is a code to process various food price dataset on data.gov.my
import pandas
def processor(file_name):
df = pandas.read_excel(file_name, skiprows=1)
# drop bad column
columns = df.columns
for column in columns:
if "Unnamed" in column:
df = df.drop(column, axis=1)
@sweemeng
sweemeng / imdb_model.py
Created September 24, 2018 13:35
just an implementation of neural network model for imdb from Deep Learning With Python book
from keras import models
from keras import layers
def model(training_data, training_label, epochs=20):
model = models.Sequential()
model.add(layers.Dense(16, activation='relu', input_shape=(10000,)))
model.add(layers.Dense(16, activation='relu'))
model.add(layers.Dense(1, activation='sigmoid'))
model.compile(optimizer='rmsprop', loss='binary_crossentropy', metrics=['accuracy'])
model.fit(x_train, y_train, epochs=epochs, batch_size=512)
import pandas as pd
import os
def main():
df = pd.read_csv("./bptms_Employed_persons_by_educational_attainment_state-1.csv")
if not os.path.exists("image_dir"):
os.makedirs("image_dir")
for s in df["State/Country"].unique():
@sweemeng
sweemeng / klang_tanjungmalim.csv
Created June 11, 2018 04:00
KTM Komuter schedule from Pelabuhan Klang to Tanjung Malim as of June 2018
We can make this file beautiful and searchable if this error is corrected: It looks like row 5 should actually have 55 columns, instead of 44. in line 4.
PELABUHAN KLANG - TANJUNG MALIM,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
NO.TREN / TRAIN NUMBER,2104,2106,2340,2304,2306,2108,2308,2110,2112,2342,2114,2310,2116,2118,2312,2120,2344,2122,2124,2314,2126,2346,2128,2130,2316,2132,2348,2134,2318,2320,2136,2138,2350,2140,2322,2142,2144,2324,2146,2148,2150,2352,2152,2154,2156,2158,2160,2354,2326,2162,2328,2164,2166,2330
PEL. KLANG,05:10,05:43,05:50,,,06:13,,06:40,07:10,,07:40,,08:15,08:40,,09:17,,09:40,10:32,,11:05,,11:40,12:23,,13:05,,13:40,,,14:35,15:05,,15:40,,16:05,16:13,,16:40,16:55,17:10,,17:43,18:02,18:15,18:45,19:25,,,20:05,,20:47,21:25,
JALAN KASTAM,05:17,05:50,05:57,,,06:20,,06:47,07:17,,07:47,,08:22,08:47,,09:24,,09:47,10:39,,11:12,,11:47,12:30,,13:12,,13:47,,,14:42,15:12,,15:47,,16:12,16:20,,16:47,17:02,17:17,,17:50,18:09,18:22,18:52,19:32,,,20:12,,20:54,21:32,
KG RAJA UDA,05:20,05:53,06:00,,,06:23,,06:50,07:20,,07:50,,08:25,08:50,,09:27,,09:50,10:42,,11:15,,11:50,12:33,,13:15,,13:50,,,14:45,15:15,,15:50,,16:15,16:23,,16:50,17:05,17:20,,17:5
@sweemeng
sweemeng / tanjungmalim_klang.csv
Created June 11, 2018 03:59
KTM Komuter schedule from Tanjung Malim to Pelabuhan Klang as of June 2018
We can make this file beautiful and searchable if this error is corrected: It looks like row 7 should actually have 56 columns, instead of 10. in line 6.
TANJUNG MALIM - PELABUHAN KLANG,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
NO.TREN / TRAIN NUMBER,2341,2103,2105,2309,2107,2109,2311,2111,2113,2313,2115,2315,2343,2117,23172119,2121,2123,2321,2345,2125,2127,2323,2129,2347,2325,2131,2133,2327,2135,2349,2137,2139,2329,2141,2351,2143,2331,2145,2147,2149,2353,2151,2333,2153,2155,2335,2157,2355,2159,2337,2161,2339,2163,2165,
TANJUNG MALIM,,,05:15,05:30,,05:50,,,06:05,06:25,,07:20,,,08:38,,,,10:15,,,,11:52,,,12:40,,,13:55,,,,,15:40,,,,16:45,,,,,,19:00,,,20:00,,,,21:00,,22:00,,
KUALA KUBU BARU,,,05:31,05:46,,06:06,,,06:21,06:41,,07:36,,,08:54,,,,10:31,,,,12:11,,,12:56,,,14:11,,,,,15:56,,,,17:01,,,,,,19:16,,,20:16,,,,21:16,,22:16,,
RASA,,,05:37,05:52,,06:12,,,06:27,06:47,,07:42,,,09:00,,,,10:37,,,,12:17,,,13:02,,,14:17,,,,,16:02,,,,17:07,,,,,,19:22,,,20:22,,,,21:22,,22:22,,
BATANG KALI,,,05:42,05:57,,06:17,,,06:32,06:52,,07:47,,,09:05,,,,10:42,,,,12:22,,,13:07,,,14:22,,,,,16:07,,,,17:12,,,,,,19:27,,,20:27,,,,21:27,,22:27,,
SERENDAH,,,05:52,06:07,,06:27,,,
@sweemeng
sweemeng / batucaves_pulausebang.csv
Created June 8, 2018 01:52
KTM Komuter schedule from Batu Caves to pulau sebang as of June 2018
We can make this file beautiful and searchable if this error is corrected: It looks like row 6 should actually have 46 columns, instead of 42. in line 5.
BATU CAVES - PULAU SEBANG,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
NO.TREN / TRAIN NUMBER,2003,2241,2005,2007,2009,2243,2011,2013,2245,2015,2017,2019,2021,2023,2025,2247,2027,2029,2031,2033,2035,2037,2249,2039,2041,2043,2251,2045,2047,2051,2253,2053,2055,2057,2059,2061,2257,2063,2067,2069,2071,2259,2073,2075,2077
BATU CAVES,05:15,05:45,06:10,,07:10,07:38,,08:05,08:45,,,09:18,,10:18,,11:15,,12:15,,13:05,,14:05,14:50,,,15:35,16:00,,16:35,17:05,17:35,,18:05,,,19:00,19:50,,,,20:42,21:35,,,22:30
TAMAN WAHYU,05:18,05:48,06:13,,07:13,07:41,,08:08,08:48,,,09:21,,10:21,,11:18,,12:18,,13:08,,14:08,14:53,,,15:38,16:03,,16:38,17:08,17:38,,18:08,,,19:03,19:53,,,,20:45,21:38,,,22:33
KG BATU,05:20,05:50,06:15,,07:15,07:43,,08:10,08:50,,,09:23,,10:23,,11:20,,12:20,,13:10,,14:10,14:55,,,15:40,16:05,,16:40,17:10,17:40,,18:10,,,19:05,19:55,,,,20:47,21:40,,,22:35
BT KENTONMEN,05:23,05:53,06:18,,07:18,07:46,,08:13,08:53,,,09:26,,10:26,,11:23,,12:23,,13:13,,14:13,14:58,,,15:43,16:08,,16:43,17:13,17:43,,18:13,,,19:08,19:58,,,,2