Skip to content

Instantly share code, notes, and snippets.

View soren's full-sized avatar

Søren Lund soren

View GitHub Profile
#!/bin/env perl
use warnings;
use strict;
my $line = "one,two, three, four , five ";
sub print_list {
printf "[%s]\n", join(', ', @_);
}
@soren
soren / pwdcomposer.user.js
Created October 10, 2014 09:01
Password Composer 2.04
/* vim: ts=4 noet ai :
$Id: pwdcomposer.user.js 79 2006-09-08 07:44:01Z joe $
CREDITS
=======
Inspired by Nick Wolff's bookmarklet "Generate Password"
http://angel.net/~nic/passwdlet.html
MD5 hash functions (c) Paul Johnston
@soren
soren / colorize.pl
Created October 1, 2014 07:57
Simple Perl script that adds colors to e.g. log files using ANSI escape codes
#!/usr/bin/env perl
=head1 NAME
colorize.pl - adds colors to e.g. log files using ANSI escape codes
=head1 SYNOPSIS
colorize.pl LOGFILE
some_command | colorize.pl
@soren
soren / utf8.el
Created September 24, 2014 13:47
Getting UTF-8 to work in GNU/Emacs
(prefer-coding-system 'utf-8)
(set-default-coding-systems 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
(setq default-buffer-file-coding-system 'utf-8)
(if (eq window-system 'x)
(setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING)))
(if (eq system-type 'windows-nt)
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
// There's more than one way to do it
public class StaticInitialization {
private static final Map<String, String> MAP_ONE = new HashMap<String, String>() {{
put("one", "1. first");
}};
@soren
soren / AltMouseWindowMove.ahk
Created December 30, 2013 08:40
Move Windows by holding Alt and clicking (and holding) the left mouse button anywhere in the window.
; Move Windows by holding Alt and clicking (and holding) the left mouse button anywhere in the window.
; You'll need http://www.autohotkey.com to use this script
LAlt & LButton::
CoordMode, Mouse ; Switch to screen/absolute coordinates.
MouseGetPos, EWD_MouseStartX, EWD_MouseStartY, EWD_MouseWin
WinGetPos, EWD_OriginalPosX, EWD_OriginalPosY,,, ahk_id %EWD_MouseWin%
WinGet, EWD_WinState, MinMax, ahk_id %EWD_MouseWin%
if EWD_WinState = 0 ; Only if the window isn't maximized
SetTimer, EWD_WatchMouse, 10 ; Track the mouse as the user drags it.
@soren
soren / wc2_reducer.pl
Last active December 29, 2015 02:19
A Hadoop Word Count example implemented in Perl using Hadoop::Streaming. Tested with Java 1.6 and Hadoop 1.0.4.
#!/usr/bin/perl -I./lib.jar
use My::Hadoop::WordCount;
My::Hadoop::WordCount::Reducer->run();
@soren
soren / wc2_mapper.pl
Created November 22, 2013 13:49
A Hadoop Word Count example implemented in Perl using Hadoop::Streaming. Tested with Java 1.6 and Hadoop 1.0.4.
#!/usr/bin/perl -I./lib.jar
use My::Hadoop::WordCount;
My::Hadoop::WordCount::Mapper->run();
@soren
soren / WordCount.pm
Last active December 29, 2015 01:49
A Hadoop Word Count example implemented in Perl using Hadoop::Streaming. Tested with Java 1.6 and Hadoop 1.0.4.
package My::Hadoop::WordCount;
use Any::Moose qw(Role);
sub map {
my ($self, $line) = @_;
$self->emit(lc $_ => 1) foreach split /[\s.,:;!?]+/, $line;
}
sub reduce {
@soren
soren / wc_reducer.pl
Created November 22, 2013 07:42
A Perl Word Count reducer script. Can be used as a reducer in Hadoop using the Streaming interface. Tested with Java 1.6 and Hadoop 1.0.4.
#!/usr/bin/env perl
use warnings;
use strict;
my $current_word = "";
my $current_count = 0;
while (<>) {
chomp;