Skip to content

Instantly share code, notes, and snippets.

View ap's full-sized avatar

Aristotle Pagaltzis ap

View GitHub Profile
@ap
ap / license
Created January 27, 2010 11:22 — forked from defunkt/license
#!/bin/bash
# Usage: license [fullname]
# Prints an MIT license appropriate for totin' around.
#
# $ license > COPYING
# $ license 'Joe Random' > COPYING
#!/bin/sh
FULLNAME=${1:-$(getent passwd $(id -u) | cut -d: -f5 | cut -d, -f1)}
cat << "."
Copyright (c) `date +%Y` $FULLNAME
use 5.006;
use strict;
use Irssi;
our $VERSION = '0.1';
our %IRSSI = (
authors => 'Nanuq',
contact => 'n/a',
name => 'quotepass',
description => q"gets around Undernet's silly /QUOTE PASS nonsense",
\ cf.:
\ Algorithm: http://en.wikipedia.org/wiki/Exponentiation_by_squaring
\ Other examples: http://canonical.org/~kragen/sw/inexorable-misc/exponent.fs
variable the-exp
: do-exp ( x -- x^the-exp )
>r
the-exp @ 0= if rdrop 1 exit then
use List::Util 'reduce';
sub pascal {
my ( $x, @p, @q ) = shift;
push @p, reduce { push @p, $a + $b; $b } 1, @q = @p, @p = () for 1 .. $x - 1;
1, @p;
}
@ap
ap / sudowrite.vim
Created October 12, 2010 20:58
:Sudo command that saves files using sudo(1)
" defines a :Sudo command that works largely like :w
" but uses `sudo` to the file using root permissions
function! SudoWrite(file,line1,line2)
" intercept the external file change reload prompt event
autocmd FileChangedShell <buffer> :
" shazzam
exe 'silent' a:line1 . ',' . a:line2 . 'write !sudo tee 1>/dev/null' strlen(a:file) ? a:file : '%'
" force-trigger vim's file modification check, then undo the intercept
checktime | autocmd! FileChangedShell <buffer>
@ap
ap / gist:624446
Created October 13, 2010 17:00
Git goodies: a grab bag
# you need this
alias gg='git grep -E'
# highlighted diff goodness is not just for git repos any more
alias diff='git diff --no-index'
# qf=quickfix
git config --global alias.qf 'commit --amend -C HEAD'
# Git Is My Refactoring IDE: edit all files that contain a particular pattern
@ap
ap / README.md
Last active September 24, 2015 08:27
By request: my current .bashrc
@ap
ap / I18N_STEFFENW.en.pod
Last active January 13, 2023 11:35
Selecting an Internationalization Framework (GPW10)

Selecting an Internationalization Framework

Author

Steffen Winkler [email protected]

Bio

@ap
ap / app.psgi
Created July 4, 2011 19:34
Missing Plack body filter feature?
#!perl
use Plack::Builder;
builder {
enable sub {
my $app = shift;
sub {
my $env = shift;
Plack::Util::response_cb( $app->( $env ), sub {
my @out = ( 'a' .. 'z' );
sub { shift @out }
@ap
ap / gist:2919035
Created June 12, 2012 17:58
List CPAN distributions of an author that have Debian packages
#!/usr/bin/env perl
use 5.014;
use strict;
use warnings;
use HTTP::Tiny ();
use JSON 'decode_json';
sub get_dists_for_author {
my ( $author ) = @_;
my $url = sprintf 'http://api.metacpan.org/v0/release/_search?q=author:%s+AND+status:latest;fields=name;size=200', $author;