Skip to content

Instantly share code, notes, and snippets.

@prakashk
prakashk / rename-lost-files.hs
Last active August 29, 2015 13:59
rename files in git lost-found directory
-- rename Project Euler files in git lost-found directory
-- get the file type and the problem number from the initial comments
-- in each file
import System.Directory
import Text.Regex.Posix
import Control.Monad (forM_)
lostFilesDir = ".git/lost-found/other"
@prakashk
prakashk / nocase-file-matches.pl
Last active December 29, 2015 13:59
Print file names matching the given argument (exactly, no wild-cards) while ignoring case
#!/usr/bin/env perl
## look for files in case-insensitive manner
use strict;
use warnings;
use feature 'say';
use File::Glob ":glob";
my $filename = shift or die "Missing filename";
;; set font interactively
;; from https://news.ycombinator.com/item?id=6773670
(defun set-font (font-family height)
(interactive "sFont family: \nnHeight: ")
(set-face-attribute 'default nil :family font-family :height height)
(set-fontset-font "fontset-default" 'unicode font-family))
#!/usr/bin/env perl
use v5.14;
use mop;
use Data::Printer;
class Foo {
has $!foo is ro;
method new($class: $foo) {
#!/usr/bin/env perl
use v5.14;
use mop;
class Foo {
has $!sentence is ro;
method new($class: @words) {
$class->next::method(words => \@words);
@prakashk
prakashk / bigfloat-vs-pari.pl
Created September 12, 2013 16:27
Math::BigFloat vs Math::Pari
#!/usr/bin/env perl
use Benchmark qw/:all :hireswallclock/;
use Math::BigFloat;
use Math::Pari;
my $count = shift || 10_000;
my $pressure_bf = Math::BigFloat->new(1011.4598);
my $pressure_pari = Math::Pari::PARI(1011.4598);
#!/usr/bin/perl
use feature qw{ say state };
use strict;
use warnings;
use Benchmark qw{:all};
use Carp;
my $str = "state declares a lexically scoped variable, just like my. However, those variables will never be reinitialized, contrary to lexical variables that are reinitialized each time their enclosing block is entered.";
my $len = length($str);
@prakashk
prakashk / 032-package-w-extends.t
Created August 1, 2013 21:06
Creating an instance of a class extended from another in the same package fails.
#!perl
use strict;
use warnings;
use Test::More;
{
package Foo;
(defun copy-comment-paste ()
"copy active region/current line, comment, and then paste"
(interactive)
(unless (use-region-p)
(progn
(beginning-of-line 2)
(push-mark (line-beginning-position 0))))
(kill-ring-save (region-beginning) (region-end))
(comment-region (region-beginning) (region-end))
(yank)
@prakashk
prakashk / moe.sh
Created February 5, 2013 05:36
run moe from command-line
scala -classpath target/scala-2.10/classes:$HOME/.ivy2/cache/commons-cli/commons-cli/jars/commons-cli-1.2.jar:$HOME/.ivy2/cache/jline/jline/jars/jline-2.10.jar org.moe.Moe