Skip to content

Instantly share code, notes, and snippets.

@VictorTaelin
VictorTaelin / ai_reasoning_challenge_v2.md
Last active April 17, 2025 08:38
INVERT A BINARY TREE - $10k AI REASONING CHALLENGE (v2)

THE PROBLEM

🌲 Invert a binary tree! 🌲

Except with 3 catches:

  1. It must invert the keys ("bit-reversal permutation")
  2. It must be a dependency-free, pure recursive function
  3. It must have type Bit -> Tree -> Tree (i.e., a direct recursion with max 1 bit state)
@apangin
apangin / Objects.java
Last active February 14, 2025 21:29
Objects.hash alternative capable of allocation elimination
public static int hash(String... args) {
if (args != null) {
switch (args.length) {
case 1:
return 31 + Objects.hashCode(args[0]);
case 2:
return 961 + Objects.hashCode(args[0]) * 31
+ Objects.hashCode(args[1]);
case 3:
return 29791 + Objects.hashCode(args[0]) * 961
@dhh
dhh / linux-setup.sh
Last active April 28, 2025 16:30
linux-setup.sh
# THIS LINUX SETUP SCRIPT HAS MORPHED INTO A WHOLE PROJECT: HTTPS://OMAKUB.ORG
# PLEASE CHECKOUT THAT PROJECT INSTEAD OF THIS OUTDATED SETUP SCRIPT.
#
#
# Libraries and infrastructure
sudo apt update -y
sudo apt install -y \
docker.io docker-buildx \
build-essential pkg-config autoconf bison rustc cargo clang \
#include <stdio.h>
#include <stdlib.h>
#define da_append(xs, x) \
do { \
if ((xs)->count >= (xs)->capacity) { \
if ((xs)->capacity == 0) (xs)->capacity = 256; \
else (xs)->capacity *= 2; \
(xs)->items = realloc((xs)->items, (xs)->capacity*sizeof(*(xs)->items)); \
} \
@GavinRay97
GavinRay97 / Dockerfile
Created September 21, 2022 15:00
OpenJDK build environment
FROM quay.io/fedora/fedora:38
# Install requirements for building OpenJDK from source
RUN dnf install -y \
file \
diffutils \
alsa-lib-devel \
cups-devel \
fontconfig-devel \
freetype-devel \
@robert-king
robert-king / pizza_delivery.rs
Last active October 12, 2022 19:48
kickstart pizza delivery
/*
@robertkingnz
https://www.youtube.com/c/RobertKing/videos -> https://youtu.be/Z5WzJ9jbnKg
https://codingcompetitions.withgoogle.com/kickstart/round/00000000008cb0f5/0000000000ba86e6
*/
extern crate core;
fn calc_toll(c: i64, toll: &(char, i64)) -> i64 {
let ans = match toll.0 {
<!-- plug-in configuration to put into your parent POM for avoiding any usages of
outdated log4j2 versions, some of which are subject to the RCE CVE-2021-44228
("Log4Shell"), CVE-2021-45046, and CVE-2021-45105. Make sure to check for the
latest version of log4j2 at
https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.0.0</version>
@WJWH
WJWH / gist:f3a196e65fdabd6eace5f89da430600e
Created October 1, 2021 14:16
Server that does no syscalls for handling connections
// Extremely hacky server program that will send a standard response
// to every client that connects, then closes the connection. Will
// issue no system calls (as measured by `strace`) after initial setup
// no matter how many requests are served.
// Yes, this program is sorely lacking in error checking. It's a toy
// and not meant to be taken seriously.
// compile with gcc no_syscall_server.c -luring
#!/usr/bin/env python3
#
# Copyright 2021 Matt Fleming
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
@bric3
bric3 / IsATTY.java
Created June 8, 2021 15:42
Allows to determine if standard stream are connected to a terminal. Calls native isatty C function, and dynamically build the wrapper code.
/*
* MIT License
*
* Copyright (c) 2021 Brice Dutheil <[email protected]>
*
* 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