Skip to content

Instantly share code, notes, and snippets.

View lovasoa's full-sized avatar
🎯
Focusing

Ophir LOJKINE lovasoa

🎯
Focusing
View GitHub Profile
@lovasoa
lovasoa / simplificateur.hs
Created March 21, 2015 16:33
Simplificateur d'équations booléennes
type ProcNum = Int
type Sort = String
data Op = And | Or deriving (Show,Eq)
data Ex = Proc Sort ProcNum | BoolOp Op Ex Ex | Not Ex
instance Show Ex where
show (BoolOp op a b) = "("++show a++" "++show op++" "++show b++")"
show (Proc name n) = name++show n
show (Not e) = '!':show e
@lovasoa
lovasoa / Sk.lp
Last active August 29, 2015 14:17
Holà muchachos y muchachas, si esta la solutiones del ecercicos de es matinos.
#const n=5.
#const k=3.
num(1..n).
ens(1..k).
1{dans(N,E) : ens(E)}1 :- num(N).
:- dans(N,E), dans(M,E), dans(M+N,E).
#show dans/2.
@lovasoa
lovasoa / solveur_simple.cpp
Created March 26, 2015 16:26
Solveur d'équations booléennes en C++
#include <vector>
#include <string>
using namespace std;
class Proc {
public:
string name;
int num;
Proc(string nm, int n) : name(nm), num(n) {};
@lovasoa
lovasoa / join.rs
Created July 2, 2015 22:40
join vector of strings in rust
fn join<S:ToString> (l: Vec<S>, sep: &str) -> String{
l.iter().fold("".to_string(),
|a,b| if a.len()>0 {a+sep} else {a} + &b.to_string()
)
}
@lovasoa
lovasoa / primes.rs
Created July 2, 2015 23:05
compute prime numbers in Rust
struct Primes {
primes : Vec<u64>,
}
impl Primes {
fn new() -> Primes {
Primes{primes: vec![2]}
}
fn test(&self, totest: u64) -> bool {
let mut n = totest;
struct Primes {
primes : Vec<u64>,
}
impl Primes {
fn new() -> Primes {
Primes{primes: vec![2]}
}
fn test(&self, totest: u64) -> bool {
let mut n = totest;
@lovasoa
lovasoa / lambert2GPS.php
Created July 10, 2015 13:57
Conversion de coordonnées du format lambert vers WGS84 (GPS)
<?php
function lambert2gps($x, $y, $lambert) {
$lamberts = array(
"LambertI" => 0,
"LambertII" => 1,
"LambertIII" => 2,
"LamberIV" => 3,
"LambertIIExtend" => 4,
"Lambert93" => 5
);
@lovasoa
lovasoa / graham_scan.es6
Last active July 29, 2016 23:52
Graham scan
function graham_scan(points) {
const pivot = points.reduce((c, p) =>
p.y < c.y || p.y===c.y && p.x<c.x ? p : c);
const sorted = points
.map(p=>({x:p.x,y:p.y,angle:Math.atan2(p.y-pivot.y,p.x-pivot.x)}))
.sort((a,b) => a.angle === b.angle ? a.x - b.x : a.angle - b.angle);
function cross_p (a,b,c) {return (b.x-a.x)*(c.y-a.y) <= (b.y-a.y)*(c.x-a.x);}
var result = [sorted[0], sorted[1]], top = 1;
for(var i=2; i<sorted.length; i++){
while (top >= 1 && cross_p(result[top-1], result[top], sorted[i])) top--;
@lovasoa
lovasoa / zif.es6
Last active March 28, 2016 07:18
ZIF (Zoomify Image File) format parser
/**
* THIS CODE IS OUT OF DATE
* SEE: https://github.com/lovasoa/ZIF/
**/
class ZIF {
constructor(file) {
this.file = file;
this.head = this.parseHead(); // A promise for the header
}
@lovasoa
lovasoa / csv-fill-template.py
Created August 5, 2015 11:33
Fill a template with values from a csv file
#!/usr/bin/env python3
"""Use a csv file to fill a template"""
import sys
import csv
from string import Template
def csvfill(csvfile, template, outfilepattern):
t = Template(template)
fnametpl = Template(outfilepattern)
r = csv.DictReader(csvfile)