Skip to content

Instantly share code, notes, and snippets.

View Thesephi's full-sized avatar
:octocat:
active at 3am

dk Thesephi

:octocat:
active at 3am
View GitHub Profile
@Thesephi
Thesephi / scream_in_2_streams.rs
Last active December 24, 2024 21:03
rust fn that outputs into 2 streams
fn main() {
println!("I'm spit out of stdout, you can see me e.g. in the web browser or curl");
eprintln!("I am thrown out of stderr, you can see me at https://log.zzzz.dev/show if you know where I was deployed from");
}
@Thesephi
Thesephi / de_flag.rs
Created November 26, 2024 00:15
rust function that outputs the 🇩🇪 flag in bmp format
use std::io::{self, Write};
fn generate_german_flag_bmp() -> io::Result<()> {
let mut stdout = io::stdout();
let mut handle = stdout.lock();
const WIDTH: u32 = 500;
const HEIGHT: u32 = 300;
// Each row must be a multiple of 4 bytes, so calculate padding
@Thesephi
Thesephi / mario.rs
Last active November 24, 2024 14:57
rust fn that allegedly draws Mario
fn print_ascii_art() {
let art = r#"
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣤⣶⠶⠒⠂⠀⠐⠶⠶⠶⣶⣤⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡾⠟⠋⠀⣀⣤⢶⡿⠿⠿⢿⢶⣤⡀⠈⠙⠷⣦⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡾⠋⠀⠀⢀⣾⠋⠀⣸⣧⡀⣰⣾⡆⠉⢿⣶⣤⠤⠀⠙⢷⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡾⠃⠀⠀⠀⢀⣾⠇⠀⣼⡿⠻⣿⡿⢻⣿⣆⠀⢻⣿⣤⣀⠀⠀⠹⣦⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣰⠟⠀⠀⠀⠀⢀⣸⣿⡄⢸⣿⠇⠀⠈⠀⠀⢻⣿⡄⣾⣿⣿⣿⣶⣄⠀⠈⢷⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⠏⠀⡀⠀⠀⢈⣸⣷⣽⣿⣦⣝⣀⣤⣤⣤⣤⣼⣭⣾⣿⣿⣿⣿⣿⣿⣷⠀⠈⣿⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⢸⠏⠀⠀⠀⣤⣶⣶⣿⣿⣿⣶⣾⣿⣿⣿⣿⣿⣿⣿⣿⣶⣯⣭⣛⣿⣿⣿⣿⣿⡄⠘⣷⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⢀⡟⠀⢀⣶⣿⣿⣿⣿⣿⣿⣿⣿⡿⢿⠿⠛⠛⠛⠛⠿⢿⣿⣿⣿⣿⣿⣿⣾⣿⣿⣿⡆⢹⣧⠀⠀⠀⠀⠀⠀⠀⠀⠀
@Thesephi
Thesephi / simple.cpp
Last active November 8, 2024 16:31
a simple function written in c++
#include <stdio.h>
#include <iostream>
int main(int argc, char **argv, char **envp)
{
printf("%s\n", "Ich liebe dich");
return 0;
}
@Thesephi
Thesephi / simple.py
Created November 8, 2024 16:21
a simple function written in python
import sys
import os
print("I love ya")
@Thesephi
Thesephi / simple.rs
Last active November 8, 2024 02:54
a very simple rust function, to demonstrate on https://zzzz.dev
use std::env;
pub fn main() {
let args: Vec<String> = env::args().collect();
let mut ret_val = String::from("hello, ");
ret_val.push_str(&args[1]);
ret_val.push_str("\n");
ret_val.push_str("try calling me like https://fd96bd80a0d79fe3831f67a461d064b6.run.zzzz.dev/mommy");
println!("{}", ret_val);
}
@Thesephi
Thesephi / hello_rust.rs
Last active November 8, 2024 01:58
a simple function written in rust
pub fn main(name: &str) -> String {
let mut ret_val = String::from("xin chào, ");
ret_val.push_str(name);
println!("{}", ret_val);
ret_val
}
// normally `main` isn't supposed to return `String` type
// but this is done on purpose here to support a specially intended use case
@Thesephi
Thesephi / testing-library-and-jest-react-hooks-shallow-co-existence.test.js
Created March 30, 2022 23:51
@testing-library/react-hooks and jest-react-hooks-shallow co-existence
import { renderHook } from '@testing-library/react-hooks'
import enableHooks, { withoutHooks } from 'jest-react-hooks-shallow'
// enable jest-react-hooks-shallow helper by default
enableHooks(jest)
describe('@testing-library/react-hooks renderHook and jest-react-hooks-shallow co-existence', () => {
it('testing-library `renderHook` does NOT work when jest-react-hooks-shallow helper is enabled', () => {
jest.spyOn(console, 'log');
@Thesephi
Thesephi / gpg_keys_management.sh
Last active September 11, 2021 13:46
simple gpg key management
# view list of keys available on the system
gpg --list-secret-keys --keyid-format=long
# generate a new key (to be associated with a specific email address for which you'll be prompted)
gpg --full-generate-key # might differ depending on the gpg version being used
# echo pub key to the console
gpg -a --export your@email.example.com
# example use case: sign git commits with your gpg key
@Thesephi
Thesephi / it.should.work.spec.js
Created January 29, 2019 09:07
it should work
describe('test', () => {
it('should work', () => {
});
}