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 / README.md
Last active January 21, 2021 19:56
Compute the intersection of large arrays in javascript

WARNING : This code now lives in its own github repository: lovasoa/fast_array_intersect. It is also published on npm: fast_array_intersect

Array intersect

Fastest function to intersect a large number of big arrays in javascript, without dependencies

  • The compressed version is only 345 caracters long.
  • Faster than common libraries, even a large number of arrays, or on very big arrays. (See benchmarks)
@lovasoa
lovasoa / README.md
Created September 1, 2012 09:22
Télécharger les mp3 et les pochettes des albums Danakil qui sont disponibles en streaming sur leur site danakil.fr, et ajouter les tags en ID3

Téléchagement des mp3 de danakil (avec les pochettes)

Dépendances

* Python 2 * mutagen (bibliothèque pour la gestion des tags audio en python)

Utilisation

sur une debian-like (Ubuntu par exemple):
@lovasoa
lovasoa / c_random.js
Last active December 17, 2015 06:08
Javascript implementation of C stdlib random() function (the spec specifies no algorithm, the one of the GNU GLIBC is used). For a description of the algorithm, see: http://www.mathstat.dal.ca/~selinger/random/. I just realised that I was not logged in when I created the gist, so it's also available as an anonymous gist.
function Random(seed) {
/*JS implementation of GNU C stdlib random() algorithm described here:
http://www.mathstat.dal.ca/~selinger/random/
*/
/*Usage :
r = new Random(1);
r.random();
this will generate the same sequence of pseudo-random numbers as C stdlib's random().
*/
@lovasoa
lovasoa / README.md
Last active December 17, 2015 10:39
This little utility allows me to test an API (kind of fuzzing it). Starting from a json request that I know is working, it reduces it (by removing properties) until the json object isn't a valid API call anymore.

inputReducer.js

Description

This little utility allows me to test an API (kind of fuzzing it). Starting from a big json request that I know is working, it reduces it (by removing properties) until the json object isn't a valid API call anymore.

How to use

reduceInput(
	bigWorkingObj,
	function(semiReduced, callback){
@lovasoa
lovasoa / wabcamquizz.html
Last active December 18, 2015 01:29
HTML5 webcam quizz
<!DOCTYPE html>
<head>
<meta charset="utf8" />
<title>Webcam Quizz</title>
<style>
#webcam, #pict {
height:100px;
}
#answers > span {
border : 1px solid black;
@lovasoa
lovasoa / basic_lcs.js
Last active December 19, 2015 23:58
Longest common subsequence This is what I code while reading http://en.wikipedia.org/wiki/Longest_common_subsequence_problem
//Without memoization. This can be very slow
function basic_lcs_count (x, y) {
function rec(i,j){
if (i===0||j===0) return 0;
if (x[i-1]===y[j-1]) return rec(i-1,j-1)+1;
else return Math.max(rec(i,j-1),rec(i-1,j));
}
return rec(x.length,y.length);
}
@lovasoa
lovasoa / sequence.c
Last active December 20, 2015 12:59
sqrt(2) ≃ mean(2 1 1 2 1 2 1 1 2 1 2 1 1 2 1 2 1 2 1 1 2 1 2 1 1 2 1 2 1 2 1 1 2 1 2 1 1 2 1 2 1 1 2 1 2 1 2 1 1 2 1 2 1 1 2 1 2 1 2 1 1 2 1 2 1 1 2 1 2 1 1 2 1 2 1 2 1 1 2 1 2 1 1 2 1 2 1 2 1 1 2 1 2 1 1 2 1 2 1 2 1 1 2 1 2 1 1 2 1 2 1 1 2 1 2 1 2 1 1 2 1 2 1 1 2 1 2 1 2 1 1 2 1 2 1 1 2 1 2 1 1 2 1 2 1 2 1 1 2 1 2 1 1 2 1 2 1 2 1 1 2 1 2 1 1 2 …
#include <stdio.h>
//See http://oeis.org/A001030
unsigned int maxdepth, nbrtermes;
unsigned int recur(char num, unsigned int depth) {
if (depth>=maxdepth) {
nbrtermes++;
return (unsigned int)num;
}
@lovasoa
lovasoa / minitpl.js
Last active December 21, 2015 21:19
MiniTPL is a tiny templating library in javascript. MiniTPL is really small: less than 300 bytes when minified and gzipped!
/*
MiniTPL, by Ophir LOJKINE
license : WTFPL
*/
// ==ClosureCompiler==
// @output_file_name minitpl.min.js
// @compilation_level ADVANCED_OPTIMIZATIONS
// ==/ClosureCompiler==
@lovasoa
lovasoa / longest-increasing-subsequence.py
Last active October 1, 2020 19:58
Solution to the longest increasing subsequence problem, in 5 lines of python
def lis(a):
L = []
for (k,v) in enumerate(a):
L.append(max([L[i] for (i,n) in enumerate(a[:k]) if n<v] or [[]], key=len) + [v])
return max(L, key=len)
inp = [int(a) for a in input("List of integers: ").split(' ')]
print(lis(inp));
@lovasoa
lovasoa / canvas color picker.html
Last active February 28, 2024 19:53
JS color picker: HTML5 & javascript color picker that uses HTML5 canvas. User can choose hue and value, saturation is set to 1. It has color history management.
<!doctype html>
<html>
<head>
<meta charset="utf8" />
<title>Canvascolor</title>
<style>
body {
background-image:url(http://github.com/favicon.ico); /*Just for fun*/
}
main {