Skip to content

Instantly share code, notes, and snippets.

View iomonad's full-sized avatar
🍋
λ

iomonad iomonad

🍋
λ
  • 13:06 (UTC +03:00)
View GitHub Profile
(ns cljsandbox.lattices)
;; euler 15
(defn ! [x]
(reduce *' (range 1 (inc x))))
(defn lattices-paths [x]
(/ (! (* 2 x)) (* (! x)) (! x)))
@iomonad
iomonad / collatz.clj
Last active February 16, 2021 08:12
The Collatz conjecture implemented with lazy-seq
(ns cljsandbox.collatz)
(defn next-collatz [n]
"Return the next step"
{:pre [(> n 0)]}
(cond
(even? n) (-> n (/ 2))
(odd? n) (-> n (* 3) (inc))))
(defn collatz [n]
@iomonad
iomonad / expng.ex
Created November 27, 2020 08:47 — forked from zabirauf/expng.ex
PNG format Parser in Elixir
defmodule Expng do
defstruct [:width, :height, :bit_depth, :color_type, :compression, :filter, :interlace, :chunks]
def png_parse(<<
0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A,
_length :: size(32),
"IHDR",
width :: size(32),
height :: size(32),
@iomonad
iomonad / flatmap.ex
Created November 13, 2020 10:16
Elixir Flatmap
File.stream!("/etc/passwd")
|> Enum.chunk_every(4)
|> Enum.flat_map(&(Enum.map(&1, fn x -> String.length(x) end)))
@iomonad
iomonad / virtualbox_ports.png
Created September 23, 2020 12:45 — forked from snb/virtualbox_ports.png
virtualbox serial console
virtualbox_ports.png
@iomonad
iomonad / nginx-tuning.md
Created May 23, 2020 11:56 — forked from denji/nginx-tuning.md
NGINX tuning for best performance

NGINX Tuning For Best Performance

For this configuration you can use web server you like, i decided, because i work mostly with it to use nginx.

Generally, properly configured nginx can handle up to 400K to 500K requests per second (clustered), most what i saw is 50K to 80K (non-clustered) requests per second and 30% CPU load, course, this was 2 x Intel Xeon with HyperThreading enabled, but it can work without problem on slower machines.

You must understand that this config is used in testing environment and not in production so you will need to find a way to implement most of those features best possible for your servers.

@iomonad
iomonad / obfuscate.txt
Created April 26, 2020 08:52
A primer on some C obfuscation tricks.
A primer on some C obfuscation tricks.
Typedef abuse:
1) normal expected form:
typedef signed int my_int;
2) abuse it by:
signed int typedef my_int;
int typedef signed my_int;
@iomonad
iomonad / notify.py
Created April 20, 2020 07:44
Python Class member mutation notification
class Notify:
def __init__(self, name):
self._name = name def __set__(self, instance, value):
instance.__dict__[self._name] = value
for callback in instance.__dict__[f"__notify_{self._name}"]:
callback(value)
def watch(instance, field, callback):
setattr(instance.__class__, field, Notify(field))
instance.__dict__.setdefault(f"__notify_{field}", []).append(callback)
@iomonad
iomonad / gist:69c91e51175382ea607c097ee390d566
Created March 26, 2020 17:27 — forked from chrisdone/gist:02e165a0004be33734ac2334f215380e
Build and run minimal Linux / Busybox systems in Qemu

Common

export OPT=/opt
export BUILDS=/some/where/mini_linux
mkdir -p $BUILDS

Linux kernel

@iomonad
iomonad / paginator2000.js
Created March 9, 2020 13:48
Pagination script for Mr Quentin.
//
// file: paginate.js
//
function pagination(c, max, count) {
var current = c,
last = max,
left = current - count,
right = current + count + 1,
range = [],