Introduction

This's my personal wiki (brain dump), detailing almost everything I know.

Tools

Notes

Todo

  1. Update dotfiles.
  2. Update repo.

TabNine

Tested on sublime text, high memory usage so turned off local usage. More tests required.

Programming

I'm working through Elements of Programming Interviews. My plan is to get through most of the problems in about a year.

I'm starting to see some patterns with problems, which is a good thing.

My github repo: here

Raspberry

Change password to password

Edit /etc/shadow on SD card, change the hashed password to

$1$salt$qJH7.N4xYta3aEG/dfqo/0

Bash

Special characters in file names

- is recognized as stdin, so use ./- for checking filenames beginning with -.

Use "hello world" when names contain spaces.

IO redirection

Note: Basic file descriptor (fd) for shell's operation are 0 for STDIN, 1 for STDOUT, 2 for STDERR.

I used this code for OverTheWire Bandit 25.

#!/bin/bash

# Link fd3 to localhost:30002 bidirectional
exec 3<>/dev/tcp/localhost/30002	
# Print out first line from fd3
head -1 <&3							

old_password="UoMYTrfrBFHyQXmg6gzctqAwOmw1IohZ"

for i in {0000..9999}
do
    answer="${old_password} ${i}"
    # Send to fd3
    echo $answer >&3				
    response=$(head -1 <&3)
    if ! [[ $response =~ "Wrong" ]]
    then
        echo $i
        break
    fi
done

# Reset fd3 to normal
exec 3>&-

Variables

No spaces between =, ie. x=23. String interpolation uses ${}.

x="hello"
y="world"
z="${x} ${y}"

netcat

Use nc to create a server/client to send tcp.

# Server
nc -l 1234
# Client
nc localhost 1234

Python

Negative number

Positive numbers have leading 0, negative numbers have leading 1.

# TODO think about this, don't understand why atm
-x = complement(x-1)

Function

A function either returns something or mutate arguments. Probably put 'mutate' in docstring just in case.

Server

I'm using Ansible playbook to automate setting up vps.

TODO

Add:

  • security
  • wireguard
  • pihole

Projects

A few personal projects.

Homepass

StreetPass

3DS has a built-in feature StreetPass which lets nearby users to exchange data from games and applications. This is great if you live in a big city where there are a lot of 3DS devices. However, if you live in a small town, you would be lucky to just get a handful of streetpasses monthly.

StreetPass Relay

Due to that, Nintendo introduced another feature called StreetPass Relay. Every 3DS device has a whitelist of public wifi AP which it can automatically connect to. If connected, some data will be sent and stored on Nintendo server. When another 3DS user connects to the same AP, Nintendo server will send the stored data to the latter device. Consequently, 3DS devices don't have to be in close proximity to exchange data.

The whitelist contains the SSID and MAC of public wifi AP. Thus, some nice people figured out ways to create homemade StreetPass relays by spoofing MAC and SSID1. The basic idea to create a public wifi AP with the same SSID and MAC as in the whitelist.

For Raspberry Pi, there is SpillPass-Pi2 which work automatically when you plug in. You only need a wifi dongle wlan0 which support mac spoof and a wired internet connection eth0.

My setup is slightly different because I don't have a wired connection to the home router. What I have is 2 wifi dongles, wlan0 and wlan1. The idea is still the same, but instead of eth0 bridge to wlan0, I have wlan1 connected to the internet and wlan0 as wifi AP. All the traffic are forwarded to/from wlan0 to wlan1.

Setup

I used Raspbian Jessie Lite image. I don't have external keyboard or monitor so desktop on Raspberry Pi is unnecessary. Installed the image on the SD card by either dd or Etcher, then added your wifi network to /etc/wpa_supplicant/wpa_supplicant.conf.2

#/etc/wpa_supplicant/wpa_supplicant.conf
network={
    ssid="testing"
    psk="testingPassword"
}

Updated and installed softwares:

sudo apt update && sudo apt upgrade
sudo apt -y install hostapd dnsmasq haveged iptable-persistent sqlite3

I used this wonderful guide to setup forwarding.

Interfaces

Set wlan0 to a static ip address 10.0.0.1.

#/etc/network/interfaces
auto lo
iface lo inet loopback

iface eth0 inet manual

