Skip to content

Instantly share code, notes, and snippets.

@rightson
rightson / setup.sh
Created November 14, 2017 13:03
git diff with vim
git config --global diff.tool vimdiff
git config --global difftool.prompt false
git config --global alias.vimdiff difftool
# Usage: git vimdiff
# git vimdiff --cached
@rightson
rightson / download-pip.sh
Created November 15, 2017 06:22
Download pip packages to specific folder
pip download -r requirement.txt -d pip-packages
@rightson
rightson / install-pip-offline.sh
Created November 15, 2017 06:24
Install pip packages from given folder
pip install --no-index --find-links file://`pwd`/pip-pkgs -r requirement.txt
@rightson
rightson / build-python3-with-sqlite3.sh
Created November 16, 2017 10:06
Link to a specific version of sqlite3 when building Python 3 versions
# references: https://github.com/pyenv/pyenv/issues/333
# get pyenv
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
# configure pyenv
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> $PROFILE
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> $PROFILE
# install python
@rightson
rightson / expand-path.cpp
Last active December 4, 2017 16:42
A rough and dirty way to expand string containing path using GNU wordexp
// ref: https://linux.die.net/man/3/wordexp
#include <iostream>
#include <string>
#include <wordexp.h>
using namespace std;
std::string expandPath(const std::string &str) {
wordexp_t p;
char** w;
wordexp(str.c_str(), &p, 0);
@rightson
rightson / tty_ldisc.h
Created December 13, 2017 10:56
TTY line discipline example structure
struct tty_ldisc {
int magic;
char *name;
int num;
int flags; /* * The following routines are called from above. */
int (*open)(struct tty_struct *);
void (*close)(struct tty_struct *);
void (*flush_buffer)(struct tty_struct *tty);
ssize_t (*chars_in_buffer)(struct tty_struct *tty);
ssize_t (*read)(struct tty_struct *tty, struct file *file, unsigned char *buf,
@rightson
rightson / terminator.config
Last active December 20, 2017 03:35
~/.config/terminator/config
[global_config]
scroll_tabbar = True
title_font = Lucida Console Semi-Condensed 13
title_inactive_bg_color = "#000000"
title_inactive_fg_color = "#714c4c"
title_transmit_bg_color = "#000001"
[keybindings]
switch_to_tab_1 = <Alt>1
switch_to_tab_2 = <Alt>2
switch_to_tab_3 = <Alt>3
@rightson
rightson / memory-layout.c
Created January 10, 2018 13:05
Example memory layout
#include <stdio.h>
#include <stdlib.h>
int init_global_var = 10; /* Initialized global variable */
int global_var; /* Uninitialized global variable */
static int init_static_var = 20; /* Initialized static variable in global scope */
static int static_var; /* Uninitialized static variable in global scope */
int main(int argc, char **argv, char **envp)
@rightson
rightson / memory-layout.c
Created January 10, 2018 13:05
Example memory layout
#include <stdio.h>
#include <stdlib.h>
int init_global_var = 10; /* Initialized global variable */
int global_var; /* Uninitialized global variable */
static int init_static_var = 20; /* Initialized static variable in global scope */
static int static_var; /* Uninitialized static variable in global scope */
int main(int argc, char **argv, char **envp)
@rightson
rightson / simple-pipe-redirect.c
Last active January 10, 2018 13:11
Simple pipe and redirect
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
int main(int argc, char *argv[], char *envp[])
{
// goal: emulate the behavior of `ls -l | grep prog > output 2> errfile`
int outfd;
int errfd;
int pipefd[2];