Skip to content

Instantly share code, notes, and snippets.

View Liam0205's full-sized avatar
🎯
Focusing

Liam Huang Liam0205

🎯
Focusing
View GitHub Profile
#include <iostream>
#include <string>
struct Person {
size_t age = 0;
std::string name;
Person& operator++() { // prefix
++age;
return *this;
@Liam0205
Liam0205 / install_git.sh
Created December 18, 2018 10:53
Compile and Install Git on CentOS 7
yum install asciidoc
yum install xmlto
yum install zlib-devel
yum install cpan
version="2.9.5"
fname="git-${version}"
tarball="${fname}.tar.gz"
wget https://mirrors.edge.kernel.org/pub/software/scm/git/${tarball}
@Liam0205
Liam0205 / install_vim.sh
Created November 2, 2018 03:17
Compile and install VIM on CentOS 6.x without root.
#!/bin/bash
git clone https://github.com/vim/vim.git --depth=1
cd vim
make -p $HOME/local/bin
./configure --prefix=$HOME/local/vim --enable-multibyte --with-tlib=tinfo --enable-pythoninterp --enable-rubyinterp --with-ruby-command=/usr/bin/ruby --with-features=huge
make -j24
make install
cd $HOME/local/bin
for file in $(ls $HOME/local/vim/bin); do ln -sf $HOME/local/vim/bin/$file $file; done
@Liam0205
Liam0205 / cstring_switch.cc
Last active July 29, 2021 02:15
Apply C style string in switch-case clause in C++. (C++11 or above required)
#include <iostream>
#include <string>
using hash_t = size_t;
constexpr hash_t prime = 0x100000001B3ull;
constexpr hash_t basis = 0xCBF29CE484222325ull;
hash_t hash_run_time(const char* str) {
hash_t ret = basis;
@Liam0205
Liam0205 / displayfile
Created April 23, 2018 15:14
displayfile (Skim)
#!/bin/bash
# displayfile (Skim)
#
# Usage: displayfile [-r] [-g] PDFFILE
#
# Modified from "displayline" to only revert the file, not jump to a given line
#
if [ $# == 0 -o "$1" == "-h" -o "$1" == "-help" ]; then
\documentclass{article}
\usepackage{xcolor}
\usepackage{listings}
\lstdefinestyle{lfonts}{
basicstyle = \footnotesize\ttfamily,
stringstyle = \color{purple},
keywordstyle = \color{blue!60!black}\bfseries,
commentstyle = \color{olive}\scshape,
}
\lstdefinestyle{lnumbers}{
@Liam0205
Liam0205 / distinct_random.cc
Last active February 2, 2018 12:01
generate distinct random numbers in C++.
#include <iostream>
#include <unordered_set>
#include <random>
template <typename IntType = int>
class distinct_uniform_int_distribution {
public:
using result_type = IntType;
private:
@Liam0205
Liam0205 / MersenneTwister.py
Created January 25, 2018 04:40
A demo implementation of Mesenne Twister PRNG in Python.
class MersenneTwister:
__n = 624
__m = 397
__a = 0x9908b0df
__b = 0x9d2c5680
__c = 0xefc60000
__kInitOperand = 0x6c078965
__kMaxBits = 0xffffffff
__kUpperBits = 0x80000000
__kLowerBits = 0x7fffffff
\documentclass{article}
\usepackage{amsmath}
\newcommand{\arbbv}[3][0]{\ensuremath{#2_{#1}, #2_{#1}, \ldots, #2_{#3}}}
\begin{document}
\[
\arbbv{a}{n}.
\]
\end{document}
@Liam0205
Liam0205 / socket_client.c
Created January 19, 2018 01:34
A "hello world"-demo for Inter-Process Communication by the use of socket. Borrowed code from https://users.cs.cf.ac.uk/Dave.Marshall/C/node28.html.
/* borrowed from https://users.cs.cf.ac.uk/Dave.Marshall/C/node28.html */
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define NSTRS 3 /* no. of strings */