# AP
allow-hotplug wlan0
iface wlan0 inet static
    address 10.0.0.1
    netmask 255.255.255.0

# wireless
allow-hotplug wlan1
iface wlan1 inet manual
    wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf

Tell DHCPCD to ignore wlan0.

#/ect/dhcpcd.conf
denyinterfaces wlan0

Hostapd

Hostapd is an user daemon to start up AP. In /etc/default/hostapd, uncomment or add the line DAEMON_CONF=/etc/hostapd/hostapd.conf.

#/etc/hostapd/hostapd.conf
#sample hostapd.conf
#overwrite by homepass.sh

ssid=attwifi
bssid=34:bd:c8:db:79:00

interface=wlan0
driver=nl80211

hw_mode=g
channel=6
auth_algs=3
wpa=0
rsn_pairwise=CCMP
beacon_int=100

macaddr_acl=0

wmm_enabled=0
eap_reauth_period=360000000

You can test if AP is working by running sudo hostapd /etct/hostapd/hostapd. You should be able to see attwifi.

I use dnsmasq to map IP addresses to MAC addresses. When 3DS connect to my hotspot, it will be assigned a dynamic IP address. It is also possible to bind 3DS MAC address to a static IP address.

#/etc/dnsmasq.conf
interface=wlan0
except-interface=wlan1
dhcp-range=10.0.0.2,10.0.0.255,12h

Port forwarding

In /etc/sysctl.conf, uncomment net.ipv4.ip_forward=1.

sudo iptables -t nat -A POSTROUTING -o wlan1 -j MASQUERADE
sudo iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlan0 -o wlan1 -j ACCEPT
sudo sh -c 'iptables-save > /etc/iptables/rules.v4'

Start services sudo service hostapd start && sudo service dnsmasq start. Reboot Raspberry Pi and test if attwifi can be connected to the internet.

systemd service and timer

I use systemd to run my homepass.sh at boot time and the script will rerun every 5 minutes to change wlan0 to new SSID and MAC.

#/etc/systemd/system/homepass.service
[Unit]
Description=Homepass

[Service]
ExecStart=/home/pi/homepass.sh

[Install]
WantedBy=multi-user.target
#/etc/systemd/system/homepass.timer
[Unit]
Description=Run homepass.service every 5 minutes

[Timer]
OnStartupSec=10
OnUnitActiveSec=5min
Unit=homepass.service

[Install]
WantedBy=multi-user.target

Enable the timer by executing this command

systemctl enable homepass.timer
systemctl start homepass.timer

A nice feature of using systemd to run the script is we can access the logging easily for debugging

journalctl -u homepass

homepass.sh

This script was modified from orginal script by Semperverus. You can check out his guide for more details about HomePass. I took the idea of using sqlite3 to store MAC and SSID in a database from danielhoherd's script.

The script is rerun every 5 minutes by systemd. It stops current running hostapd service. A new /etc/hostapd/hostapd.conf is generated from querying MAC and SSID from a database. The hostapd service is then restarted with the new conf file.

#!/bin/bash
service hostapd stop

SLEEP_TIME=300
DB=/home/pi/homepass.db
CONFIG_FILE=/etc/hostapd/hostapd.conf

if [[ ! -e "$CONFIG_FILE" ]] ; then
  touch "$CONFIG_FILE"
fi

read -d '' query << EOF
SELECT mac, ssid
FROM aps
WHERE last_used < datetime('now', '-2 days') OR last_used IS NULL
ORDER BY random()
LIMIT 1;
EOF

