Skip to content

Instantly share code, notes, and snippets.

View ap's full-sized avatar

Aristotle Pagaltzis ap

View GitHub Profile
\ 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 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",
@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
#!/usr/bin/perl
use 5.010;
use strict;
use warnings;
no warnings qw( once qw );
use Parse::Perl qw( current_environment parse_perl );
use PadWalker qw( peek_my peek_sub );
use Devel::LexAlias qw( lexalias );
my $empty_env = current_environment;
@ap
ap / html2markdown.xslt
Last active August 26, 2020 08:35
HTML to Markdown in (E)XSLT
<xsl:stylesheet version="1.0"
xmlns:h="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fn="http://exslt.org/functions"
xmlns:str="http://exslt.org/strings"
xmlns:my="urn:my:"
extension-element-prefixes="fn str my"
>
<xsl:output method="text" encoding="utf-8" />
use 5.010;
use strict;
use SQL::Beautify;
my $sql = do { local $/; <> };
$_ = do {
my $p = SQL::Beautify->new;
$p->query( $sql );
$p->beautify;
#!/usr/bin/perl
# original by towo <[email protected]> under CC-BY
use strict;
use File::Basename qw( basename );
use File::Spec::Functions qw( catfile );
use Scalar::Utils qw( openhandle );
my %monthnum = qw(
Jan 01 Feb 02 Mar 03

Storing/Retrieving from the File System

Some projects (the Git project itself for example) store additional files directly in the Git file system without them necessarily being a checked in file.

Let’s start off by storing a random file in Git:

$ echo "Foo" | git hash-object -w --stdin
51fc03a9bb365fae74fd2bf66517b30bf48020cb

At this point the object is in the database, but if you don’t set something up to point to that object it will be garbage collected. The easiest way is to tag it:

@ap
ap / Apple_KB_and_Initrd_Notes.mkd
Created November 6, 2009 01:25
Apple mini aluminium keyboard in Linux and Initrd Notes

Apple mini aluminium keyboard in Linux and Initrd Notes

Problem: The Fn key on my Apple mini aluminium keyboard (wired) doesn’t work in Linux.

Solution, according to long Google research: the hid-apple and usbhid modules in recent kernel versions list the combination of properties of this keyboard so the kernel can support it properly.

Problem: I don’t want to recompile my entire kernel.

Solution: In the case of usbhid, Ryan Finnie points out that the driver accepts keyboard properties configuration with an option, so I don’t need to recompile anything in the first place:

Both of these sed programs transform lines containing binary addition expressions of the form

1+1111111111111

to the respective value of the expression, again in binary.

The easiest way to invoke them in shell is using here strings, like so:

./bin_add.sed <<< 1+1111111111111

./bin_add_fast.sed <<< 1+1111111111111