Skip to content

Instantly share code, notes, and snippets.

@c00kiemon5ter
c00kiemon5ter / math.problem.mkdn
Created June 29, 2011 13:31
where is your God now ?

initial condition

a = b

* a

a2 = ab

+ a2 - 2ab

a2 + a2 - 2ab = ab + a2 - 2ab

grouping

@c00kiemon5ter
c00kiemon5ter / sp.c
Created July 25, 2011 00:21
swap files
#include <stdio.h>
#include <stdlib.h>
enum errors {
EARGNUM = 1, /* wrong number of arguments */
ETMPFAIL, /* creating temporary file failed */
ERNMFAIL /* rename failed */
};
/* rename the given files */
@c00kiemon5ter
c00kiemon5ter / deploy-post-commit-hook
Created November 20, 2011 01:39
generate site from master branch src; update gh-pages; on post-commit.
#!/usr/bin/env bash
# executables prefix
_prefix="/usr/bin"
# git executable
_git="$_prefix/git"
# site generation executable
_generate="$_prefix/jekyll"
# options for the generator
@c00kiemon5ter
c00kiemon5ter / addline
Created November 20, 2011 01:40
add a line to a file, on the first comment
#!/usr/bin/env bash
newline="$1"
filein="$2"
fileout="$3"
counter=0
while read -r; do
((counter++))
if ! [[ $REPLY =~ ^# ]]; then
@c00kiemon5ter
c00kiemon5ter / gitrenameauthor.sh
Created November 20, 2011 01:44
look through commits and replace old committer or author name with a new one
#!/bin/sh
git filter-branch -f --env-filter '
an="$GIT_AUTHOR_NAME"
am="$GIT_AUTHOR_EMAIL"
cn="$GIT_COMMITTER_NAME"
cm="$GIT_COMMITTER_EMAIL"
if [ "$GIT_COMMITTER_EMAIL" = "old mail" ]
@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
@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 / 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 / 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 / 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);