result=$(sqlite3 "$DB" "$query")
resultArr=(${result//|/ })

MAC=${resultArr[0]}
SSID=${resultArr[1]}

if [[ -z "$MAC" ]] || [[ -z "$SSID" ]] ; then
  echo "missing MAC or SSID"
  exit 1
fi

sqlite3 "$DB" "UPDATE aps SET last_used = datetime('now') WHERE mac = '$MAC'"

cat > $CONFIG_FILE << EOF
ssid=$SSID
bssid=$MAC

interface=wlan0
driver=nl80211

hw_mode=g
channel=6
auth_algs=3
wpa=0
rsn_pairwise=CCMP
beacon_int=100

macaddr_acl=0

wmm_enabled=0
eap_reauth_period=360000000
EOF

echo "==========================================="
echo "SSID:" $SSID "- BSSID:" $MAC
echo "Time before next change:" $SLEEP_TIME "seconds"
echo "Current time:" $(date)
echo "==========================================="

service hostapd start

All files

You can find all my files at my github repo.

Games

Gaming is my hobby to pass the time.

Those days I mostly play mobile gatcha games instead of pc games. I usually purchase monthly packages so I'm not a f2p player. I used to balk at the idea of paying monthly subscription to MMOs, but now I do it without blinking for mobile games.

Playing

Girls' Frontline

Guns as anime girls.

July 31 2020

I finished the Isomer ranking map with 606k scores. It was good enough to get the exclusive fairy so I had no intention of retrying.

It was a bad day for me mentally; I felt overwhelmed all day. I cried when I made a bunch of mistakes microing the game. I ate a whole box of ice cream for dinner.

SF capture

It's coming to EN server; I really hope it isn't too much p2w.

Arknights

Tower defense with anime girls and some males.

Finished

Persona 4 Golden

I started playing Persona 4 back in 2008; I lost my save so never finished it. As the game came to PC, I finally had the chance and motivation to restart and beat it.

The gameplay is great, I'd describe it as traditional turn based JRPG combined with dating sim. IMO the story does overstay its welcome, the beginning feels too long and there are lot of downtimes in the middle. Moreover I prefer darker theme of Persona 3 to Persona 4. Persona 4 is still a great game though.

I got the golden ending on 7/5/2020. I'm missing a few achievements; I am not a completionist so I don't feel like starting new game + any time soon.

Thanks to the game, I became a longtime fan of SMT series and Atlus. I imported Demon's Souls, SMT: Strange Journey and SMT: Devil Survivor to UK when I was in college. Funny enough, I also lost my save to Strange Journey; maybe one day I'll attempt to complete Strange Journey Redux.

Monster Train

I'm a big fan of Slay the Spire and the former game scratches the same itch. It combines deck building with tower defense, which are pretty cool.

I got to covenant 25 so I'm taking a break from the game.

Books

I'm reading

  • Reverend Insanity: evil MC, cultivation story.
  • Lord of the Mysteries: steampunk setting, cool story. The first 100 chapters are tedious, but it keeps getting better after that.
  • Kumo: Japanese reincarnation light novel.
  • Tearmoon Empire: finished second book. Fun light-hearted story; misunderstanding - the story.
  • Bakarina: reading volume 3. It's not as good as the first 2 books.

Watching

I'm watching:

  1. Doom Patrol season 2.
  2. Hololive. I recently got into vtuber.

Trading

This isn't investment, it's pure speculation at best and gambling at worst.

Why

I feel alive testing my hypotheses, regardless of wins or losses.

Financial Responsibility

I've a separate retirement account and a fun Robinhood account. The former account is invested in boring ETFs and bonds to hold forever. As for the latter, it isn't a big deal if I lost it all.

I also only allocate 1% or 2% of my portfolio for every risky play. So a single loss won't wipe my entire account. On the flip side, I'm not going to get rich any time soon.

I followed /r/wallstreetbets and it has been a wild ride. Sometimes I win, sometimes I lose; at least my account is still positive. I got burnt playing naked options so I don't want to touch them for now.

Plays

Beware: Survivor Bias belows.

UPRO/TMF 55/45 Jan 1 2019 - present

About 90% of my account are on this. I found about this through the subreddit; it was originally posted at bogleheads.

In March 2020, it was down by 30%. Luckily I didn't abandon the strategy and I also kept buying UPRO as it went down. I also did some re-balancing during that time, sold TMF and bought UPRO.

Since then, it has steadily recovered. As of today August 2020, it's about 21% up.

PRPL

I saw the posts about the mattress company on subreddit at the end of July 2020. They've sound arguments and data to back them up, at least to my ears anyways.

August 4 2020: bought 100 shares at $24.74, sold 30C 8/21/20 for $2.10

Target price: $30

Plan: wait until earning report next week and decide what to do next, may hold for long term though.

PSTHU

First time I've ever heard and invested into SPAC. Bill Ackman is behind this so it has a lot of hype going.

July 2020: bought 234 shares at $21.68.

Plan: pray for good news about the targeted mature unicorn.