Skip to content

Instantly share code, notes, and snippets.

View cynecx's full-sized avatar
🌧️
(~˘▾˘)~ 🌧

cynecx cynecx

🌧️
(~˘▾˘)~ 🌧
  • Germany
  • 08:29 (UTC +02:00)
View GitHub Profile
@cynecx
cynecx / smallbox.rs
Created September 8, 2024 21:05
smallbox
// rustc:
use core::marker::PhantomData;
use core::mem::{ManuallyDrop, MaybeUninit};
use core::ops::{Deref, DerefMut};
use core::ptr::{addr_of, addr_of_mut};
#[derive(Copy, Clone, Debug)]
enum Kind {
Inline,
@cynecx
cynecx / tuplefn.rs
Created May 27, 2024 02:00
Tuple Fn
mod private {
pub trait Sealed<A, R> {}
}
pub trait TupleFn<A, R>: private::Sealed<A, R> {
fn as_tuple_fn(self) -> impl FnMut(A) -> R;
}
macro_rules! impl_tuple_fns {
(__emit $($arg:ident),*) => {
@cynecx
cynecx / main.rs
Created September 28, 2023 00:38
TOTP
use std::{
process::exit,
time::{SystemTime, UNIX_EPOCH},
};
use hmac::{Hmac, Mac};
use sha1::Sha1;
type HmacSha1 = Hmac<Sha1>;
@cynecx
cynecx / once.rs
Last active May 31, 2023 21:37
Once
use std::{
cell::UnsafeCell,
panic::{self, AssertUnwindSafe},
sync::atomic::{AtomicBool, AtomicPtr, Ordering},
thread::{self, Thread},
unreachable,
};
use sptr::Strict;
@cynecx
cynecx / countries.csv
Created April 18, 2023 12:38
Country code
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
Afghanistan;AF;AFG
Aland Islands;AX;ALA
Åland Islands;AX;ALA
Albania;AL;ALB
Algeria;DZ;DZA
American Samoa;AS;ASM
Andorra;AD;AND
Angola;AO;AGO
Anguilla;AI;AIA
Antarctica;AQ;ATA
#![no_std]
#![feature(link_llvm_intrinsics)]
extern "C" {
#[link_name = "llvm.memcpy.inline.p0.p0.i64"]
fn llvm_memcpy_inline(dst: *mut (), src: *const (), len: usize, is_volatile: bool);
}
#[inline(always)]
unsafe fn memcpy_inline<const N: usize>(dst: *mut (), src: *const ()) {
@cynecx
cynecx / uuidv7.sql
Last active January 6, 2023 21:31
Generate a version 7 UUID in PL/pgSQL as specified in the draft (https://www.ietf.org/archive/id/draft-peabody-dispatch-new-uuid-format-04.html)
--- Generate a version 7 UUID in PL/pgSQL as specified in the draft (https://www.ietf.org/archive/id/draft-peabody-dispatch-new-uuid-format-04.html)
CREATE OR REPLACE FUNCTION uuid_generate_v7() RETURNS uuid AS $$
DECLARE
raw bytea;
tsbits bit(48);
BEGIN
raw := decode(replace(uuid_generate_v4()::text, '-', ''), 'hex');
tsbits := (extract(epoch from clock_timestamp()) * 1000)::bigint::bit(48);
--- set unix timestamp (big endian) in the upper 48 bits/6 bytes
@cynecx
cynecx / test.rs
Created June 6, 2022 14:20
Somekind of specialization in nightly using negative_impls + with_negative_coherence
#![feature(negative_impls, with_negative_coherence)]
#[derive(Debug)]
struct A;
#[derive(Debug)]
struct B;
#[derive(Debug)]
enum Foo {
@cynecx
cynecx / github-mobile-fix.js
Last active December 14, 2023 01:21
Use with userscript extension on iOS. I hate sticky headers.
// ==UserScript==
// @name Fix Github Mobile
// @encoding utf-8
// @match *://*.github.com/*
// @compatible chrome
// @compatible firefox
// @compatible opera
// @compatible safari
// @compatible edge
// @run-at document-idle
@cynecx
cynecx / script.js
Created April 15, 2022 17:12
Force Native Emoji Font (eg. Apple) on GitHub As Tampermonkey Script
(function () {
"use strict";
const originalCustomElements = window.customElements;
const originalPropertyDescriptor = Object.getOwnPropertyDescriptor(window, "customElements");
const newCustomElements = {
get(name) {
return originalCustomElements.get(name)
},
define(name, constructor, options) {
if (name === "g-emoji") {