Skip to content

Instantly share code, notes, and snippets.

View lucabrunox's full-sized avatar

Luca Bruno lucabrunox

View GitHub Profile
@lucabrunox
lucabrunox / http_header_parse.php
Created October 14, 2013 15:19
Parse HTTP headers in PHP.
$header = "...";
$parsed = array_map(function($x) { return array_map("trim", explode(":", $x, 2)); },array_filter(array_map("trim", explode("\n", $header))));
public delegate G TaskFunc<G> () throws Error;
public async G run_in_thread<G> (owned TaskFunc<G> func) throws Error {
SourceFunc resume = run_in_thread.callback;
Error err = null;
G result = null;
new Thread<void*> (null, () => {
try {
result = func ();
} catch (Error e) {
@lucabrunox
lucabrunox / aabb_alloc.mod
Last active August 29, 2015 13:55
Optimal 2d AABB allocation
# See http://lethalman.blogspot.it/2014/01/intersection-test-and-optimal.html
# Run as glpsol --tmlim 5 -m alloc.mod
param cols integer >= 0;
param rows integer >= 0;
param n integer >= 1;
param w{1..n} integer >= 1 <= cols;
param M := cols+rows;
param C := 1/(2*n*rows);
[Test (name = "/foo")]
public void foo () {
message ("foo");
}
[Test (name = "/bar")]
public void bar () {
message ("bar");
}
function isalpha(c) {
return (((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')));
}
function isdigit(c) {
return ((c >= '0') && (c <= '9'));
}
function isalnum(c) {
return (isalpha(c) || isdigit(c));
@lucabrunox
lucabrunox / nagios-module.nix
Created June 19, 2014 08:09
Nginx, Nagios, NixOS
services.nagios4.cgiConfigFile = pkgs.writeText "nagios.cgi.conf" ''
main_config_file=${cfg.mainConfigFile}
use_authentication=1
url_html_path=${cfg.urlPath}
authorized_for_system_information=lethalman
authorized_for_system_commands=lethalman
authorized_for_configuration_information=lethalman
authorized_for_all_hosts=lethalman
authorized_for_all_host_commands=lethalman
authorized_for_all_services=lethalman
with import <nixpkgs> {};
{
inherit (e18) efl evas emotion elementary enlightenment terminology econnman;
}
@lucabrunox
lucabrunox / tested.nix
Last active August 29, 2015 14:05
Lethal hydra
{ nixpkgs }:
let
combined = import "${nixpkgs}/nixos/release-combined.nix" { inherit nixpkgs; supportedSystems = [ "x86_64-linux" ]; };
nixos = combined.nixos;
peek = x: x.x86_64-linux;
in
{
simple = peek nixos.tests.simple;
gnome3 = peek nixos.tests.gnome3;
@lucabrunox
lucabrunox / autotools.nix
Last active December 19, 2018 02:38
Nix pill 10
pkgs: attrs:
with pkgs;
let defaultAttrs = {
builder = "${bash}/bin/bash";
args = [ ./builder.sh ];
setup = ./setup.sh;
baseInputs = [ gnutar gzip gnumake gcc binutils coreutils gawk gnused gnugrep patchelf findutils ];
buildInputs = [];
system = builtins.currentSystem;
};
{ nixpkgs }:
let
combined = import "${nixpkgs}/nixos/release-combined.nix" { inherit nixpkgs; supportedSystems = [ "x86_64-linux" ]; };
tests = combined.nixos.tests;
peek = x: x.x86_64-linux;
in
{
simple = peek tests.simple;
openssh = peek tests.openssh;