Skip to content

Instantly share code, notes, and snippets.

View asaaki's full-sized avatar
🦀
I may be slow to respond. Ping me on Twitter instead: https://twitter.com/asaaki

Christoph Grabo asaaki

🦀
I may be slow to respond. Ping me on Twitter instead: https://twitter.com/asaaki
View GitHub Profile
@asaaki
asaaki / lint-staged.sh
Created September 8, 2023 10:28
[ruby] rubocop, but only check git staged files
#!/bin/sh
# time execution
time bin/rubocop -L --stderr $(git diff --name-only --cached | grep '\.rb')
# bare minimum
bin/rubocop $(git diff --name-only --cached | grep '\.rb')
# -L = list files (good to see which one got checked since we don't see the nested command's output
# --stderr = may or may not be useful to pipe output there
@asaaki
asaaki / containers-and-clone.rs
Last active July 16, 2023 11:50 — forked from rust-play/playground.rs
[rust] How to avoid leaking trait bounds (to avoid such changes to be breaking changes)
// https://rust-lang.github.io/api-guidelines/future-proofing.html
/*
The following traits should never be used in bounds on data structures:
* Clone
*/
#[derive(Clone, Debug)]
@asaaki
asaaki / 0___rust_serde_json_wasm_parcel___0.md
Last active January 28, 2023 14:14
Rust-to-JS JSON string exchange (parcel.js, wasm)

Rust, serde-json, wasm, parcel.js

With this combination it is fairly easy to get things done in Rust and utilize it in JavaScript. Yay!

@asaaki
asaaki / .gitconfig
Last active October 14, 2022 03:06
Using different emails and GPG keys for work and personal stuff on GitHub
[core]
# ...
[init]
defaultBranch = main
[commit]
gpgsign = true
# you want that to have a default for locations outside of your regular dev folders
@asaaki
asaaki / pygments-monokai.css
Created June 4, 2011 00:57
Jekyll module for github like source code highlighting
.highlight { background-color: #49483e }
.c { color: #75715e } /* Comment */
.err { color: #960050; background-color: #1e0010 } /* Error */
.k { color: #66d9ef } /* Keyword */
.l { color: #ae81ff } /* Literal */
.n { color: #f8f8f2 } /* Name */
.o { color: #f92672 } /* Operator */
.p { color: #f8f8f2 } /* Punctuation */
.cm { color: #75715e } /* Comment.Multiline */
.cp { color: #75715e } /* Comment.Preproc */
@asaaki
asaaki / delete-branch.yaml
Last active September 17, 2021 09:04
Automatically delete branches of unmerged pull requests
# .github/workflows/delete-branch.yaml
name: Delete unmerged branch
on:
pull_request:
branches: [ main ]
types: [ closed ]
jobs:
worker:
@asaaki
asaaki / m💩.rb
Last active August 16, 2021 12:18
M💩.🔫 #=> 💥
module M💩
module_function
def 🔫
puts '💥'
end
end
M💩.🔫
@asaaki
asaaki / Dockerfile
Last active March 15, 2021 20:24
PostgreSQL 11.5 with pglogical 2.2.2 as docker image
FROM postgres:11.5
RUN apt-get update && apt-get install -y curl
RUN curl https://dl.2ndquadrant.com/default/release/get/deb | bash && apt-get update
### IMPORTANT: use 2.2.2 instead of 2.2.1! Otherwise PG 11.5 is very sad!
RUN apt-get install -y -V postgresql-${PG_MAJOR}-pglogical=2.2.2-1.stretch+1
# the following copied from https://github.com/reediculous456/docker-pglogical/blob/master/Dockerfile
@asaaki
asaaki / code.js
Created September 17, 2020 13:37
fetch and no-cors, a difficult story
// Fetch - readable on origin only (it does make the call though)
let res = await (async () => {
const url = "https://markentier.tech/feed.json";
// const url = "https://dummy.restapiexample.com/api/v1/employee/9";
const res = await fetch(url, { mode: "no-cors" });
if(res.ok && res.status === 200) {
const body = await res.json();
return {body}
// const headers = Object.fromEntries(res.headers);
// return { body, headers }
@asaaki
asaaki / fire-and-forget-results.rs
Created July 16, 2020 08:12
Rust: Result types for quick prototyping
/*
IMPORTANT NOTE: It is not a good idea to use this pattern in production code!
*/
// Q&D way of catching all errors without worrying about their types at compile time
// @see https://doc.rust-lang.org/stable/rust-by-example/error/multiple_error_types/boxing_errors.html