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 / lib.rs
Last active October 30, 2022 00:33
autovec : alternative to rust's standard vector type which uses column-oriented storage for better code auto-vectorization. In short: makes rust code working with vectors of structs magically faster.
#[derive(Clone, Debug, PartialEq)]
struct B {
x: bool,
y: f64,
}
pub trait AutoVec {
type Vec;
}
@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() {
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 / id_ed25519.pub
Created December 11, 2020 14:54
X1 public key
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGZ4MWfrK3MrBbfj+xP72A5Up2JT5p6pT9fv1UmNs4WF ophir-x1
@lovasoa
lovasoa / read_logs.go
Created November 30, 2020 11:41
Read compressed docker logs without decompressing them all to disks simultaneously. (see https://github.com/moby/moby/issues/41678)
package main
import (
"compress/gzip"
"context"
"encoding/json"
"fmt"
"io"
"log"
"os"
@lovasoa
lovasoa / read_gzip_lines.go
Last active October 14, 2022 08:55
How to Read Lines from GZIP-Compressed Files in Go
package main
import (
"bufio"
"compress/gzip"
"fmt"
"io"
"log"
"os"
)
/**
* This is a cloudflare worker for dezoomify
*/
/**
* Respond to the request
* @param {Request} request
*/
async function handleRequest(request) {
@lovasoa
lovasoa / fork_bomb.rs
Created July 17, 2020 14:46
A process that repeatedly executes itself
use std::process::Command;
use std::env;
use std::process;
use std::time::SystemTime;
use crossbeam; // 0.7.3;
pub fn main() {
let myself = env::current_exe().expect("no current exe");
let n: u64 = env::args()
.enumerate()
@lovasoa
lovasoa / mandelbrot.sql
Last active June 12, 2020 17:10
Mandelbrot rendering implemented in SQL
WITH RECURSIVE
-- First, we define the grid we are working on
xaxis(x) AS (VALUES(-2.0) UNION ALL SELECT x+0.05 FROM xaxis WHERE x<0.5),
yaxis(y) AS (VALUES(-1) UNION ALL SELECT y+0.1 FROM yaxis WHERE y<1),
-- Then we compute the iterations of the mandelbrot function
iterations(iter, cx, cy, x, y) AS ( -- one value per iteration step per point
SELECT 0, x, y, 0.0, 0.0 FROM xaxis, yaxis -- c = cx + i * cy
UNION ALL
SELECT iter+1, cx, cy, x*x-y*y + cx, 2.0*x*y + cy -- z(iter+1) = z(iter)^2 + c. x=Re(z(iter+1)), y=Im(z(iter+1))
FROM iterations