Skip to content

Instantly share code, notes, and snippets.

\def\reftextcurrent {}
\newrefformat{fig}{Fig.~\ref{#1}\vpageref{#1}}
\newrefformat{par}{Section~\ref{#1}\vpageref{#1}}
\newrefformat{sec}{Section~\ref{#1}\vpageref{#1}}
\newrefformat{sub}{Section~\ref{#1}\vpageref{#1}}
\newrefformat{table}{Table~\ref{#1}\vpageref{#1}}
\newrefformat{alg}{Algorithm~\ref{#1}\vpageref{#1}}
\newrefformat{chap}{Chapter~\ref{#1}}
\newrefformat{eq}{equation~\eqref{#1}}
\begin{tikzpicture}
\coordinate (root) {}
child[level distance=8em, sibling distance=8em] {
node (A) {$X$}
edge from parent node[left] {$0.1$}
}
child[level distance=4em] {
coordinate {}
child {
node {$Y$}
@ehamberg
ehamberg / trie.hs
Created July 30, 2011 13:58
Simple string → value trie
import Control.Arrow
data Trie a = Trie (Maybe a) [(Char, Trie a)] deriving Show
find :: Trie a -> String -> Maybe a
find (Trie v _) [] = v
find (Trie v ts) (c:cs) = case lookup c ts of
Just t -> find t cs
Nothing -> Nothing
import qualified Data.HashMap.Lazy as M -- from unordered-containers
firstNonRep :: String -> Char
firstNonRep =
head . M.keys . M.filter (==1) . M.fromListWith (+) . map (\c -> (c,1))
main = print $ firstNonRep "aabcbcdeef" == 'd'
@ehamberg
ehamberg / trigraph.c
Created August 24, 2011 08:21
C craziness
// gcc --std=c99 trigraph.c -o test && ./test
#include <stdio.h>
int main(int argc, const char *argv[])
{
int x = 1;
// what is going on here??/
x = 0;
@ehamberg
ehamberg / highlight_functions.vim
Created August 25, 2011 09:11
Highlight Function names in Vim
" Highlight Function names. From
" http://stackoverflow.com/questions/736701/class-function-names-highlighting-in-vim/773392#773392
syn match cCustomParen "(" contains=cParen contains=cCppParen
syn match cCustomFunc "\w\+\s*(" contains=cCustomParen
hi def link cCustomFunc Function
hi Function term=bold gui=bold
@ehamberg
ehamberg / markdown.vim
Created September 4, 2011 13:56
Vim: Syntax highlighting for in-line code in gitit markdown
" from http://vim.wikia.com/wiki/VimTip857
function! TextEnableCodeSnip(filetype, start, end, textSnipHl)
let ft=toupper(a:filetype)
let group='textGroup'.ft
if exists('b:current_syntax')
let s:current_syntax=b:current_syntax
" Remove current syntax definition, as some syntax files (e.g. cpp.vim)
" do nothing if b:current_syntax is defined.
unlet b:current_syntax
endif
@ehamberg
ehamberg / dynpath.bash
Created September 6, 2011 09:29
Automatically shortened path for use in bash prompts
#returns current path, but shortens it if it's longer than $COLUMNS/4, so that
# /usr/share/doc/foo would become /u…/s…/d…/foo
# Usage: PS1="\u@\h \$(_dynpath) \$ "
_dynpath()
{
CURR="${PWD/#$HOME/~}"
MAX_WIDTH=$(($COLUMNS/4))
while [[ ${#CURR} -gt $MAX_WIDTH && $CURR =~ /.[^…].*/ ]] ; do
@ehamberg
ehamberg / create-symlinks
Created September 10, 2011 10:47
Symlink dotfiles
@ehamberg
ehamberg / scatterv.c
Last active January 17, 2024 00:55
MPI_Scatterv example
#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define SIZE 4
int main(int argc, char *argv[])
{
int rank, size; // for storing this process' rank, and the number of processes