Skip to content

Instantly share code, notes, and snippets.

@IvanaGyro
IvanaGyro / createNTUCourseEvents.js
Last active September 10, 2022 16:44
Create the Google Calendar event links of the courses on the NTU "My Schedule" page.
javascript: (() => {
/**
* This script is used to create the Google Calendar event links of the
* courses on the NTU "My Schedule" page.
*/
if (
location.href !== "https://nol.ntu.edu.tw/nol/coursesearch/myschedule.php"
) {
return;
}
@IvanaGyro
IvanaGyro / Beiyi.py
Created January 13, 2022 13:25
嘲諷北宜區間測速
'''
WARNING: This model does NOT reflect the situation of the real world, and
I(the author) do NOT like to decide which policy the government should
implement based on accidents data.
'''
import sys
import random
if not sys.version_info.major == 3 and sys.version_info.minor >= 7:
@IvanaGyro
IvanaGyro / copy_result.js
Last active January 17, 2021 16:58
Copy results of Taipei traffic violation reports from Gmail web page to the clipboard.
/**
* Usage:
* 1. Minify this script.
* 2. Rewrite minified script to `javascript:THE_MINIFIED_SCIPT`.
* 3. Add modified script to your bookmark.
* 4. Click it when you're at the Gmail page.
*/
(async function () {
if (location.hostname != 'mail.google.com') return;
@IvanaGyro
IvanaGyro / extract_ooni.py
Last active September 4, 2020 03:24
把OONI測試趨勢家長防護網的結果從資料庫中匯出至CSV
import csv
import json
import pathlib
import re
import sqlite3
import sys
import urllib
from pprint import pprint
from bs4 import BeautifulSoup
@IvanaGyro
IvanaGyro / Chapter-1-6.hs
Last active July 31, 2020 08:57 — forked from banacorn/Chapter-1-6.hs
FLOLAC 2020「邏輯、語言、與計算暑期研習營」的課前作業
-- This exercise covers the first 6 chapters of "Learn You a Haskell for Great Good!"
-- Chapter 1 - http://learnyouahaskell.com/introduction
-- Chapter 2 - http://learnyouahaskell.com/starting-out
-- Chapter 3 - http://learnyouahaskell.com/types-and-typeclasses
-- Chapter 4 - http://learnyouahaskell.com/syntax-in-functions
-- Chapter 5 - http://learnyouahaskell.com/recursion
-- Chapter 6 - http://learnyouahaskell.com/higher-order-functions
-- Download this file and then type ":l Chapter-1-6.hs" in GHCi to load this exercise
@IvanaGyro
IvanaGyro / demo_argspec.py
Created June 23, 2020 07:35
Demo `getargspec` and `getfullargspec`
from inspect import getargspec, getfullargspec
def kwargs_only(a, b, c=3, d=4, **kwargs):
pass
def default_args(a, b, c=3, d=4, *args, **kwargs):
pass
def default_kwargs(a, b, *args, c=3, d=4, **kwargs):
@IvanaGyro
IvanaGyro / seq2lookup.py
Created June 23, 2020 06:45
Sequence to lookup map -- a stupid function
from typing import Dict, List, Iterable, Hashable, Mapping, Sequence
def seq2lookup(
seqences: Iterable[Sequence], index: int,
) -> Dict[Hashable, Sequence]:
"""
Build the lookup table from a group of sequences.
The lookup table is used to quickly find the target sequence with the
corresponding item which is at the specific index of the target sequence.
@IvanaGyro
IvanaGyro / photo_datetime.py
Last active March 18, 2023 12:15
Draw datetime on the photos and the videos.
import os
import io
from pathlib import Path
from PIL import Image
from PIL import ImageFont
from PIL import ImageDraw
from PIL import ExifTags
import exiftool
@IvanaGyro
IvanaGyro / schema.js
Created June 22, 2020 09:54
Helper for exploring MongoDB's schema.
function signature(e){switch(typeof e){case"string":return"s";case"number":return Number.isInteger(e)?"i":"f";case"undefined":return"u";default:return null===e?"n":e.constructor===Array?"a":`{${Object.keys(e).sort().map(r=>`${r}:${signature(e[r])}`).join(",")}}`}}
function deserilize(sign){return eval(`i='i';s='s';n='n';a='a';f='f';var o=${sign};o;`)}
function _diff([e,t]){return Object.keys(e).forEach(f=>{"object"==typeof e[f]&&"object"==typeof t[f]?([e[f],t[f]]=_diff([e[f],t[f]]),Object.keys(e[f]).length||Object.keys(t[f]).length||(delete e[f],delete t[f])):e[f]===t[f]&&(delete e[f],delete t[f])}),[e,t]}
function diff(f,i){return _diff([f,i].map(deserilize))}
// > use mydb
db.mycollection.mapReduce(function() { emit(signature(this), 1)}, function(k, vs) { return Array.sum(vs) }, { out: {replace: 'mycollection_', db: 'mydbschema'}, scope: { signature })
// > use mydbschema
@IvanaGyro
IvanaGyro / hanlpWrapper.js
Created February 12, 2020 03:19
Wrap java objects to get the properties with the dot operator.
const java = require('java');
const path = require('path');
const JAVA_DIR = path.resolve(__dirname, '../libs/java/');
java.options = [ '-Xms3072m' , '-Xmx3072m', '-Xmn1152m' ];
java.asyncOptions = {
asyncSuffix: 'Async',
syncSuffix: '', // For readability, remove the convetional suffix of sync
// functions.
ifReadOnlySuffix: '_alt',