Skip to content

Instantly share code, notes, and snippets.

View Leedehai's full-sized avatar
:octocat:
Undefined behavior

Leedehai

:octocat:
Undefined behavior
View GitHub Profile
@Leedehai
Leedehai / git-filter.py
Last active April 22, 2018 21:31
Python script: better git-filter-branch to remove sensitive file from all branches
#!/usr/bin/env python
# usage: git-filter.py PATH_TO_TARGET_FILE
# (or make an alias for "git-filter-branch.py")
# Prototype:
# git filter-branch --force --index-filter \
# 'git rm --cached --ignore-unmatch PATH_TO_TARGET_FILE' \
# --prune-empty --tag-name-filter cat -- --all
# Reference: https://help.github.com/articles/removing-sensitive-data-from-a-repository/
@Leedehai
Leedehai / keep
Created April 26, 2018 08:02
Shell command line to display incrementing dots (should not be in a script)
'while true; do sleep 0.5; echo -en "\r. "; sleep 0.5; echo -en "\r.. "; sleep 0.5; echo -en "\r... "; sleep 0.5; echo -en "\r "; done' # should not be in a shell script
git gc --aggressive --prune=now
git reflog expire --expire=now --expire-unreachable=now --all
git repack -ad # Remove dangling objects from packfiles
git prune # Remove dangling loose objects
@Leedehai
Leedehai / manual-rtti.cc
Last active June 12, 2019 17:39
Play with manual C++ RTTI (inspired by LLVM/Clang)
#include <iostream>
using namespace std; // yeah I know it's better to use "ns::foo" instead of declaring "using namespace ns" at the top...
// but this file is just a toy, right. Live a little.
enum Kind_t { KA, KB, KC, KD };
class A {
Kind_t kind;
public:
A(Kind_t kind = KA) : kind(kind) {}
@Leedehai
Leedehai / make-64-bit-mask.cc
Last active June 12, 2019 17:38
Make 64 bit masks: set bits [a, b] to 1's and others 0's
// C++ version 1
#include <iostream>
#include <string>
#include <bitset>
using namespace std; // yeah I know it's better to use "ns::foo" instead of declaring "using namespace ns" at the top...
// but this file is just a toy, right. Live a little.
int main_old()
{
int a = 31, b = 63;
@Leedehai
Leedehai / Makefile detect OS and select compiler
Created August 16, 2018 07:39
Makefile detect OS and select compiler
T_OPERERATING_SYSTEM := $(shell uname -s)
ifeq ($(T_OPERERATING_SYSTEM), Linux)
T_CXX := g++
endif
ifeq ($(T_OPERERATING_SYSTEM), Darwin) # macOS
T_CXX := clang++
endif
@Leedehai
Leedehai / build.sh
Last active August 1, 2019 02:51
Build LLVM/Clang on Linux/macOS from scratch (CMake required)
#!/usr/bin/env sh
echo About to build LLVM/Clang.. Are you sure \(y/N\)?
read consent
if [ $consent != 'y' ] && [ $consent != 'Y' ]; then
echo Aborted
exit 1
fi
echo Start downloading > time.log
date >> time.log
@Leedehai
Leedehai / vm.sh
Last active July 13, 2019 05:30
Control VirtualBox from terminal command line: VirtualBox CLI shortcuts script (set alias vm='vm.sh')
#!/usr/bin/env sh
DEFAULT_VM=your_default_vm_name # fill it yourself
SSH_USERNAME=your_username_to_ssh # fill it yourself
VM_PROPERTY_IP=/VirtualBox/GuestInfo/Net/1/V4/IP
VM_PROPERTY_OS=/VirtualBox/GuestInfo/OS/Product
function print_usage() {
echo " vm -h|--help -- display this help message"
echo " vm on|off [VM] -- turn on/off VM"
echo " vm ssh [VM] -- ssh to VM"
@Leedehai
Leedehai / print-line-elide.py
Created January 10, 2019 04:55
Python: print strings in the same line, overwriting the previous content
#!/usr/bin/env python
# Tested on Python2.7 and Python3.5
import os, sys
import time
lines = [
"abc",
"abcdefghi",
"a",
@Leedehai
Leedehai / vim-ls.sh
Created June 1, 2019 08:04
vim <=> ls: to relieve a common command typo headache when working in terminal
# This contains two files.. the ls proxy and the vim proxy
# Problem I wanted to solve:
# when working in terminal, sometimes I mistake ls with vim, or vice versa, when I
# am inspecting a directory recursively. When this happens, I have to retype the
# command. Yes, '!$' helps me to re-use the previous argument, but I still wish the
# experience could be smoother.
# Solution:
# make ls and vim interchangeable by delegating ls and vim to proxy scripts, and set
# alias 'ls' and 'vim' to these scripts.