Skip to content

Instantly share code, notes, and snippets.

#!/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 / 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/env perl
use v5.14;
use mop;
class Foo {
has $!sentence is ro;
method new($class: @words) {
$class->next::method(words => \@words);
#!/usr/bin/env perl
use v5.14;
use mop;
use Data::Printer;
class Foo {
has $!foo is ro;
method new($class: $foo) {
;; 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))
@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";
@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 / rename-lost-files-2.hs
Created April 17, 2014 04:25
rename files in git lost-found directory - v2
-- 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 / rename-lost-files-3.hs
Created April 21, 2014 20:46
rename lost files - v3
-- 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.Environment
import System.Directory
import Text.Regex.Posix
import Control.Monad (forM_)
@prakashk
prakashk / gist:e464478b2697c5ef2eaa
Last active August 29, 2015 14:01
Implementation of few haskell builtins
-- https://questhub.io/realm/haskell/quest/537bb4e2bbd0bed61d00007d
head :: [a] -> a
head [] = error "head: empty list"
head (x:xs) = x
tail :: [a] -> [a]
tail [] = error "tail: empty list"
tail (x:xs) = xs