Skip to content

Instantly share code, notes, and snippets.

View ltriant's full-sized avatar
🪐
floating

Luke Triantafyllidis ltriant

🪐
floating
View GitHub Profile
@ltriant
ltriant / xmas.erl
Last active December 17, 2015 22:43
-module(xmas).
-export([tree/1]).
tree(Width, _, _) when Width < 3 orelse Width > 21 ->
error( { out_of_range, { min, 3 }, { max, 21 }, { input, Width } } );
tree(Width, _, _) when Width rem 2 == 0 ->
error( { width_is_not_odd, Width } );
tree(Width, Trunk, Leaves) ->
lists:foreach(
fun (A) ->
#!/usr/bin/env perl
use warnings;
use strict;
use Mojo::UserAgent;
die "usage: cpanver <module>\n" unless @ARGV;
my ($module) = @ARGV;
@ltriant
ltriant / mx.psgi
Last active October 2, 2017 06:39
Promises-based non-blocking Plack/PSGI app
#!/usr/bin/env perl
# mx.psgi -- get geographic information about a domain's mailservers
# This was written purely as an example real-world-ish non-blocking
# Plack/PSGI application because I'm sick of seeing the usual
# "Hello World"-esque examples.
# In one shell:
# $ feersum --listen :5000 -a mx.psgi
#
#!/usr/bin/env perl
use v5.10;
use warnings;
use strict;
use EV;
use AnyEvent;
use Sys::Hostname qw(hostname);
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int main(void)
{
pid_t pid = fork();
#!/usr/bin/env perl
use v5.10;
use warnings;
use strict;
use EV;
use AnyEvent;
# XXX comment this out, and it works
#!/usr/bin/env perl
use v5.10;
use warnings;
use strict;
use EV;
use AnyEvent;
use POSIX qw();
@ltriant
ltriant / Dockerfile
Created April 23, 2019 23:12
MD5 as a Service
FROM perl:5.28
RUN curl -L http://cpanmin.us | perl - App::cpanminus
RUN cpanm Carton
COPY app.psgi /app/app.psgi
COPY cpanfile /app/cpanfile
COPY cpanfile.snapshot /app/cpanfile.snapshot
RUN cd /app && carton install --deployment
@ltriant
ltriant / life.c
Last active October 15, 2019 00:29
Conway's Game of Life
/*
* Conway's Game of Life
*
* Press any key to re-initialise :)
* Click the window to exit.
*
* gcc -std=c99 -lsdl2 -Wall -Werror -Wpedantic -Wno-unused-function -o life life.c
*/
#include <stdio.h>
@ltriant
ltriant / life.zig
Last active April 8, 2021 02:10
Conway's Game of Life in Zig
// Conway's Game of Life
//
// Initialises the canvas randomly
//
// zig run life.zig -isystem /usr/local/include --library sdl2
const std = @import("std");
const os = std.os;
const warn = std.debug.warn;
const c = @cImport({