Skip to content

Instantly share code, notes, and snippets.

The "right-left" rule is a completely regular rule for deciphering C
declarations. It can also be useful in creating them.
First, symbols. Read
* as "pointer to" - always on the left side
[] as "array of" - always on the right side
() as "function returning" - always on the right side
as you encounter them in the declaration.
@c00kiemon5ter
c00kiemon5ter / pipes
Created April 22, 2012 15:14
fill your terminal with colored pipes/tubes
#!/bin/bash -e
declare -i f=75 s=13 r=5000 t=0 c=1 n=0 l=0
declare -i x=$((w/2)) y=$((h/2))
declare -ar v=( [00]="\x83" [01]="\x8f" [03]="\x93"
[10]="\x9b" [11]="\x81" [12]="\x93"
[21]="\x97" [22]="\x83" [23]="\x9b"
[30]="\x97" [32]="\x8f" [33]="\x81"
)
trap "clear; tput rmcup; tput cnorm" EXIT
@c00kiemon5ter
c00kiemon5ter / Makefile
Created April 9, 2012 14:17
mparser - a simple parser for monsterwm's output
# Makefile for mparser - see UNLICENSE for nonlicense and noncopyright information
VERSION = cookies-git
NAME = mparser
PREFIX ?= /usr/local
BINDIR ?= ${PREFIX}/bin
INCS = -I. -I/usr/include
LIBS = -L/usr/lib -lc
@c00kiemon5ter
c00kiemon5ter / Answers.csv
Created March 13, 2012 16:17
convert csv formated data to json
We can't make this file beautiful and searchable because it's too large.
AQCod,AAA,ALect,ACorr,ASound
1,1,"Περνάτε στην 3η ταχύτητα.",1,"SA-1-1"
1,2,"Περνάτε στην 5η ταχύτητα.",0,"SA-1-2"
2,1,"Εννέα και τέταρτο ως δέκα και δέκα.",1,"SA-2-1"
2,2,"Εννέα.",0,"SA-2-2"
2,3,"Έντεκα και πέντε.",0,"SA-2-3"
3,1,"Έχετε «βάλει» την 1η ταχύτητα και πιέζετε τον ποδομοχλό του συμπλέκτη.",0,"SA-3-1"
3,2,"Έχετε το μοχλό ταχυτήτων στη «νεκρά» και πιέζετε τον ποδομοχλό της πέδης (φρένο).",1,"SA-3-2"
3,3,"Έχετε το μοχλό ταχυτήτων στη «νεκρά» και πιέζετε τον ποδομοχλό του συμπλέκτη.",0,"SA-3-3"
4,1,"Μόνο όταν έχετε πρόθεση να αλλάξετε κατεύθυνση προς τα αριστερά.",0,"SA-4-1"
@c00kiemon5ter
c00kiemon5ter / monsterwm2bar
Created February 25, 2012 02:40
monsterwm output to dzen2 or some_sorta_bar
ff="/tmp/monsterwm.fifo"
[[ -p $ff ]] || mkfifo -m 600 "$ff"
# desktop names
ds=("web" "dev" "foo" "null")
# layout names
ms=("T" "M" "B" "G" "F")
while read -t 60 -r wmout || true; do
@c00kiemon5ter
c00kiemon5ter / abs_no_branch.c
Created February 23, 2012 01:53
absolute function in c that does not branch
// branching function:
// inline int abs(int x)
// {
// return (x<0) ? -x : x;
// }
inline int abs_no_branch(int x)
{
int m = (x >> (8 * sizeof(int)-1));
return ((x ^ m) - m);
@c00kiemon5ter
c00kiemon5ter / arrows.diff
Created February 22, 2012 22:04
use arrow keys to navigate images in meh
diff --git a/src/xlib.c b/src/xlib.c
index 393617d..9940eb3 100644
--- a/src/xlib.c
+++ b/src/xlib.c
@@ -201,9 +201,13 @@ void handlekeypress(XEvent *event){
key_action();
break;
case XK_j:
+ case XK_l:
+ case XK_Right:
@c00kiemon5ter
c00kiemon5ter / pcp
Created February 11, 2012 01:21
cp wrapper with a progressbar
#!/bin/bash
current=0
completed=0
read -r total _ < <(/bin/du -bc "${@:1:${#}-1}" | tail -n1)
/bin/cp $@ &
while (( current != total )); do
@c00kiemon5ter
c00kiemon5ter / findnosymlinkedfiles.sh
Created December 7, 2011 00:54
find no symlinked files
#!/bin/sh
localdir="/tmp/test" # which directory to check
filelist="/tmp/filelist" # where to store regular file names
symlist="/tmp/symlist" # where to store symlinks file names
results="/tmp/results" # where to store file names that have no symlink pointed to them
cd "$localdir"
# seperate files and symlinks
@c00kiemon5ter
c00kiemon5ter / updateIP.sh
Created November 20, 2011 01:45
update your dynamic IP, for freedns.afraid.org; place under cron
#!/bin/sh
cacheip="/etc/ip.cache"
checkurl='http://freedns.afraid.org/dynamic/check.php'
updateurl='http://freedns.afraid.org/dynamic/update.php?xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
[ -r "${cacheip}" ] && read -r _date _time _oldip <<< "$(tail -1 "${cacheip}")"
_newip="$(wget "$checkurl" -o /dev/null -O /dev/stdout | sed -n 's/^Detected.*: \(.\+\)/\1/p')"
[ "${_newip}" == "${_oldip}" ] && printf "IP has not changed: %s\n" "${_newip}" && exit 0