Skip to content

Instantly share code, notes, and snippets.

View ap's full-sized avatar

Aristotle Pagaltzis ap

View GitHub Profile
@ap
ap / gist:152462
Created July 23, 2009 04:27
My first Haskell code
-- http://thedailywtf.com/Articles/Programming-Praxis-Russian-Peasant-Multiplication.aspx
foldl1 (+) . map (snd) . filter (odd . fst) . takeWhile ((0 <) . fst) $ iterate (\(x,y) -> (x`div`2, y*2)) (18,23)
" DELIMITERS MADE LESS ANNOYING
"
" Main novelty here (if it is one): this does NOT try to be helpful by
" inserting the closing delimiter for you when you type an opening one.
" Instead it only tries to be smart about what to do when you type a closing
" delimiter yourself.
"
" If you just typed an empty delimiter pair, it'll move the cursor back
" inside. If you type a closing delimiter the cursor is already on (or to
" the left of, if the cursor is on a space), it'll skip the cursor past that
@ap
ap / gcd.sh
Created May 28, 2009 14:26
shell func for cd'ing to top of git working copy
# these implementations both take special care to keep `cd -` working correctly
# good way
gcd() {
local TOP="`git rev-parse --show-cdup 2> /dev/null`" || return 1
[ "$TOP" ] && cd "$TOP"
}
# old, dumb, bad way
gcd() {
%s![^\x00-\xff]!\= '&#' . char2nr(submatch(0)) . ';' !g
@ap
ap / gist:94251
Created April 13, 2009 04:10
Broken dvipdft fix (failed trying to mkdir tempdir that it had already created)
--- /usr/share/texmf/bin/dvipdft 2007-06-28 04:50:14.000000000 +0200
+++ dvipdft 2009-04-13 06:13:05.000000000 +0200
@@ -31,7 +31,14 @@
$progname --help
$progname --version"
-tmpdir=`mktemp -d ${TMP-/tmp}/$progname.XXXXXX`
+# before we create the tmpdir, set trap for cleanup
+trap 'rm -rf $tmpdir ; exit 1' 1 2 3 7 13 15
+trap 'rm -rf $tmpdir' 0
@ap
ap / httpd-cgit.conf
Created March 31, 2009 12:22
cgit clean URLs Apache config
# cgit setup for Apache that results in completely clean URLs, ie.
# visiting http://git.example.org/ will produce the cgit index page
<VirtualHost *>
# this part is stand fare
ServerName git.example.org
DocumentRoot /var/www/htdocs/cgit/
<Directory "/var/www/htdocs/cgit/">
AllowOverride None
Options ExecCGI
Order allow,deny
@ap
ap / gist:66108
Created February 18, 2009 00:41
Polyglot Makefile (embedding a Perl script)
# polyglot Makefile (embedding a Perl script)
output.txt: input.txt Makefile
perl -x Makefile $< > $@
#!/usr/bin/perl
q-ignore:
-;
use strict;
# rest of Perl script;
@ap
ap / gist:61242
Created February 10, 2009 04:57
Answers to Tom Duff's stylistic conundrums presented in “Reading Code From Top to Bottom”, http://www.iq0.com/notes/deep.nesting.html
/* answers to Tom Duff's stylistic conundrums presented in
[Reading Code From Top to Bottom]
(http://www.iq0.com/notes/deep.nesting.html)
*/
char *skip(char *s, int c) {
char cc;
for(;;) {
if(!*s) break;
cc = *s++;
@ap
ap / termtitle.sh
Created December 31, 2008 07:58
Set terminal title then run a command
#!/bin/bash
TITLE="$1"
shift
printf '\e]0;%s\007' "$TITLE"
"$@"
@ap
ap / proxy.pac.js
Created December 14, 2008 14:20
Efficient ad blocking via proxy autoconfig
/* the network your computer is on, and the subnet mask of that network */
var local_network = '192.168.1.0';
var local_netmask = '255.255.255.0';
/* the host and port of your regular proxy, if any; otherwise an empty string */
var upstreamProxy = '';
/* space-separated list of hosts or domains that should always be connected to directly without using a proxy */
var directZones = 'plasmasturm.org delicious.com paulgraham.com yahoo.com';