Skip to content

Instantly share code, notes, and snippets.

View peteygao's full-sized avatar
💭
Writing Elm @ LearningLoop.com

Peter Gao peteygao

💭
Writing Elm @ LearningLoop.com
  • CTO @ LearningLoop.com
  • Singapore / San Francisco
View GitHub Profile
@peteygao
peteygao / expandable-text.js
Created November 24, 2023 08:14
Expandable Text web component (hide text behind a "Read more" button)
class ExpandableText extends HTMLElement {
private shadow: ShadowRoot;
private container: HTMLDivElement;
private readMoreBtn: HTMLSpanElement;
private expanded: boolean;
private containerLargerThanText: boolean;
constructor() {
super();
this.shadow = this.attachShadow({ mode: 'open' });
@peteygao
peteygao / install_docker.sh
Last active February 17, 2024 05:03
Auto-Install Docker and Docker Compose on AWS Lightsail running Ubuntu 20.04
# Create a 1GiB Swap File
# Lightsail ubuntu image doesn't boot with swap.
# If you run out of RAM, the system hangs OOM.
sudo fallocate -l 1G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
sudo cp /etc/fstab /etc/fstab.bak
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
### Keybase proof
I hereby claim:
* I am peteygao on github.
* I am pyg (https://keybase.io/pyg) on keybase.
* I have a public key ASD5uulFcfkEJ-omky9YHgW4ZwaBSf4K47Jo-bhaqe7twQo
To claim this, I am signing this object:
CSV Import
Empty State
submits good CSV -> Modal Closes
submits bad CSV -> Modal Shows Error
Modal Closes
Modal Shows Error
User Manually Clicks on Modal to Dismiss -> Empty State
@peteygao
peteygao / Linux Snippets
Created November 16, 2016 02:26
Linux Snippets
watch -n 1 cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq # including logical processors (HyperThreading)
watch -n 1 cat /sys/bus/platform/devices/coretemp.0/hwmon/hwmon1/temp{1,2,3}_input # temp1 is the highest core's temp
alsamixer # Terminal audio mixer (if the volume setting doesn't show up in desktop UI)
@peteygao
peteygao / .xmodmap
Last active November 16, 2016 01:14
xmodmap to swap Ctrl_L with Alt_L and remap Capslock to BackSpace
remove control = Control_L
remove mod1 = Alt_L
keycode 37 = Alt_L
keycode 64 = Control_L
add control = Control_L
add mod2 = Alt_L
clear lock
keycode 66 = BackSpace
@peteygao
peteygao / rubinius_segfault.log
Created March 21, 2016 20:52
Rubinius Segfaults during build
** Invoke gems:melbourne (first_time)
** Execute gems:melbourne
/home/pi/rubinius-3.19/staging/bin/rbx ./extconf.rbc
make && make install
compiling var_table.cpp
compiling symbols.cpp
compiling grammar.cpp
compiling melbourne.cpp
compiling visitor.cpp
compiling encoding_compat.cpp
@peteygao
peteygao / trollface.ascii
Created March 15, 2016 20:59
Trollface ACSII art
░░░░░░░░░░░░▄▀▀▀▀▀▀▀▀▄
░░░░░█░░░░▒▒▒▒▒▒▒▒▒▒▒▒▀▀▄
░░░░█░░░▒▒▒▒▒▒░░░░░░░░▒▒▒░█
░░░█░░░░░░▄██▀▄▄░░░░░▄▄▄░░░█
░▄▀▒▄▄▄▒░█▀▀▀▀▄▄█░░░██▄▄█░░░█
█░▒█▒▄░▀▄▄▄▀░░░░░░░░█░░░▒▒▒▒▒█
█░▒█░█▀▄▄░░░░░█▀░░░░▀▄░░▄▀▀▄▒█
░█░▀▄░█▄░█▀▄▄░▀░▀▀░▄▄▀░░░░░█
░░█░░░░██░░▀█▄▄▄█▄▄█▄████░█
░░░█░░░░▀▀▄░█░░░█░█▀██████░█
@peteygao
peteygao / micro_ruby_benchmark_results
Created March 2, 2016 09:45
Results of the micro Ruby benchmark testing MRI 2.3.0 vs Rubinius 3.19
RUBINIUS 3.19 MRI 2.3.0
Warming up '#sum 10 million elements' Warming up '#sum 10 million elements'
Average of 3 runs: 0.8526433626666666 Average of 3 runs: 0.7457792716666667
================================================== ==================================================
Warming up '#md5 200k elements with NO threading' Warming up '#md5 200k elements with NO threading'
Average of 3 runs: 1.4279883816666665 Average of 3 runs: 0.2355165813333333
================================================== ==================================================
Warming up '#md5 200k elements with 1 thread' Warming up '#md5 200k elements with 1 thread'
Average of 3 runs: 3.084292838666667 Average of 3 runs: 0.7009185860000001
================================================== ==================================================
@peteygao
peteygao / micro_ruby_benchmark.rb
Last active March 2, 2016 09:37
Ruby micro benchmark code to test across implementations
def bench name
warmup = yield
puts "Warming up '##{name}'"
GC.start
first = yield
GC.start
second = yield
GC.start
third = yield