Skip to content

Instantly share code, notes, and snippets.

Avatar

Johnson Zhong LemonPi

View GitHub Profile
@LemonPi
LemonPi / bmatrix.m
Created Nov 6, 2019
print matrix/vector in matlab in latex form
View bmatrix.m
function code = bmatrix(X)
code = "\\begin{bmatrix}" + newline;
rows = size(X, 1);
cols = size(X, 2);
for i=1:rows
for j=1:cols
if j == cols
code = code + X(i, j) + " \\\\";
else
code = code + X(i, j) + " & ";
@LemonPi
LemonPi / watch_sync.py
Last active Nov 3, 2018
Automatic rsync on file change (alternative for systems without inotifywait)
View watch_sync.py
import sys
import time
import logging
from watchdog.observers import Observer
from watchdog.events import RegexMatchingEventHandler
from subprocess import call
import argparse
class RsyncHandler(RegexMatchingEventHandler):
def __init__(self, path, target):
@LemonPi
LemonPi / vocab.txt
Created Aug 16, 2018
GRE vocabulary map
View vocab.txt
repeated too often as to lose meaning
- banal
- trite
- platitude (a trite remark)
- hackneyed (lacking significance from overuse)
- bromide (a trite or obvious remark)
dull
- insipid (lacking flavour or interest)
- prosaic (dull and lacking imagination)
View .screenrc
# For a complete list of available commands, see http://bit.ly/jLtj
# Message to display in the status line when activity is detected in a
# monitored window.
activity "activity in %n (%t) [%w:%s]~"
# Detach session on hangup instead of terminating screen completely.
autodetach on # default: on
# When a bell character is sent to a background window, screen displays a
@LemonPi
LemonPi / pre-commit.hook
Created Jan 18, 2018
pre-commit hook for checking source files are clang-formatted, giving command to format any unformatted files
View pre-commit.hook
#!/bin/bash
#
# Check that all source files follow a fixed format.
# Called by "git commit" with no arguments.
# Commit is blocked if any file does not follow format and outputs
# command to format them.
# Enable this by copying this file into .git/hooks/pre-commit
ROOT=$(git rev-parse --show-toplevel)
FORMATTER="clang-format"
@LemonPi
LemonPi / .clang-format
Last active Oct 2, 2017
Clang format options
View .clang-format
# put in project root
---
# We'll use defaults from the LLVM style, but with 4 columns indentation.
BasedOnStyle: LLVM
IndentWidth: 4
---
Language: Cpp
# Force pointers to the type for C++.
DerivePointerAlignment: false
@LemonPi
LemonPi / grape
Created Mar 30, 2017
Search recursively for patterns in C++ source files
View grape
#!/bin/bash
grep -rn --color=always --include=\*.{cpp,hpp,c,h} $@
@LemonPi
LemonPi / clear_terminal
Created Mar 15, 2017
Clear terminal for real rather than printing new lines; enter on bash
View clear_terminal
printf "\033c"
@LemonPi
LemonPi / mode_docs_spreadsheet
Created Feb 24, 2017
Google Docs query for listing rows by occurance
View mode_docs_spreadsheet
=query(index(if({1,1},upper(D3:D24)&"")),"select Col1,count(Col2) where Col1<>'' group by Col1 order by count(Col2) desc",0)
@LemonPi
LemonPi / g11
Last active Feb 23, 2017
Quick c++11 compile script for bash; put in user path (e.g. /usr/bin/)
View g11
filename=$(basename "$1")
outfile="${filename%.*}"
{ g++ -o $outfile $@ -std=c++11 2>&1; } | tee log.txt