Skip to content

Instantly share code, notes, and snippets.

@malloc47
malloc47 / mixin.sh
Created April 7, 2012 01:35
mixin script that works as a "preprocessor"
#!/bin/bash
num=$(grep -n \# $1 | awk -F: '{print $1}')
file=$(grep -n \# $1 | awk -F: '{print $2}' | awk '{print $2}')
if [ -n "$num" ] ; then
sed "${num}d" $1 > $2
sed -i "${num} a
" $2
sed -i "${num}r $file" $2
@malloc47
malloc47 / convert.sh
Created February 18, 2012 03:37
create page of +1s
#!/bin/sh
echo "<html><head>" > page.html
echo "<script type=\"text/javascript\" src=\"https://apis.google.com/js/plusone.js\"></script>" >> page.html
echo "</head><body>" >> page.html
grep -o http[^\"\)\']* $1 | xargs -I{} echo "<g:plusone href=\"{}\"></g:plusone>" >> page.html
echo "</body></html>" >> page.html
@malloc47
malloc47 / ladder1.cog
Created February 16, 2012 05:01
COG Example
symbols
surface downsect
message activated
thing ghosttel1
thing ghosttel2
thing player local
surface upsuf1
end
@malloc47
malloc47 / embedly.py
Created February 11, 2012 04:38
embedly challenge
# Problem 1
fact = lambda n: reduce(lambda x,y: x*y, range(1, n+1), 1)
convert = lambda n: sum(map(int,str(n)))
def p1gen():
i = 0
while True:
yield (i,convert(fact(i)))
i+=1
@malloc47
malloc47 / gist:1742772
Created February 5, 2012 04:41
find all git repositories and print info about them
# requires git alias
# s = status -s -uno
for i in `find ~/ -type d -name .git` ; do echo $i ; builtin cd $i/../ ; git s ; builtin cd ~/ ; done
@malloc47
malloc47 / git-chop
Created February 5, 2012 02:40
Git Chopping and Cropping
#!/bin/bash
# remove a file or directory
set -e
EXPECTED_ARGS=1
E_BADARGS=65
if [ $# -lt $EXPECTED_ARGS ]
then
echo "Usage: `basename $0` [directory]"
exit $E_BADARGS
fi
@malloc47
malloc47 / ls_d.cpp
Created October 30, 2011 01:21
listing files with posix C calls
// Lists directories in the given path
list_t ls_d(string path) {
list_t output;
DIR* dirp = opendir(path.c_str());
struct dirent *file;
if(dirp==NULL)
return list_t();
while ((file = readdir(dirp)) != NULL) {
string name(file->d_name);
if(!name.compare(".") || !name.compare("..")) continue;
@malloc47
malloc47 / man-flesch
Created October 25, 2011 02:44
Flesch–Kincaid Index For *nix Man Pages
# prepossess: remove newlines, add newlines after end of sentences, trim whitespace, and remove short lines
man /usr/share/man/man1/git.1.gz | tr '\n' ' ' | sed 's/\./\.\n/g' | sed -e 's/^[ \t]*//' | sed '/.\{3\}/!d'