Skip to content

Instantly share code, notes, and snippets.

@4u9u5tsong
4u9u5tsong / spacemacs-cheshe.md
Created October 28, 2018 18:59 — forked from robphoenix/spacemacs-cheshe.md
Spacemacs Cheat Sheet

Useful Spacemacs commands

  • SPC q q - quit
  • SPC w / - split window vertically
  • SPC w - - split window horizontally
  • SPC 1 - switch to window 1
  • SPC 2 - switch to window 2
  • SPC w c - delete current window
  • SPC TAB - switch to previous buffer
  • SPC b b - switch buffers
@4u9u5tsong
4u9u5tsong / latency.txt
Created November 12, 2016 17:01 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@4u9u5tsong
4u9u5tsong / gist:450d09c2973859446ae6
Created April 11, 2015 03:43 — forked from debasishg/gist:8172796
streaming algorithms
  1. General Background and Overview
@4u9u5tsong
4u9u5tsong / gist:93b4c5acece0ba99ab2d
Last active August 29, 2015 14:18
marss and dramsim

compile

  1. in DRAMSim2 folder: make libdramsim.so
  2. in Marss: scons dramsim=/full/path/to/DRAMSim2

flags

DRAMSim2/Makefile: comment -DLOG_OUTPUT for extra logs

@4u9u5tsong
4u9u5tsong / gist:c1b73d09f5215de7af3d
Created March 27, 2015 03:34
synergy over ssh tunnel
ssh -f -L 24800:127.0.0.1:24800 128.151.160.230 -N
@4u9u5tsong
4u9u5tsong / gist:ea8c81532fbec69accce
Last active August 29, 2015 14:17
python bit manipulation
def float64Tobinary(num):
return ''.join(bin(ord(c)).replace('0b', '').rjust(8, '0') for c in
struct.pack('!d', num))
def convertTo1DIntArray(d, start, end, patternwidth, f):
sview = 'S' + str(patternwidth)
return f(d[start:end]).view(sview)
@4u9u5tsong
4u9u5tsong / gist:8c5a355df430f63740bf
Created March 27, 2015 00:15
python scipy CSR format
# Got an answer from the Scipy user group:
# http://stackoverflow.com/questions/8955448/save-load-scipy-sparse-csr-matrix-in-portable-data-format
# A csr_matrix has 3 data attributes that matter: .data, .indices, and .indptr. All are simple ndarrays, so numpy.save will work on them. Save the three arrays with numpy.save or numpy.savez, load them back with numpy.load, and then recreate the sparse matrix object with:
# new_csr = csr_matrix((data, indices, indptr), shape=(M, N))
# So for example:
def save_sparse_csr(filename,array):
np.savez(filename,data = array.data ,indices=array.indices,
indptr =array.indptr, shape=array.shape )
@4u9u5tsong
4u9u5tsong / gist:447133da601b3486762f
Created March 24, 2015 18:26
genfromtxt read from a pipe with subprocess
inpstream = subprocess.check_output(cmdstr).split('\n')
data = sp.genfromtxt(inpstream, dtype=np.uint64)
@4u9u5tsong
4u9u5tsong / readdata.py
Created January 30, 2015 17:07
python read cvs file float64 to binary string
#!/usr/bin/env python
import struct
import scipy as sp
import numpy as np
def binary(num):
return ''.join(bin(ord(c)).replace('0b', '').rjust(8, '0') for c in struct.pack('!d', num))
@4u9u5tsong
4u9u5tsong / read numbers
Last active August 29, 2015 14:11
c++, read numbers, many lines, and different # in each line, remove redundant
ifstream pbinfile(argv[2]);
vector<unordered_set<int> > numbers;
while(getline(pbinfile, stemp)){
istringstream buffer(stemp);
vector<int> line((istream_iterator<int>(buffer)),
istream_iterator<int>());
unordered_set<int> s(line.begin(), line.end());
numbers.push_back(s);
}