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 / subset_sum.rs
Last active August 29, 2015 14:07
Subset sum problem solution in rust
fn can_sum<NumType: Num+PartialOrd, IterType: Iterator<NumType> + Clone>
(mut nums: IterType, total: NumType) -> bool {
let zero = std::num::Zero::zero();
if total == zero {return true;}
if total < zero {return false;}
match nums.next() {
None => total == zero,
Some(x) => {
can_sum(nums.clone(), total-x) || can_sum(nums,total)
}
@lovasoa
lovasoa / decision_tree.py
Last active August 29, 2015 14:08
Dirty python work on decision trees, for my math lesson
import math
def ent(l):
s = sum(l)
if s==0: return 0
res = sum(-k/s * math.log2(k/s) for k in l if k != 0)
return res
def columns(m):
for i,_ in enumerate(m[0]):
@lovasoa
lovasoa / lexique.sql
Last active December 3, 2016 00:13
Base de données Lexique au format SQL (SQLite). http://www.lexique.org/
This file has been truncated, but you can view the full file.
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE lexique(ortho varchar, phon varchar, lemme varchar, cgram varchar, genre char, nombre char, freqlemfilms float, freqlemlivres float, freqfilms float, freqlivres float, infover varchar, nbhomogr integer, nbhomoph integer, islem boolean, nblettres integer, nbphons integer, cvcv varchar, p_cvcv varchar, voisorth integer, voisphon integer, puorth integer, puphon integer, syll varchar, nbsyll integer, cv_cv varchar, orthrenv varchar, phonrenv varchar, orthosyll varchar);
INSERT INTO "lexique" VALUES('a','a','a','NOM','m','',81.36,58.65,81.36,58.65,'',3,8,1,1,1,'V','V',25,18,1,1,'a',1,'V','a','a','a');
INSERT INTO "lexique" VALUES('a','a','avoir','AUX','','',18559.22,12800.81,6350.91,2926.69,'ind:pre:3s','',3,8,0,1,'1','V','V',25,18,1,'1','a','1','V','a','a');
INSERT INTO "lexique" VALUES('a','a','avoir','VER','','',13572.4,6426.49,5498.34,1669.39,'ind:pre:3s','',3,8,0,1,'1','V','V',25,18,1,'1','a','1','V','a','a');
INSERT INTO "lexique" VALUES('a capella','a
@lovasoa
lovasoa / AutoCompletionInput.js
Last active August 29, 2015 14:11
React auto-completion component
var AutoCompletionInput = React.createClass({
getInitialState: function() {
return {completion:'',prevText:''};
},
getCompletion : function(txt){
if (txt.length === 0|| this.state.prevText.length>=txt.length) return '';
var finder = function(x){return x.startsWith(txt)}.bind(this);
var repl = this.props.completionValues.find(finder);
if (!repl) return '';
else return repl.substring(txt.length);
@lovasoa
lovasoa / ph.cf
Last active August 29, 2015 14:14
LBNF Grammar for process hitting models http://loicpauleve.name/pint/doc/syntax.html
comment "(*" "*)" ;
Prog. Program ::= [HeaderElem] [BodyElem] [FooterElem] ;
DefaultRate. HeaderElem ::= "directive" "default_rate" Number;
Stochasticity. HeaderElem ::= "directive" "stochasticity_absorption" Integer;
Sample. HeaderElem ::= "directive" "sample" Number;
separator HeaderElem "";
InitState. FooterElem ::= "initial_state" [Process];
@lovasoa
lovasoa / processHitting.ph2
Last active August 29, 2015 14:15
New syntax for the description of process hitting
(*
New syntax, easier to read and to parse
Process definitions are optional (they can be inferred)
condition : bounce (params)
where
condition is a set of basic_conditions bound by "and" and "or" operators.
basic_condition can be of type (sortname comparisonOerator processNumber) or (sortname) which is a shortcut for (sortname>0)
@lovasoa
lovasoa / asep.js
Created February 21, 2015 01:24
Cooperativity-driven singularities in asymmetric exclusion (probabilistic version)
var lambda = .5;
var p = new Array(10);
for(var i=0; i<p.length;i++) p[i]=0;
p[2]=1;
var niter = 3;
for (var k=0;k<niter;k++){
@lovasoa
lovasoa / q3.js
Created February 27, 2015 14:26
ARSYS
var MAX = 3;
var a=0, b=0, n=0, p=0;
var ncorr = 0, pred=0;
var histpred = {};
var hist = [false,false,false,false];
for (var i=0; i<24; i++) {
a = (a+1)%2;
@lovasoa
lovasoa / shell.c
Created March 4, 2015 16:51
My first shell
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/wait.h>
#define MAXS (255)
int main(void) {
@lovasoa
lovasoa / ARSYS-robot-ophir.c
Created March 18, 2015 14:59
Killer robot
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <pthread.h>
#define NPROC (10)
int procnums[NPROC];
enum mode_t {VULNERABLE, PROT1, PROT2};