Skip to content

Instantly share code, notes, and snippets.

View lovasoa's full-sized avatar
🎯
Focusing

Ophir LOJKINE lovasoa

🎯
Focusing
View GitHub Profile
-- Run online at: https://repl.it/repls/WeeSlightExams
-- hackernews thread: https://news.ycombinator.com/item?id=21543377
solve funcs = filter (matches funcs) (possibilities funcs)
matches funcs truths = truths == zipWith (($).($truths).flip) funcs [0..]
possibilities [] = [[]]
possibilities (x:xs) = concatMap (sequence [(True:), (False:)]) (possibilities xs)
all_of = ((and.).)
one_of = ((or.).)
@lovasoa
lovasoa / get_tile_counts.js
Last active October 29, 2019 23:58
zoomify viewer initialization function
function get_tile_counts(width, height, tile_width, tile_height, numtiles) {
var level_count = 0, level_widths=[], level_heights=[], level_tile_count=[], level_tile_count_x=[], level_tile_count_y=[];
var imageW = width;
var imageH = height;
var tileWidth = tile_width;
var tileHeight = tile_height;
width = imageW;
height = imageH;
while (width > tileWidth || height > tileHeight) {
@lovasoa
lovasoa / mul_add.rs
Last active October 25, 2019 09:29
Improvement upon the code presented in "Rust and C++ on Floating-point Intensive Code" (https://www.reidatcheson.com/hpc/architecture/performance/rust/c++/2019/10/19/measure-cache.html)
/*
compile with:
rustc -C target-cpu=native -C opt-level=3 -C inline-threshold=1 -O mul_add.rs
*/
use std::env;
fn main(){
use std::time::{Instant};
let args: Vec<String> = env::args().collect();
let n=args[1].parse::<usize>().unwrap();
@lovasoa
lovasoa / hanoi.rs
Last active January 28, 2023 14:09
Tower of hanoi solver in rust.
/***
Tower of Hanoi solver.
https://en.wikipedia.org/wiki/Tower_of_Hanoi
Example :
```
$ rustc hanoi.rs
$ ./hanoi 3
@lovasoa
lovasoa / README.md
Last active October 1, 2019 14:40
Command-line utility that transcribes a number to the mayan numeral system. Written in rust.
pub fn decrypt(mut input_buf: Vec<u8>) -> Result<Vec<u8>, InvalidEncryptedImage> {
if get_int(&input_buf, 0) != 0x0A_0A_0A_0A { return Ok(input_buf); }
let header_size = get_int(&input_buf, input_buf.len() as u32 - 4);
let encrypted_size_pos = header_size + 4;
let encrypted_pos = encrypted_size_pos + 4;
let encrypted_size = get_int(&input_buf, encrypted_size_pos);
let encrypted_end_pos = encrypted_pos + encrypted_size;
let footer_size = input_buf.len() as u32 - 4 - encrypted_end_pos;
let encrypted = input_buf.get(encrypted_pos as usize..(encrypted_pos + encrypted_size) as usize).unwrap();
let mut encrypted_copy = Vec::from(encrypted);
@lovasoa
lovasoa / influxdb_benchmark.py
Created July 11, 2019 10:47
InfluxDB python client benchmark
def test(client, n):
"""Stupid test function"""
q = f"SELECT * FROM test LIMIT {n}"
client.query(q)
setup = """
from __main__ import test
from influxdb import InfluxDBClient
html, body {
font-family: sans-serif;
margin: 0;
padding: 0;
font-size: 16px;
}
header > nav{
display: flex;
border: 1px solid black;
import xml.sax
import sys
import json
class InkscapeSvgHandler(xml.sax.ContentHandler):
def __init__(self):
self.o = {}
self.t = 1554660678511
def startElement(self, name, attrs):
if name not in ("path","line","rect"):
This file has been truncated, but you can view the full file.
<?xml version="1.0"?>
<svg xmlns="http://www.w3.org/2000/svg" id="canvas" width="51880" height="65536" version="1.1" style="cursor: move; will-change: auto; transform: scale(0.1);">
<defs id="defs"/>
<line id="sjww41vjcg" x1="16580" y1="15620" x2="16610" y2="15620" stroke="#fdeedf" stroke-width="48" opacity="1"/>
<line id="sjww42o52m" x1="18560" y1="11500" x2="18920" y2="11700" stroke="#ffffff" stroke-width="48" opacity="1"/>
<line id="sjww42q3rs" x1="18730" y1="11500" x2="18760" y2="11500" stroke="#ffffff" stroke-width="48" opacity="1"/>
<line id="sjww42qyy4" x1="18710" y1="11520" x2="19110" y2="11930" stroke="#ffffff" stroke-width="48" opacity="1"/>
<line id="sjww44z7l3" x1="14570" y1="10900" x2="14570" y2="10890" stroke="#fff6ee" stroke-width="48" opacity="1"/>
<line id="sjww476g4i" x1="15630" y1="11410" x2="15620" y2="11410" stroke="#fff6ee" stroke-width="48" opacity="1"/>
<path id="ljww4bditk" stroke="#84776b" stroke-width="48" opacity="0.3" d="M 25950 13620"/>