Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / server.js
Created October 20, 2017 10:04
Koa example minimal server
'use strict';
const path = require('path');
const zlib = require('zlib');
const winston = require('winston');
const Koa = require('koa');
const Router = require('koa-router');
const koaLogger = require('winston-koa-logger');
const convert = require('koa-convert');
const compress = require('koa-compress');
# from https://stackoverflow.com/questions/1128496/to-get-a-prompt-which-indicates-git-branch-in-zsh
# get the name of the branch we are on
git_prompt_info() {
git branch | awk '/^\*/ { print $2 }'
}
get_git_dirty() {
git diff --quiet || echo '*'
}
autoload -U colors
@rightson
rightson / git-clean-large-object.sh
Last active June 7, 2017 07:05
Script to clean up large object from git repository
# Reference: http://stevelorek.com/how-to-shrink-a-git-repository.html
function discoveryLargeGitObject() {
IFS=$'\n';
# list all objects including their size, sort by size, take top 10
objects=`git verify-pack -v .git/objects/pack/pack-*.idx | grep -v chain | sort -k3nr | head`
echo "All sizes are in kB. The pack column is the size of the object, compressed, inside the pack file."
@rightson
rightson / .Xresources
Created May 2, 2017 23:27
molokai color theme for xterm (from vreon/.Xresources)
*xterm*font: 12x24
*xterm*background: #101010
*xterm*foreground: #d0d0d0
*xterm*cursorColor: #d0d0d0
*xterm*color0: #101010
*xterm*color1: #960050
*xterm*color2: #66aa11
*xterm*color3: #c47f2c
*xterm*color4: #30309b
*xterm*color5: #7e40a5