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 / csv_to_sqlite.py
Created January 24, 2014 02:24
Import csv file in a SQLite database
#!/usr/bin/python3
import sqlite3,sys,os.path
if len(sys.argv) != 3:
print ("Usage:\n\t%s db_file csv_data_file" % (sys.argv[0],))
exit(1)
datatypes = (int, float, lambda s:s.strip(" \n\t\"'"))
@lovasoa
lovasoa / create_stop_route_link_table.sql
Last active May 12, 2021 19:39
GTFS: Select stops with associated routes (works on a database build from gtfs files, one table per file) https://developers.google.com/transit/gtfs/reference)
@lovasoa
lovasoa / SRTmove.md
Last active January 4, 2016 13:59
SRTmove: shift all subtitles from an srt file, in order to make them appear earlier or later.

SRTmove

Compilation

g++ -o srtmove srtmove.cpp

This small programm uses no library.

@lovasoa
lovasoa / srtmove.html
Last active January 4, 2016 15:49
SRTmove-js: move subtitles without having to upload them
<!doctype html>
<html>
<head>
<meta charset="utf8" />
<title>SRTmove</title>
<style>
html {
background-color:black;
}
@lovasoa
lovasoa / levenshtein.js
Last active June 9, 2022 14:24
levenshtein’s distance implementation in python and javascript, with very detailed comments in the python version (in french)
function levenshtein(w1, w2, costs) {
var line_i = [];
if (costs === undefined) costs = [1,1,1]; //Cost of addition, deletion, replacement
for(var k=0; k<=w1.length; k++) line_i.push(k);
for (var i=1; i<=w2.length; i++) {
var prev_line = line_i;
var line_i = [i];
for (var k=1; k<=w1.length; k++) {
cost = (w1[k-1] == w2[i-1]) ? 0 : costs[2];
line_i[k] = Math.min(line_i[k-1]+costs[0], prev_line[k]+costs[1], prev_line[k-1]+cost);
@lovasoa
lovasoa / doublons.py
Last active January 4, 2016 20:48
Detect similar file names in a folder and its subfolders. Created to detect duplicate films in a messy folder.
#!/usr/bin/env python3
#coding: utf8
########################
### doublons.py ###
### By Ophir LOJKINE ###
### LICENSE : LGPLv3 ###
########################
import re, os, sys, mimetypes, unicodedata, threading
@lovasoa
lovasoa / node-walk.es6
Last active March 11, 2025 15:15
Walk through a directory recursively in node.js.
// ES6 version using asynchronous iterators, compatible with node v10.0+
const fs = require("fs");
const path = require("path");
async function* walk(dir) {
for await (const d of await fs.promises.opendir(dir)) {
const entry = path.join(dir, d.name);
if (d.isDirectory()) yield* walk(entry);
else if (d.isFile()) yield entry;
@lovasoa
lovasoa / mimetypes.json
Created January 29, 2014 16:29
Apache list of all mimetypes, in json
{"wvx": "video/x-ms-wvx", "susp": "application/vnd.sus-calendar", "tmo": "application/vnd.tmobile-livetv", "m2v": "video/mpeg", "plf": "application/vnd.pocketlearn", "der": "application/x-x509-ca-cert", "plb": "application/vnd.3gpp.pic-bw-large", "plc": "application/vnd.mobius.plc", "ttc": "application/x-font-ttf", "car": "application/vnd.curl.car", "onepkg": "application/onenote", "def": "text/plain", "vcard": "text/vcard", "sus": "application/vnd.sus-calendar", "iif": "application/vnd.shana.informed.interchange", "deb": "application/x-debian-package", "m2a": "audio/mpeg", "pls": "application/pls+xml", "cgm": "image/cgm", "rdz": "application/vnd.data-vision.rdz", "ttf": "application/x-font-ttf", "ecma": "application/ecmascript", "uu": "text/x-uuencode", "meta4": "application/metalink4+xml", "roa": "application/rpki-roa", "cww": "application/prs.cww", "rdf": "application/rdf+xml", "igl": "application/vnd.igloader", "clp": "application/x-msclip", "dvb": "video/vnd.dvb.file", "sub": "text/vnd.dvb.subtitle", "ig
@lovasoa
lovasoa / filldata.js
Last active August 29, 2015 13:56
Automatic form fill, random form fill, and all kind of nice things with forms. Can be used for mass user account generation on a web site, for instance.
exports.url = "http://test.com"; //URL of the first page of the form
exports.fillRules = [ //Each element is a new page in the form
{// First page
// Keys must be CSS selectors
// Values indicate how to fill the selected element
"#inputid" : "constant string value",
@lovasoa
lovasoa / add_google_contact.php
Created March 14, 2014 13:27
Add contact using google contact api
<?php
require_once("google_api_info.php");
//TODO
$redirect_uri = "http://localhost/D%C3%A9veloppement/HISTU/ajout_contact.php";
$group_id = "6"; // Used as the default 'My Contacts' group.
require_once ('Google/Client.php');
require_once ('Google/Http/Request.php');