Skip to content

Instantly share code, notes, and snippets.

@tommyip
tommyip / git-stash-extras.fish
Created August 23, 2023 11:24
The missing Git stash commands
# Pass in stash message as the first argument
function git-stash-unstaged --description "Only stash unstaged changes"
git commit -m "git-stash-unstaged"
git stash push -u -m $argv[1]
git reset --soft HEAD^
end

Keybase proof

I hereby claim:

  • I am tommyip on github.
  • I am thomasip (https://keybase.io/thomasip) on keybase.
  • I have a public key ASBZzsI9Q7hdaY-EEmOmEDOkeXulP23Zdmz0RdFz4sOT4wo

To claim this, I am signing this object:

@tommyip
tommyip / venv.fish
Last active February 23, 2024 20:00
venv.fish - Automatically activate/deactivate virtualenv in fish shell
# Based on https://gist.github.com/bastibe/c0950e463ffdfdfada7adf149ae77c6f
# Changes:
# * Instead of overriding cd, we detect directory change. This allows the script to work
# for other means of cd, such as z.
# * Update syntax to work with new versions of fish.
# * Handle virtualenvs that are not located in the root of a git directory.
function __auto_source_venv --on-variable PWD --description "Activate/Deactivate virtualenv on directory change"
status --is-command-substitution; and return
@tommyip
tommyip / minimal_wiki.css
Last active January 1, 2021 10:57
Minimalist Wikipedia theme (hide header and sidebars + bigger fonts + limit max width)
#content {
margin-left: 0;
}
#mw-panel {
display: none;
}
#bodyContent {
font-size: 18px;
@tommyip
tommyip / aoc2020_day13.dyalog
Created December 28, 2020 04:35
AoC2020 Day 13 Dyalog APL solution from @jayfoad
⍝ Credit: @jayfoad (https://github.com/jayfoad/aoc2020apl/blob/main/p13.dyalog)
⎕IO←0
a←⍎⊃p←⊃⎕NGET'p13.txt'1
d←⍎¨b⌷⍨⊂c←⍸(,'x')∘≢¨b←'\w+'⎕S'&'⊃⌽p
{(⊃⍋⍵)⊃d×⍵}d|-a ⍝ part 1
⎕PP←17 ⋄ ⎕FR←1287
gcd←{⍵=0:⍺ 1 0 ⋄ g s t←⍵∇⍵|⍺ ⋄ g t(s-t×⌊⍺÷⍵)}
crt←{z←⍵÷⍨m←×/⍵ ⋄ m|+/⍺×z×1⊃¨z gcd¨⍵}
(-c)crt d ⍝ part 2
#!/usr/bin/env ruby
# Usage
# ~~~~~
#
# Run from the root of ETS
#
# $ chmod +x migrate_address
# $ ./migrate_address.rb <address csv file>
@tommyip
tommyip / gsoc19_work_product.md
Last active August 24, 2019 06:13
GSoC 2019 Work Product (Thomas Ip)

GSoC 2019 Work Product

This summer I worked on improving the developer-friendliness of the frontend toolchain as well as fixing other miscellaneous issues. It has been a rewarding experience to work with Zulip and learn from this awesome community. Huge thanks to @tabbott and @andersk for their help and reviews on my work.

Below is a list of work I did during the summer:

#!/usr/bin/env python3
"""
1. Convert CommonJS to typescript module
1.1 Remove IIFE wrapping
1.2 Use ES6 style import
1.3 Use ES6 style export
1.4 Import from other modules
1.5 Remove from .eslintrc
1.6 Remove from js_typings
1.7 Remove from app.js bundle
#include <iostream>
#include <iostream>
#include <cstdlib> // for srand() and rand()
#include <ctime> // for time()
using namespace std;
void fillCubeRandomly(int cube[][3][3]) {
srand(time(nullptr));
for (int x = 0; x < 3; ++x) {
for (int y = 0; y < 3; ++y) {
/* Lab 6: Voting - An election system
* File: lab6_skeleton.cpp
*/
#include<iostream>
using namespace std;
const int MAX_SIZE = 50;
const int MAX_STRING_LENGTH = 20;