Skip to content

Instantly share code, notes, and snippets.

@jiafulow
jiafulow / rfc1925.txt
Last active April 12, 2021 18:00
The Twelve Networking Truths
The Twelve Networking Truths
(1) It Has To Work.
(2) No matter how hard you push and no matter what the priority,
you can't increase the speed of light.
(2a) (corollary). No matter how hard you try, you can't make a
baby in much less than 9 months. Trying to speed this up
*might* make it slower, but it won't make it happen any
@jiafulow
jiafulow / unix.md
Created June 18, 2019 16:05
Basics of the Unix Philosophy from 'The Art of Unix Programming" by Eric Steven Raymond

Basics of the Unix Philosophy

source: https://homepage.cs.uri.edu/~thenry/resources/unix_art/ch01s06.html

  1. Rule of Modularity: Write simple parts connected by clean interfaces.
  2. Rule of Clarity: Clarity is better than cleverness.
  3. Rule of Composition: Design programs to be connected to other programs.
  4. Rule of Separation: Separate policy from mechanism; separate interfaces from engines.
  5. Rule of Simplicity: Design for simplicity; add complexity only where you must.
  6. Rule of Parsimony: Write a big program only when it is clear by demonstration that nothing else will do.
@jiafulow
jiafulow / gray.cc
Created October 25, 2017 17:56
C++ Gray code
//
// Code from "Numerical Recipe in C (2nd edition)" by Press et al.
// Chapter 20.2 pg.896
//
#include <cstdint>
#include <iostream>
// Return the Gray code of n
uint64_t gray(uint64_t n)
CXX=clang++
CXXFLAGS=-g -std=c++11 -Wall -pedantic
BIN=prog
SRC=$(wildcard *.cpp)
OBJ=$(SRC:%.cpp=%.o)
# $^ is all the dependencies
# $? is all the modified dependencies
all: $(OBJ)
@jiafulow
jiafulow / ROOT tutorial #3
Last active April 7, 2016 03:41
Clone a TTree and modify the values stored in selected branches #askROOT
Download the C codes and run the following commands:
$ alias rot='root -l -b -q'
$ rot create_tree.C+
$ rot clone_tree.C+
Tested in ROOT 6.06/00
#include "TStyle.h"
// tdrGrid: Turns the grid lines on (true) or off (false)
//void tdrGrid(bool gridOn) {
// tdrStyle->SetPadGridX(gridOn);
// tdrStyle->SetPadGridY(gridOn);
//}
// fixOverlay: Redraws the axis
@jiafulow
jiafulow / ROOT tutorial #2
Last active April 7, 2016 03:36
Create a TTree filled with double, vector<double>, and vector<vector<double> > #askROOT
Download the C codes and run the following commands:
$ alias rot='root -l -b -q'
$ rot create_vector_vars.C+
$ rot read_vector_vars.C+
Tested in ROOT 6.06/00
@jiafulow
jiafulow / ROOT tutorial #1
Last active April 7, 2016 03:36
Create a TFile with TTrees, then update the TFile with more TTrees #askROOT
Download the C codes and run the following commands:
$ alias rot='root -l -b -q'
$ rot create_trees.C+
$ rot update_trees.C+
Tested in ROOT 6.06/00
@jiafulow
jiafulow / gfm2html.py
Last active August 29, 2015 13:57
gfm2html.py
#!/usr/bin/env python
import sys
import urllib2
import json
# To learn GitHub Flavored Markdown, see
# http://guides.github.com/overviews/mastering-markdown
gh_url = 'https://api.github.com/markdown'