This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
DB=~/.pomodoro.db | |
if [ ! -f $DB ]; then | |
sqlite3 $DB "CREATE TABLE timerecord ( record_time text, duration text);" | |
fi | |
# Count down $1 number of seconds | |
countdown() { | |
start="$(( $(date +%s) + $1))" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <unistd.h> | |
#include <fcntl.h> | |
#include <elf.h> | |
#include <errno.h> | |
#include <sys/types.h> | |
#include <sys/stat.h> | |
#include <sys/stat.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
## Study Pratt parsing for python3 | |
## Ref: http://effbot.org/zone/simple-top-down-parsing.htm | |
import re | |
token_pattern = re.compile(r"\s*(?:(\d+)|(\*\*|.))\s*") | |
def tokenize(program): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <stdarg.h> | |
#include <string.h> | |
#include <ctype.h> | |
#include <stdbool.h> | |
/* clang -Wall -W -g -std=c11 -Wno-missing-field-initializers -pedantic calc.c -o calc */ | |
typedef enum { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# remap prefix from 'C-b' to 'C-a' | |
unbind C-b | |
set-option -g prefix C-o | |
bind-key C-o send-prefix | |
# split panes using | and - | |
bind | split-window -h | |
bind - split-window -v | |
unbind '"' | |
unbind % |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Compile: g++ sparse.cpp | |
* Run: ./a.out | |
* | |
* Test code: | |
* | |
* <tag1><tag11>aa</tag11><tag12>bb</tag12></tag><tag21>cc</tag21> | |
* <tag><tag1>fdfdf</tag1></tag> | |
* <tag><tag1>fdfdf<tag3>fdf</tag3></tag1></tag> | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* Write a function last : 'a list -> 'a option that returns the last element of a list. *) | |
let rec last l = match l with | |
[] -> None | |
| [x] -> Some x | |
| x :: l -> last l | |
(* Find the last but one (last and penultimate) elements of a list. *) | |
let rec last_two l = match l with | |
[] -> None | |
| [x] -> None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
class StringRep { | |
friend class String; | |
private: | |
StringRep() { *(rep = new char[1]) = '\0'; } | |
~StringRep() { delete[] rep; } | |
StringRep(const StringRep& s) { ::strcpy((rep = new char[::strlen(s.rep)+1]), s.rep); } | |
StringRep& operator=(const StringRep& s) { | |
if (rep != s.rep) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Given a list (for instance [1,2,3]), return its powerset (a set of subsets) | |
-- Combinatorics guys: well a subset is a set with/without the first element | |
-- Hoola! | |
-- powerset [1,2,3] = [[],[3],[2],[2,3],[1],[1,3],[1,2],[1,2,3]] | |
powerset :: [a] -> [[a]] | |
powerset [] = [[]] | |
powerset (x:xs) = let ss = subset xs in ss ++ (map (\ys -> x:ys) ss) | |
-- Monad guys: after a few minutes thinking |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
SSD random read 150,000 ns | |
Read 1 MB sequentially from memory 250,000 ns 0.25 ms | |
Round trip within same datacenter 500,000 ns 0.5 ms |
NewerOlder