Skip to content

Instantly share code, notes, and snippets.

View redbug312's full-sized avatar
🎃
Any pun-pkin?

redbug312

🎃
Any pun-pkin?
  • Foxtronev
  • New Taipei City, Taiwan
  • 00:06 (UTC +08:00)
View GitHub Profile
@redbug312
redbug312 / main.gs
Last active April 17, 2016 13:26
[Google App Scripts] send emails when the sheet received a submitting from the form
// https://developers.google.com/apps-script/reference/properties/properties#deletepropertykey
var colMap = PropertiesService.getScriptProperties();
colMap.setProperties({
"時間戳記": 0,
"蘆薈洗面乳": 4,
"蘆薈水晶凝露": 5,
"原味魷魚絲": 7,
"水晶魚": 8,
"紅豆糕": 9,
"泉利鹹餅": 11,
@redbug312
redbug312 / cpp.json
Last active April 16, 2016 05:02
My C++ Snippets for Visual Studio Code.
{
"Local Debug": {
"prefix": "DEBUG",
"body": [
"#define FLAG fprintf(stderr,\"\\033[32;1m#FLAG\\033[0m\\n\");",
"#define BIN(x) {fprintf(stderr,\" \\033[33;1m#DEBUG:\\033[0m \"#x\" = \"); \\",
"\tfor(int i=15;i>=0;--i)fprintf(stderr,\"%c\",((x)&(1<<i))?'1':'0'); \\",
"\tfprintf(stderr,\"\\n\");}",
"#define INT(x) fprintf(stderr,\" \\033[33;1m#DEBUG:\\033[0m \"#x\" = %d\\n\", x);",
"#define CHR(x) fprintf(stderr,\" \\033[33;1m#DEBUG:\\033[0m \"#x\" = %c\\n\", x);",
@redbug312
redbug312 / nub.hs
Created May 1, 2018 15:19
FLOLAC'18 prerequisite p1
nub :: [Int] -> [Int]
nub [] = []
nub [x] = [x]
nub (x:xs) = if x `elem` xs then nub xs else x : nub xs
@redbug312
redbug312 / histogram.hs
Last active May 6, 2018 17:54
FLOLAC'18 prerequisite p2
stat :: [Int] -> [Int]
stat [] = replicate 10 0
stat (x:xs) = (take x stats) ++ [stats !! x + 1] ++ tail (drop x stats)
where stats = stat xs
plot :: [Int] -> [String]
plot ys
| all (== 0) ys = []
| otherwise = row : plot ys'
where row = map (\y -> if y == 0 then ' ' else '*') ys
@redbug312
redbug312 / goldbach.hs
Last active May 11, 2018 10:55
FLOLAC'18 prerequisite p3
-- Build prime number table would be much slower than performing prime tests,
-- since we check only x and n-x, and in most cases x < 10 (28.7% when n < 20000).
goldbach' :: Int -> Int -> Int -> [Int]
goldbach' n m1 m2 = filter (\x -> isPrime x && isPrime (n-x)) $ 3:5:[6+m1,12+m1..n-2]
where isPrime x = null $ filter (\y -> x `mod` y == 0) [2..fsqrt x] -- expect x > 1
fsqrt = floor.sqrt.fromIntegral
goldbach :: Int -> Maybe (Int, Int)
goldbach 4 = Just (2, 2) -- the only case 2 would showed up
@redbug312
redbug312 / prerequisites.hs
Created May 21, 2018 16:14
Prerequisites for signing up FLOLAC'18
-- p1
myFst :: (a, b) -> a
myFst = fst -- seemed the only way :(
-- p2
myOdd :: Int -> Bool
myOdd = (==) 1 . flip mod 2
-- p3
{-
@redbug312
redbug312 / caeser.hs
Last active May 26, 2018 20:00
FLOLAC'18 prerequisite p4
encode :: Int -> String -> String
encode key plain = [shift key p | p <- plain]
where shift n c = ['A'..'Z'] !! mod (fromEnum c - fromEnum 'A' + n) 26
decode :: String -> (String, Int)
decode cipher = let key = (snd.maximum) search in (encode (-key) cipher, key)
where search = zip (drop 25 $ convolve cipher_stats (letter_freqs ++ letter_freqs)) (0:[25,24..1])
cipher_stats = [fromIntegral.length $ filter (==c) cipher | c <- ['A'..'Z']]
-- 1D discrete convolution altered from stackoverflow.com/a/39784716
@redbug312
redbug312 / focus-window.sh
Last active November 8, 2020 09:12
Bash script to lift and focus on (most recently focused) apps.
#!/usr/bin/env bash
# https://askubuntu.com/a/562191
usage() {
echo Usage: $(basename $0) PATTERN
exit 1
}
[ $# -ne 1 ] && usage
pattern=$1
@redbug312
redbug312 / counts.py
Last active July 8, 2020 21:52
ntuoc13-voting-counts
#!/usr/bin/env python3
import pandas as pd
import numpy as np
def display(df):
options = ['display.max_rows', None]
options += ['display.unicode.east_asian_width', True]
with pd.option_context(*options):
print(df)
@redbug312
redbug312 / gaba.dat
Last active October 14, 2020 14:52
Bubble chart in Gnuplot. Visualize GABA oolong tea with GC/MS analysis, as the final report for Introduction of Analysis in Tea Quality (2019)
#Peak RT Area% Name Quality Odor Odor-encode
12 5.88 0.90 Furfural 90 Medium bready 2 #de795f
24 8.80 1.65 Benzaldehyde 97 High fruity 3 #de5f83
25 9.09 0.30 Benzaldehyde 94 High fruity 3 #de5f83
27 9.47 0.45 Methyl_heptenone 97 Medium citric 2 #f0c674
29 9.69 0.83 (E,E)-2,4-heptadienal 94 High fatty 3 #b8baac
34 10.50 0.36 Dipentene 92 Medium citric 2 #f0c674
35 10.61 2.57 Benzyl_alcohol 98 Medium floral 2 #b283bd
43 12.17 2.64 Linalool 97 Medium floral 2 #b283bd
45 12.48 3.06 Phenethyl_alcohol 97 Medium floral 2 #b283bd