Skip to content

Instantly share code, notes, and snippets.

@masak
masak / warnings.txt
Created February 14, 2014 11:13
Uninitializedness warnings in Configure.pl script in Rakudo
$ perl Configure.pl --backends=moar
Use of uninitialized value in concatenation (.) or string at Configure.pl line 247.
Use of uninitialized value in concatenation (.) or string at Configure.pl line 247.
Using /home/masak/ours/rakudo/install/bin/nqp-m (version / MoarVM ).
Use of uninitialized value $nqp_config{"moar::dll"} in sprintf at Configure.pl line 249.
Cleaning up ...
You can now use 'make' to build Rakudo.
After that, 'make test' will run some tests and
'make install' will install Rakudo.
@masak
masak / indent.p6
Last active August 29, 2015 13:57
Indent handling in Perl 6
constant TABSTOP = 4;
class Suite {
has @.items handles <push at_pos Numeric Bool>;
}
class X::Double::Indent::NotAllowed is Exception { }
class X::Partial::Indent is Exception { }
class X::Initial::Indent is Exception { }
@masak
masak / cps-kinda.p6
Created April 14, 2014 06:18
Simulating CPS in Perl 6 - code that can be paused and resumed in the middle
## Test
my $point_1_reached = False;
my $point_2_reached = False;
my $point_3_reached = False;
class Event1 {}
class Event2 {}
class Event3 {}
@masak
masak / problem.txt
Created April 17, 2014 19:38
Problem in NQP make-land
$ make && make test
/usr/bin/perl -MExtUtils::Command -e mkpath bin
javac -source 1.7 -cp 3rdparty/asm/asm-4.1.jar:3rdparty/asm/asm-tree-4.1.jar:3rdparty/jline/jline-1.0.jar:3rdparty/jna/jna.jar -g -d bin src/vm/jvm/runtime/org/perl6/nqp/io/*.java src/vm/jvm/runtime/org/perl6/nqp/jast2bc/*.java src/vm/jvm/runtime/org/perl6/nqp/runtime/*.java src/vm/jvm/runtime/org/perl6/nqp/sixmodel/*.java src/vm/jvm/runtime/org/perl6/nqp/sixmodel/reprs/*.java src/vm/jvm/runtime/org/perl6/nqp/tools/*.java
/usr/bin/perl tools/build/gen-jvm-properties.pl . 3rdparty/asm/asm-4.1.jar:3rdparty/asm/asm-tree-4.1.jar:3rdparty/jline/jline-1.0.jar:3rdparty/jna/jna.jar > jvmconfig.properties
/usr/bin/perl tools/build/gen-jvm-properties.pl /home/masak/ours/nqp/install 3rdparty/asm/asm-4.1.jar:3rdparty/asm/asm-tree-4.1.jar:3rdparty/jline/jline-1.0.jar:3rdparty/jna/jna.jar > bin/jvmconfig.properties
jar cf0 nqp-runtime.jar -C bin/ .
sh: 1: jar: not found
make: *** [nqp-runtime.jar] Error 127
@masak
masak / git-commit-branch
Created April 20, 2014 10:22
git-commit-branch
BRANCH="$1"
shift
git checkout $BRANCH
git commit "$*"
git checkout -
@masak
masak / find-palindromes.p6
Last active August 29, 2015 14:00
Python and Perl 6 are kinda similar :)
given open('words') -> $f {
LEAVE { $f.close }
for $f.lines -> $line {
next if $line.chars == 1;
if $line.flip eq $line {
say $line
}
}
}
@masak
masak / story.txt
Created May 24, 2014 18:54
A kind of proof of concept for stories
Story: writing a blog post
user selects "new blog post"
app goes to "new blog post" screen
screen stays active while the user edits it
{{DONE}}
user selects "publish post"
{{SAVE}}
app publishes post
@masak
masak / fridays.hs
Last active August 29, 2015 14:02
Find all Fridays-the-13th in the years 2012..2017
import Control.Monad
import Data.Time.Calendar
import Data.Time.Calendar.WeekDate
main = do
forM_ [2012..2017] $ \year -> do
forM_ [1..12] $ \month -> do
let date = fromGregorian year month 13
let (_, _, weekDay) = toWeekDate date
when (weekDay == 5) (putStrLn . showGregorian $ date)

I noticed that in these two years, no-one had gone ahead an written a Haskell version of the task. So I went ahead and did it. Code below.

I had to learn a bit about Haskell date and calendar handling, looping, monads, and comprehensions before succeeding. But RosettaCode and #haskell were both good sports.

I've optimized for clarity. The isFriday condition doesn't need to be pulled out into its own function, but I felt it helped readability a bit.

import Data.Time.Calendar
import Data.Time.Calendar.WeekDate

isFriday :: Day -> Bool

@masak
masak / git-edit-commit
Created June 11, 2014 11:51
A git-edit-commit subcommand
COMMIT="$1"
echo "${COMMIT:=HEAD}"
OLD_HEAD=`git rev-parse HEAD`
git reset --hard $COMMIT
git reset --mixed HEAD~
git commit --patch || (git reset --hard $OLD_HEAD && exit)
git checkout .
git rebase -X theirs $OLD_HEAD