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
  • 03:33 (UTC +08:00)
View GitHub Profile
@redbug312
redbug312 / branch_bitmap.diff
Last active August 21, 2022 03:53
Compare memory usage in different ID maps
129c129
< for i in 0..32 as usize {
---
> for i in 0..8 as usize {
@redbug312
redbug312 / tigrc
Created August 4, 2022 14:09
Tig configuration with cactusbuddy theme
set main-view-date = custom
set main-view-date-format = "%Y-%m-%d"
set line-graphics = utf-8
set git-colors = no
# KEY-BINDING
# ref: https://github.com/jonas/tig/wiki/Bindings
bind main ! ?git revert %(commit)
bind main + ?git commit --amend
@redbug312
redbug312 / ac.txt
Created August 11, 2021 15:49
TLP 1.4.0-beta.1 on laptop asus x409fj
--- TLP 1.4.0-beta.1 --------------------------------------------
+++ Configured Settings:
defaults.conf L0004: TLP_ENABLE="1"
defaults.conf L0005: TLP_WARN_LEVEL="3"
defaults.conf L0006: TLP_PERSISTENT_DEFAULT="0"
defaults.conf L0007: DISK_IDLE_SECS_ON_AC="0"
defaults.conf L0008: DISK_IDLE_SECS_ON_BAT="2"
defaults.conf L0009: MAX_LOST_WORK_SECS_ON_AC="15"
defaults.conf L0010: MAX_LOST_WORK_SECS_ON_BAT="60"
@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
@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 / 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 / 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 / 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 / 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 / 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