Skip to content

Instantly share code, notes, and snippets.

@kmcheung12
kmcheung12 / squashing.md
Last active October 21, 2024 22:37
A Note on Squashing Django Migrations

A Note on Squashing Django Migrations

Django support squashing migrations that compresses the migration history.

eventually you will want to move back from having several hundred migrations to just a few

Which beg the obvious question, why?

Motivation

@kmcheung12
kmcheung12 / timedtext2srt.py
Created April 17, 2019 17:17
Convert youtube timedtext subtitle file into srt
import xml.etree.ElementTree as ET
fmt = '%02d:%02d:%02d,%03d'
def to_time(m_sec):
mm = m_sec % 1000
s = m_sec // 1000 % 60
m = m_sec // 1000 // 60 % 60
h = m_sec // 1000 // 60 // 60
return (h, m, s, mm)
@kmcheung12
kmcheung12 / introrx.md
Created February 2, 2018 02:25 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
Ctrl-a Move cursor to start of line
Ctrl-e Move cursor to end of line
Ctrl-b Move back one character
Esc-b Move back one word
Ctrl-f Move forward one character
Esc-f Move forward one word
Ctrl-d Delete current character
Ctrl-h Delete backward one character
Ctrl-w Cut the last word
Ctrl-k Cut everything after the cursor
@kmcheung12
kmcheung12 / recover_source_code.md
Created March 12, 2017 13:48 — forked from simonw/recover_source_code.md
How to recover lost Python source code if it's still resident in-memory

How to recover lost Python source code if it's still resident in-memory

I screwed up using git ("git checkout --" on the wrong file) and managed to delete the code I had just written... but it was still running in a process in a docker container. Here's how I got it back, using https://pypi.python.org/pypi/pyrasite/ and https://pypi.python.org/pypi/uncompyle6

Attach a shell to the docker container

Install GDB (needed by pyrasite)

apt-get update && apt-get install gdb
set nocompatible
filetype off
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
" All of your Plugins must be added before the following line
Plugin 'nvie/vim-flake8'
Host tunnel
Hostname db.example.com
User foo
Port 22
LocalForward 27017 127.0.0.1:27017
LogLevel DEBUG
IdentitiesOnly yes
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
var ws = new WebSocket("ws://127.0.0.1:8080/websocket");
ws.onopen = function() {
setInterval(send, 3000, ws);
};
function send(websocket) {
@kmcheung12
kmcheung12 / .tmux.conf
Last active February 17, 2016 04:33
My tmux conf
set -g prefix C-a
unbind C-b
set -sg escape-time 1
bind r source-file ~/.tmux.conf \; display "Reloaded!"
bind C-a send-prefix
set -g base-index 1
@kmcheung12
kmcheung12 / git aliases
Created June 1, 2015 07:05
Useful git aliases
# Aliases
alias g='git'
alias gst='git status'
alias gd='git diff'
alias gdc='git diff --cached'
alias gdt='git diff-tree --no-commit-id --name-only -r'
alias gl='git pull'
alias gup='git pull --rebase'
alias gp='git push'
alias gd='git diff'