This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
sub gen(&) { | |
use Coro; | |
my $fun = shift; | |
my $arg = new Coro::Channel; | |
my $out = new Coro::Channel; | |
my $yield = sub(@) { | |
$out->put([@_]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// klg, 2013. WTFPL 2. | |
(function($) { | |
$.fn.eoime = function() { | |
return this.each(function(next, element, table) { | |
function replace(len, str, p, s) { | |
p = element.selectionStart; | |
s = element.value; | |
element.value = s.substr(0, p - len) + str + s.substr(p); | |
element.setSelectionRange(p -= len - 1, p); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
# reshape: A ⍴ B → rho [A], B | |
sub rho($@) { | |
my $s = 1; | |
my @shape = @{+shift}; | |
'ravel' while $#_+1 < (@_ = map { ref eq 'ARRAY' ? @$_ : $_ } @_); | |
$s *= $_ for @shape; | |
@_ = @_[0 .. $s-1]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# fadeout.sh length [pid]... | |
# Slowly lower the volume along the half sine slope then kill | |
# some processes and restore original volume at the end. | |
# Requires sleepenh and amixer. | |
# klg, Jun 2013 | |
CTL=PCM | |
LEN=${1:-0} | |
shift |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use Tk; | |
my $E = MainWindow->new->Entry->pack; | |
$E->bind('<Key-Return>', sub { | |
my $e = shift; | |
my $v = $e->get; | |
$e->delete(0, length $v); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# check if string looks like a valid pubkey hash address for main Bitcoin network | |
# klg, Aug 2013 | |
package Base58Check; | |
use strict; | |
use bytes; | |
use Carp; | |
use Digest::SHA 'sha256'; | |
use Math::BigInt; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Small Promise with implicit state compatible with Promises/A+. | |
// klg, Sep 2013, WTFPL 2. | |
(function() { | |
"use strict"; | |
/** | |
* Create new Promise using given function to schedule resolution | |
* of the Promise. Continuations that respectively fulfill and | |
* reject the Promise are passed to the setup function. | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Run mcabber with dedicated gpg-agent with preset passphrase | |
# klg, Sep 2013 | |
KEYGRP=AB91925C3C10DB24EDCDB821A294A4F0248DE9A1 | |
gpg_agent=gpg-agent | |
gpg_connect_agent=gpg-connect-agent | |
gpg_preset_passphrase=/usr/lib/x86_64-linux-gnu/gnupg2/gpg-preset-passphrase | |
pinentry=pinentry |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# Encrypt the penguin with AES-ECB. I/O in PPM (P6) format. | |
# klg, Oct 2013 | |
use strict; | |
use bytes; | |
use Crypt::Rijndael; | |
my $src = do { local $/; <> }; | |
my $key = pack 'H*', '6b6c67323031332cecceab7fffe4391d'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function X = impeval(X, fun, varargin) | |
%IMPEVAL Evaluate point-wise transformation of multichannel image. | |
% | |
% function X = impeval(X, fun, ...) | |
% | |
% Given multidimensional matrix and a function, impeval calls the | |
% function with vectors along the last dimension of the matrix | |
% rearranged into columns of 2-D matrix as function's first argument. | |
% The function must return a matrix with the same number of columns | |
% which is then rearranged back into the shape of the original matrix |