Skip to content

Instantly share code, notes, and snippets.

@nicmart
nicmart / current
Last active December 11, 2015 16:08
I have to choose the more elegant interface for selectors for the treebuilder library. Here I post some alternatives to se how they look like.
<?php
// Current interface
$tree
->leaf('element', 'author')
->key('value', 'author_name')
->value('element', 'name')
->end()
->leaf('element', 'date')
->value(function(\DateTime $dateTime) { return $dateTime->format('d-m-Y'); })
[user]
name = Nicolò Martini
email = electroportal.net@gmail.com
[github]
user = nicmart
token = xxxx
[core]
excludesfile = /Users/nic/.gitignore_global
[difftool "sourcetree"]
cmd = opendiff \"$LOCAL\" \"$REMOTE\"
@nicmart
nicmart / mediawiki-globals-1.20.php
Created March 8, 2013 15:20
Mediawiki 1.20 globals. Wrapping mediawiki code into a symfony application forced me to explicitly declare all global variables (more than 800!). This is the file I include for that declarations.
<?php
/*
* This file lists all global variables found in Medawiki 1.20
*
* (c) 2013 Nicolò Martini <nicmartnic@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
@nicmart
nicmart / lesscdir
Last active December 16, 2015 01:09 — forked from gbonanome/lesscdir
#!/bin/bash
# file name: lesscdir
# Compile every .less found under a specified folder
# $1 is the folder to search
# $2 allows to use a lessc parameters for compiling
if [[ -z $1 ]];then
echo 'Specify a directory to search'
exit
@nicmart
nicmart / gist:94aa30f10c42ca47f004
Created May 9, 2014 10:55
Extension client page test
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>HTML5 basic skeleton</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style type="text/css">
@nicmart
nicmart / README.md
Last active August 29, 2015 14:21
StatementBuilder

StatementBuilder

This library was born to improve the abstraction in the conversion of an Expression to a SQL statement, but it is completely Expression and SQL agnostic, so it can be used for simlar use-cases.

The problem

Let's say you have a type FieldConverter that converts a FieldExpression object to a prepared statement. That is basically a function type

FieldConverter: FieldExpression => PreparedStatement

For the sake of the argument, let's assume that PreparedStatement is just a string with placeholders, without the PDO values bindings.

<?php
/**
* This file is part of BehatIntro
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @author Nicolò Martini <nicmartnic@gmail.com>
*/
@nicmart
nicmart / SubsetEnumerator.php
Last active February 9, 2016 16:41
Enumerate all the subsets of a set of a given size
<?php
/**
* @author Nicolò Martini - <nicolo@martini.io>
*
* Created on 05/02/2016, 19:52
*/
namespace NicMart;
/**
@nicmart
nicmart / partitions.scala
Created March 20, 2017 16:45
Partitions
def partitions(n: Int): List[List[Int]] = partitionsGreaterThan(n, 1)
def partitionsGreaterThan(n: Int, m: Int): List[List[Int]] = n match {
case _ if m > n => List()
case _ if m == n => List(List(n))
case _ if m < n =>
val ns1 = partitionsGreaterThan(n - m, m).map { m :: _ }
val ns2 = partitionsGreaterThan(n, m + 1)
ns1 ::: ns2
}
@nicmart
nicmart / symantics.scala
Created December 19, 2017 22:43
Experiments with a tagless final encoding for the simply typed lambda-calculus, following section 3 of the paper "Typed Tagless Final Interpreters" by Oleg Kiselyov
import scala.language.higherKinds
trait Symantics[F[_,_]] {
def int[E](n: Int): F[E, Int]
def add[E](n: F[E, Int], m: F[E, Int]): F[E, Int]
def z[E, T]: F[(T, E), T]
def s[E, T, A](f: F[E, T]): F[(A, E), T]
def lam[E, A, B](f: F[(A, E), B]): F[E, A => B]
def app[E, A, B](f: F[E, A => B], a: F[E, A]): F[E, B]
}