Skip to content

Instantly share code, notes, and snippets.

View Rudxain's full-sized avatar

Ricardo Fernández Serrata Rudxain

View GitHub Profile
@joboet
joboet / 0000-pattern-types.md
Last active August 26, 2024 13:19
Pattern types RFC

Summary

This RFC introduces pattern types, which are subtypes of matchable types that are statically restricted to a subset of the variants of the original type.

@vi
vi / interesting_crates.md
Last active December 27, 2024 19:45
List of crates that improves or experiments with Rust, but may be hard to find

Let's list here crates that enhance Rust as a language.

It not "batteries" like in stdx, but Rust-specific crates for workarounds for various missing features and experimental ideals from non-accepted/postponed RFCs, or just hacky tricks.

The list is supposed to contain (mostly) crates that are internal to Rust, not ones for making Rust deal with "external world" like other languages bindings, file formats, protocols and so on.

Primary focus should be on crates that are not easy to find by conventional means (e.g. no algorithm name, format or protocol to search for).

Note that quality of the listed crates may vary from proof-of-concept to stable-and-widely-used.

import random
import typing.List
def thanos_sort(a: List[int]) -> List[int]:
'''Removes half of the list until it's perfectly balanced, like all things should be.'''
def _perfectly_balanced(a: List[int]) -> bool:
like_all_things_should_be = True
@rust-play
rust-play / playground.rs
Created September 27, 2018 01:24
Code shared from the Rust Playground
enum RecursionResult<C, R> {
Continue(C),
Return(R),
}
fn tail_recurse<C, R>(mut init: C, mut f: impl FnMut(C) -> RecursionResult<C, R>) -> R {
loop {
match f(init) {
RecursionResult::Continue(c) => init = c,
RecursionResult::Return(r) => return r,
@timvisee
timvisee / falsehoods-programming-time-list.md
Last active January 8, 2025 14:15
Falsehoods programmers believe about time, in a single list

Falsehoods programmers believe about time

This is a compiled list of falsehoods programmers tend to believe about working with time.

Don't re-invent a date time library yourself. If you think you understand everything about time, you're probably doing it wrong.

Falsehoods

  • There are always 24 hours in a day.
  • February is always 28 days long.
  • Any 24-hour period will always begin and end in the same day (or week, or month).
@koji-kojiro
koji-kojiro / import_from_gist.py
Created December 24, 2016 15:47
[Python] import from Gist
#!/usr/bin/env python
# -*- coding: utf-8 -*-
def load_gist(gist_id):
"""translate Gist ID to URL"""
from json import load
from urllib import urlopen
gist_api = urlopen("https://api.github.com/gists/" + gist_id)
@izabera
izabera / bfsh
Created November 23, 2016 10:23
brainfuck interpreter in posix sh
#!/bin/sh
LANG=C
compile() {
# some preprocessing and basic optimizations
code=$(printf %s "$1" |
(tr -dc '\133\135<>,.+-'; echo) | # ksh's builtin tr doesn't like []<>,.+-
sed -e :a -e 's/<>//g;s/><//g;s/+-//g;s/-+//g
s/\[-]/z/g;s/zzz*/z/g;s/[+-]z/z/g;ta')
print(''.join([chr(x) for x in [int(x,16) for x in \
[str(hex(2 * 2 * 5 * 7 * 37 * 149 * 5417 * 148781 \
* 51939996061871)[i:(i+2)])\
for i in range(25)][2::2]]]))