Skip to content

Instantly share code, notes, and snippets.

View xandkar's full-sized avatar
🤔
quis custodiet ipsos custodes?

Siraaj Khandkar xandkar

🤔
quis custodiet ipsos custodes?
View GitHub Profile
@xandkar
xandkar / DOM3D.js
Created March 28, 2024 03:47 — forked from OrionReed/dom3d.js
3D DOM viewer, copy-paste this into your console to visualise the DOM topographically.
// 3D Dom viewer, copy-paste this into your console to visualise the DOM as a stack of solid blocks.
// You can also minify and save it as a bookmarklet (https://www.freecodecamp.org/news/what-are-bookmarklets/)
(() => {
const SHOW_SIDES = false; // color sides of DOM nodes?
const COLOR_SURFACE = true; // color tops of DOM nodes?
const COLOR_RANDOM = false; // randomise color?
const COLOR_HUE = 190; // hue in HSL (https://hslpicker.com)
const MAX_ROTATION = 180; // set to 360 to rotate all the way round
const THICKNESS = 20; // thickness of layers
const DISTANCE = 10000; // ¯\\_(ツ)_/¯
@xandkar
xandkar / l2chroot.sh
Created February 6, 2024 21:33 — forked from adamjakab/l2chroot.sh
Chroot - copy binaries and their shared dynamic libraries to chrooted envirnoment
#!/bin/bash
# Use this script to copy shared (libs) files to Apache/Lighttpd chrooted
# jail server.
# ----------------------------------------------------------------------------
# Written by nixCraft <http://www.cyberciti.biz/tips/>
# (c) 2006 nixCraft under GNU GPL v2.0+
# + Added ld-linux support
# + Added error checking support
# ------------------------------------------------------------------------------
# See url for usage:
@xandkar
xandkar / super-compilation.md
Last active February 4, 2024 21:52 — forked from hirrolot/a-preface.md
A complete implementation of the positive supercompiler from "A Roadmap to Metacomputation by Supercompilation" by Gluck & Sorensen

Supercompilation is a deep program transformation technique due to V. F. Turchin, a prominent computer scientist, cybernetician, physicist, and Soviet dissident. He described the concept as follows [^supercompiler-concept]:

A supercompiler is a program transformer of a certain type. The usual way of thinking about program transformation is in terms of some set of rules which preserve the functional meaning of the program, and a step-by-step application of these rules to the initial program. ... The concept of a supercompiler is a product of cybernetic thinking. A program is seen as a machine. To make sense of it, one must observe its operation. So a supercompiler does not transform the program by steps; it controls and observes (SUPERvises) the running of the machine that is represented by the program; let us call this machine M1. In observing the operation of

@xandkar
xandkar / async_doesnt.rs
Last active January 26, 2024 17:10
Reconnect pattern conversion failure from sync to async
use std::{future::Future, io, time::Duration};
use tokio::{net::TcpStream, time::sleep};
struct Worker {
addr: String,
stream: Option<TcpStream>,
}
impl Worker {
@xandkar
xandkar / scar_tissue.md
Created June 20, 2023 19:09 — forked from gtallen1187/scar_tissue.md
talk given by John Ousterhout about sustaining relationships

"Scar Tissues Make Relationships Wear Out"

04/26/2103. From a lecture by Professor John Ousterhout at Stanford, class CS142.

This is my most touchy-feely thought for the weekend. Here’s the basic idea: It’s really hard to build relationships that last for a long time. If you haven’t discovered this, you will discover this sooner or later. And it's hard both for personal relationships and for business relationships. And to me, it's pretty amazing that two people can stay married for 25 years without killing each other.

[Laughter]

> But honestly, most professional relationships don't last anywhere near that long. The best bands always seem to break up after 2 or 3 years. And business partnerships fall apart, and there's all these problems in these relationships that just don't last. So, why is that? Well, in my view, it’s relationships don't fail because there some single catastrophic event to destroy them, although often there is a single catastrophic event around the the end of the relation

-spec os_cmd(string()) ->
{integer(), iolist()}.
os_cmd(Command) ->
PortOptions = [stream, exit_status, use_stdio, stderr_to_stdout, in, eof],
PortID = open_port({spawn, Command}, PortOptions),
os_cmd_collect(PortID, []).
-spec os_cmd_collect(port(), iolist()) ->
{integer(), iolist()}.
os_cmd_collect(PortID, Data) ->
@xandkar
xandkar / select.rs
Created September 26, 2022 15:52 — forked from AGWA/select.rs
Very simple Rust wrapper around pselect
/* Copyright (C) 2017 Andrew Ayer
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
@xandkar
xandkar / 55-bytes-of-css.md
Created September 25, 2022 16:16 — forked from JoeyBurzynski/55-bytes-of-css.md
58 bytes of css to look great nearly everywhere

58 bytes of CSS to look great nearly everywhere

When making this website, i wanted a simple, reasonable way to make it look good on most displays. Not counting any minimization techniques, the following 58 bytes worked well for me:

main {
  max-width: 38rem;
  padding: 2rem;
  margin: auto;
}
-spec find_connected_node_pair([{N, libp2p_crypto:pubkey_bin()}]) ->
disjoint_network | {N, N} when N :: node().
find_connected_node_pair(NodeAddrs) ->
P2P = fun libp2p_crypto:pubkey_bin_to_p2p/1,
P2PAddrToNode =
lists:foldl(fun ({N, A}, A2N) -> maps:put(P2P(A), N, A2N) end, #{}, NodeAddrs),
Topology = digraph:new(),
lists:foreach(
fun ({NodeA, _}) ->
_ = digraph:add_vertex(Topology, NodeA),
[("-f" "--flag") => (λ (flag arg1 arg2 ...) (do-stuff ...)) '("Command description." "arg1 description" "arg2 description" ...)]