Skip to content

Instantly share code, notes, and snippets.

Avatar
⚠️
meow

Ondřej Hruška MightyPork

⚠️
meow
View GitHub Profile
@MightyPork
MightyPork / rsweep.sh
Created Mar 2, 2021
Run "cargo sweep" in all direct subfolders and report disk space saved
View rsweep.sh
#!/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 Apr 23, 2020
rust tuple flattening
View tuple_flatten.rs
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 Apr 14, 2020
good ASCII table with hex
View ascii.txt
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 Sep 8, 2019
userscript to make japanese posts in pleromafe bigger so kanji can be read
View bigger-japanese.user.js
// ==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 Jul 21, 2019
Get weekday from a date, C version
View weekday.c
/**
* 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 Jun 11, 2019
example of custom serialize and deserialize in serde
View custom-serde.rs
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 Dec 29, 2018
Rust animals game sample output
View animals_game.txt
----- NEW GAME -----
Secret animal is: duck
What animal is it?
> duck
Game ended.
----- NEW GAME -----
Secret animal is: dog
Is it a duck?
> no
View fibo.rs
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 {
View r2000.chunked.asm
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
View broken-nginx.yml
version: '3'
services:
nginx:
image: 'nginx:alpine'
restart: always
networks:
- web
labels:
- "traefik.docker.network=traefik"
- "traefik.backend=blog"