Skip to content

Instantly share code, notes, and snippets.

Jarrell Waggoner malloc47

View GitHub Profile
@malloc47
malloc47 / man-flesch
Created Oct 25, 2011
Flesch–Kincaid Index For *nix Man Pages
View man-flesch
# 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'
@malloc47
malloc47 / ls_d.cpp
Created Oct 30, 2011
listing files with posix C calls
View ls_d.cpp
// 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 / git-chop
Created Feb 5, 2012
Git Chopping and Cropping
View git-chop
#!/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 / gist:1742772
Created Feb 5, 2012
find all git repositories and print info about them
View gist:1742772
# 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 / embedly.py
Created Feb 11, 2012
embedly challenge
View embedly.py
# 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
View ladder1.cog
symbols
surface downsect
message activated
thing ghosttel1
thing ghosttel2
thing player local
surface upsuf1
end
@malloc47
malloc47 / convert.sh
Created Feb 18, 2012
create page of +1s
View convert.sh
#!/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 / command line
Created Apr 7, 2012 — forked from paraboul/command line
JavaScript + C Preprocessor
View command line
/usr/bin/cpp -P -undef -Wundef -std=c99 -nostdinc -Wtrigraphs -fdollars-in-identifiers -C < foo.js
@malloc47
malloc47 / mixin.sh
Created Apr 7, 2012
mixin script that works as a "preprocessor"
View mixin.sh
#!/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
View numpy_to_latex.py
def to_latex(a,label='A \\oplus B'):
sys.stdout.write('\[ '
+ label
+ ' = \\left| \\begin{array}{'
+ ('c'*a.shape[1])
+ '}\n' )
for r in a:
sys.stdout.write(str(r[0]))
for c in r[1:]:
sys.stdout.write(' & '+str(c))
You can’t perform that action at this time.