Skip to content

Instantly share code, notes, and snippets.

View umgefahren's full-sized avatar

Hannes Furmans umgefahren

View GitHub Profile
@umgefahren
umgefahren / main.rs
Created July 10, 2021 16:03
Use hyper with Tor (Rust)
use tor_stream::TorStream;
use hyper::client::conn::Builder;
use hyper::Body;
use http::Request;
use tokio::net::TcpStream;
#[tokio::main]
async fn main() {
let url = "httpbin.org:80";
@umgefahren
umgefahren / main.rs
Created July 29, 2021 15:41
libp2p Kademlia with async interface
use libp2p::swarm::SwarmEvent;
use libp2p::NetworkBehaviour;
use libp2p::PeerId;
use libp2p::kad::{Kademlia, KademliaEvent, Quorum, Record, QueryResult};
use libp2p::kad::store::MemoryStore;
use libp2p::mdns::{Mdns, MdnsEvent, MdnsConfig};
use libp2p::kad::record::Key;
use libp2p::{identity, noise, Transport, mplex, Swarm};
use libp2p::tcp::TcpConfig;
use libp2p::core::upgrade;
@umgefahren
umgefahren / graph-viz.ipynb
Created December 19, 2021 14:05
Graph Viz
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@umgefahren
umgefahren / main.c
Last active March 6, 2022 15:24
Bitfields in C
#include <stdio.h>
int main() {
unsigned int number = 1203;
short found_one = 0;
for (int i = (sizeof(unsigned int) * 8) - 1; i >= 0; i--) {
if (number & (1u << i)) {
putchar('1');
found_one = 1;
} else if (found_one) {
@umgefahren
umgefahren / Fast-Enum-C.c
Created April 28, 2022 17:55
Implementation of fast enum in C
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <time.h>
#define ONE 1
// #define PRINT_OUPUT
const uint8_t uint8_one = ONE;
const uint16_t uint16_one = ONE;
#include <stdio.h>
#include <stdint.h>
int main() {
FILE * inp_file = fopen("input.txt", "r");
uint64_t a = 0;
uint64_t b = 0;
uint64_t c = 0;
uint64_t slider = 0;
uint64_t incremented = 0;
@umgefahren
umgefahren / init.el
Created January 20, 2023 18:09
Current Emacs Config
;; Define the init file
(setq custom-file (expand-file-name "custom.el" user-emacs-directory))
(when (file-exists-p custom-file)
(load custom-file))
;; Define and initialize package repositories
(require 'package)
(setq package-archives '(("melpa" . "http://melpa.org/packages/")
("gnu" . "http://elpa.gnu.org/packages/")))
(package-initialize)
@umgefahren
umgefahren / GEMINI_RUST.md
Created May 29, 2025 14:27
Google Gemini + schemars (Rust)

Gemini

The Google Gemini API features functionality to use proper JSON Schema instead of the reduced version that is the default and that you see in the wild (it's even not implemented in the offical SDK).

Here is the documentation.

This is quite tricky though, since they only show sample code for Python.

After some trial and error I managed to get it working with Rust.