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 / ethernet_delayed_echo_server.rs
Last active October 22, 2022 23:16
Ethernet echo server with a fixed delay between request and response
// See https://www.reddit.com/r/rust/comments/yaqsqe/how_to_delay_lots_of_synchronous_actions/?sort=new
use pnet::datalink::{self};
use pnet::datalink::Channel::Ethernet;
use pnet::datalink::DataLinkSender;
use pnet::packet::ethernet::MutableEthernetPacket;
use std::sync::mpsc;
use std::time::Instant;
fn main() {
@lovasoa
lovasoa / read_gzip_lines.go
Last active October 14, 2022 08:55 — forked from cathalgarvey/jlgz_dump.go
How to Read Lines from GZIP-Compressed Files in Go
package main
import (
"bufio"
"compress/gzip"
"fmt"
"io"
"log"
"os"
)
@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 / 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);
import sys
from numpy import *
from collections import Counter
n = int(sys.argv[1])
def mat_fun(i,j): return (j == (i+1)%9) | ((i==6) & (j==0))
M = matrix(fromfunction(mat_fun, (9, 9)), dtype=int)**n
ages=Counter(map(int,input().split(',')))
sizes=array([ages[i] for i in range(9)])
print(M.dot(sizes).sum())
from asyncua import ua
from asyncua.ua import ua_binary
import sys
import timeit
obj = ua.WriteParameters(NodesToWrite=[
ua.WriteValue(
NodeId_=ua.NodeId("hello_world"),
Value=ua.DataValue(
Value=
@lovasoa
lovasoa / README.md
Last active June 30, 2021 16:23
ODT to HTML conversion

#Ophir.php

Important note

This code is not up to date. It is now hosted at https://github.com/lovasoa/ophir.php

PHP script that converts ODT to HTML

ophir.php is a lightweight script that parses an open document file and outputs a simple HTML file, with very few tags (contrarily to most other tools that do the same).

Features

Currently, the script parses bold (b tag), italic (i tag), underline (u tag), quotations (blockquote tag), images (using data URIs), links, headings (h1, h2, ...), lists (ul and li), tables (table tr and td) annotations and footnotes.
@lovasoa
lovasoa / UTF8byteLength.js
Created April 27, 2014 23:23
Compute the length in bytes of a javascript string, when encoded in UTF8
function byteLength(str) {
// returns the byte length of an utf8 string
var s = str.length;
for (var i=str.length-1; i>=0; i--) {
var code = str.charCodeAt(i);
if (code > 0x7f && code <= 0x7ff) s++;
else if (code > 0x7ff && code <= 0xffff) s+=2;
if (code >= 0xDC00 && code <= 0xDFFF) i--; //trail surrogate
}
return s;
@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 / find_pair_with_sum.md
Last active February 9, 2021 06:22
Working at google: answers to google job interview programming problem mentioned in https://www.youtube.com/watch?v=XKu_SEDAykw

find_pair_with_sum

Given a sorted array of integers and a number n, find a pair of numbers in the array whose sum is n.

Solution

Algorithm

Start with a pair constituted of the first and last numbers of the sorted array. At each step, compute the sum of the current pair. If the sum is larger than our objective, take following element as the first of our pair.