Skip to content

Instantly share code, notes, and snippets.

View MightyPork's full-sized avatar
🐶
meow

Ondřej Hruška MightyPork

🐶
meow
View GitHub Profile
@MightyPork
MightyPork / rsweep.sh
Created March 2, 2021 17:37
Run "cargo sweep" in all direct subfolders and report disk space saved
#!/bin/bash
before=$(du -bs | cut -d$'\t' -f1)
for d in $(ls -1); do
if [[ -e "$d/target" ]]; then
echo "------------ $d -------------"
cd "$d"
cargo sweep -i
cd ..
fi
@MightyPork
MightyPork / tuple_flatten.rs
Created April 23, 2020 15:36
rust tuple flattening
mod tuple_flatten {
pub trait TupleFlatten3<A, B, C> {
fn flatten(self) -> (A, B, C);
}
impl<A, B, C> TupleFlatten3<A, B, C> for (A, (B, C)) {
fn flatten(self) -> (A, B, C) {
(self.0, (self.1).0, (self.1).1)
}
@MightyPork
MightyPork / ascii.txt
Created April 14, 2020 11:28
good ASCII table with hex
Dec Hex Char Dec Hex Char Dec Hex Char Dec Hex Char
-------------- -------------- -------------- --------------
0 00h NUL (null) 32 20h SP 64 40h @ 96 60h `
1 01h SOH (start of heading) 33 21h ! 65 41h A 97 61h a
2 02h STX (start of text) 34 22h " 66 42h B 98 62h b
3 03h ETX (end of text) 35 23h # 67 43h C 99 63h c
4 04h EOT (end of transmission) 36 24h $ 68 44h D 100 64h d
5 05h ENQ (enquiry) 37 25h % 69 45h E 101 65h e
6 06h ACK (acknowledge) 38 26h & 70 46h F 102 66h f
7 07h BEL (bell) 39 27h ' 71 47h G 103 67h g
@MightyPork
MightyPork / bigger-japanese.user.js
Last active September 8, 2019 08:30
userscript to make japanese posts in pleromafe bigger so kanji can be read
// ==UserScript==
// @name Bigger japanese
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://piggo.space/*
// @grant none
// ==/UserScript==
@MightyPork
MightyPork / weekday.c
Last active May 2, 2023 11:52
Get weekday from a date, C version
/**
* Weekday calculation utils.
*
* Month and weekday are 1-based, 1 is Monday.
* The enums may be replaced by ints at the expense of clarity.
*
* Released to the public domain
*/
#include <stdint.h>
@MightyPork
MightyPork / custom-serde.rs
Created June 11, 2019 20:34
example of custom serialize and deserialize in serde
use serde::ser::SerializeMap;
use serde::{Serialize, Serializer, de::Visitor, de::MapAccess, Deserialize, Deserializer};
use std::fmt;
#[derive(Debug)]
struct Custom(String, u32);
impl Serialize for Custom {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
@MightyPork
MightyPork / animals_game.txt
Created December 29, 2018 09:12
Rust animals game sample output
----- NEW GAME -----
Secret animal is: duck
What animal is it?
> duck
Game ended.
----- NEW GAME -----
Secret animal is: dog
Is it a duck?
> no
use std::io;
use std::io::Write;
fn fibo(n:u32) -> u32 {
if n <= 2 {
1
} else {
let mut prev1 = 1;
let mut prev2 = 1;
for _n in 2..n {
0000: 04 05 JMP 0005
0002: 00 NOP
0003: 24 2C JMP 012C
0005: 9A EF ANL P2,EF
0007: F4 EC CALL 07EC
0009: B8 51 MOV R0,51
000B: F0 MOV A,@ R0
000C: D3 AA XRL A,AA
000E: B9 04 MOV R1,04
0010: C6 2A JZ 2A
version: '3'
services:
nginx:
image: 'nginx:alpine'
restart: always
networks:
- web
labels:
- "traefik.docker.network=traefik"
- "traefik.backend=blog"