Skip to content

Instantly share code, notes, and snippets.

View FabienArcellier's full-sized avatar

Fabien Arcellier FabienArcellier

View GitHub Profile
@FabienArcellier
FabienArcellier / list_carre.prolog
Created December 20, 2012 15:27
Apply squarred on every element in a list
carre(X, Result) :- Result is X * X.
list_carre([X], [XCarre]) :- carre(X, XCarre).
list_carre([X|R], [XCarre| Result1]):- lcarre(R, Result1), carre(X, XCarre).
@FabienArcellier
FabienArcellier / gpair.prolog
Created December 20, 2012 15:51
Extrait odd elements from a list
is_pair(X) :- Pair is X mod 2, Pair =:= 0.
is_impair(X) :- Impair is X mod 2, Impair =:= 1.
gpair([],[]).
gpair([T|R], [TP|RP]) :- is_pair(T), gpair(R, RP), TP = T.
gpair([T|R], L) :- is_impair(T), gpair(R, L).
@FabienArcellier
FabienArcellier / selec.prolog
Created December 20, 2012 16:01
Get 2 lists for odd and even elements of list
is_pair(X) :- 0 is X mod 2.
is_impair(X) :- not(is_pair(X)).
selec([], [], []).
selec([T|R], [TP|RP], LI) :- is_pair(T), selec(R, RP, LI), TP = T.
selec([T|R], LP, [TI|RI]) :- is_impair(T), selec(R, LP, RI), TI = T.
@FabienArcellier
FabienArcellier / graph_path.prolog
Created December 20, 2012 16:20
Resolve graph path using prolog
arc(b, a, 1).
arc(b, c, 3).
arc(a, d, 4).
arc(c, d, 5).
arc(d, e, 7).
arc(d, f, 6).
ch1(O, D, Longueur) :- arc(O, D, Longueur).
ch1(O, D, Longueur) :- arc(O, N, L0), ch1(N, D, L1), Longueur is L1 + L0.
@FabienArcellier
FabienArcellier / cstl.pl
Last active December 11, 2015 05:58
Build a new list which is the same than the list given as param and add 0 at the end
% Appel cstl([1,2,3], Y]) % -> Y=[1|[2|[3|[0]]]]
cstl([], Result):- Result = [0].
cstl([Y|L], Result):- cstl(L, Result1), Result = [Y| Result1].
@FabienArcellier
FabienArcellier / autoload.php
Last active December 11, 2015 07:19
A PSR-0 autoloader compatible
<?php
/**
* Autoload function for PHP. (Compatible PSR-0)
* Use automatic include base on directory
*/
function autoload($className)
{
$className = ltrim($className, '\\');
$fileName = '';
@FabienArcellier
FabienArcellier / hors_de.prolog
Created January 24, 2013 07:55
Operations sur les listes
hors_de(X,[Y]):- X\==Y.
hors_de(X,[Y|R]):- X\==Y, hors_de(X,R).
dedans(X,[X]).
dedans(X,[X|_]).
dedans(X,[_|L]):-dedans(X,L).
tous_dif([_]).
tous_dif([X|L]):- hors_de(X,L), tous_dif(L).
@FabienArcellier
FabienArcellier / tree.prolog
Created February 7, 2013 11:33
Insert a node in a binary tree
%planche 4
%
%Exercice 1
donnee(arbre1, nd(7,nd(5,nd(3,v,v),v), nd(18,nd(9, nd(8,v,v),v),nd(20,v,v)))).
donnee(arbre2, nd(3,v,nd(5,v,v))).
%inv(5,nd(3,v,v),Ar)
%donnee(arbre1, A), inv(12,A,Ar)).
%
@FabienArcellier
FabienArcellier / svn2git.bash
Last active December 15, 2015 15:49
This bash snippet is a script to migrate svn repository with a structure (trunk, branches and tags) to a new git repository. It take care of doing authors matching and remove the adress of old svn
#!/bin/bash
# This snippet suppose the file authors_list exists
# take a look at http://www.yterium.net/Migrer-un-projet-SVN-vers-GIT
if [[ "$1" == "" && "$2" == "" ]] ; then
echo "$1"
echo "$2"
echo "Arguments are invalid"
exit
fi
var MyCollection = Backbone.Collection.extend({
//custom methods
fetch: function(options) {
//do specific pre-processing
//Call Backbone's fetch
return Backbone.Collection.prototype.fetch.call(this, options);