Skip to content

Instantly share code, notes, and snippets.

View wweic's full-sized avatar
😀
Hacking

Wei Chen wweic

😀
Hacking
View GitHub Profile
@wweic
wweic / progressbar.py
Created May 20, 2015 23:02
A smooth progress bar in terminal found online
# Abuse the power of unicode to give smooth progressbars in the terminal
#
# Unicode defines the codepoints 0x2588 up to 0x258F as SOLID BLOCK, LEFT SEVEN
# EIGHTS BLOCK etc.. This can be used for almost pixel-by-pixel painting of a
# progressbar. The Progressbar class does that for you and can also guess what
# width your progressbar should be.
#
# Usage:
# Progressbar(target=100, start=0, reserve=20, columns=None)
# - target is the final numerical goal of the progressbar
@wweic
wweic / rmq.py
Created October 10, 2015 23:37
generic block based rmq
def split(arr, size):
arrs = []
while len(arr) > size:
pice = arr[:size]
arrs.append(pice)
arr = arr[size:]
arrs.append(arr)
return arrs
class BFRMQ():
# zsh
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
@wweic
wweic / latency.txt
Created January 9, 2016 19:47 — 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
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms
Read 4K randomly from SSD* 150,000 ns 0.15 ms
ubuntu@ip-172-31-11-97:~$ cat run.sh
set -x
sudo rm -rf /var/www/data
VER=1
./local/bin/strace -ff -s 500 -o strace.out ./usr/bin/sourcexr ./sourcexr_config
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
class TrieNode {
public:
// Initialize your data structure here.
TrieNode(): end(false) {
fill_n(node, 26, nullptr);
#include <vector>
#include <unordered_map>
#include <queue>
using namespace std;
class Solution {
public:
vector<int> topKFrequent(vector<int>& nums, int k) {
vector<int> result;
class Solution {
public:
vector<int> intersection(vector<int>& nums1, vector<int>& nums2) {
sort(nums1.begin(), nums1.end());
sort(nums2.begin(), nums2.end());
int i1 = 0, i2 = 0;
vector<int> result;
while (i1 < nums1.size() && i2 < nums2.size()) {
if (nums1[i1] == nums2[i2]) {
type token = Bool of bool
| Number of int
| Identifier of string
| SemiColon
| LeftBracket
| RightBracket
| LeftParen
| RightParen
| KeywordIf
| KeywordThen
#include <thread>
int const NUM_THREADS = 5;
uint32_t counter[NUM_THREADS];
void driver(int threadId) {
for (int i = 0; i < 100000000; ++i) {
counter[threadId * 16]++;
}