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 / 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 / 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 / .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 / 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
@asaaki
asaaki / bench-env-vars-in-different-scopes.rb
Last active July 6, 2020 11:14
Ruby: Do ENV vars have a significant impact on the runtime performance?
#!/usr/bin/env ruby
# gem install benchmark-ips
require 'benchmark'
require 'benchmark/ips'
# https://github.com/evanphx/benchmark-ips#custom-suite
class GCSuite
def warming(*); run_gc; end
def running(*); run_gc; end
def warmup_stats(*); end
@asaaki
asaaki / tco.rs
Created June 12, 2020 17:41
TCO #rustlang #recursion
// Recursion: TCO (Tail Call Optimization)
// Computerphile: https://www.youtube.com/watch?v=_JtPhF8MshA
fn fib(n: usize) -> usize {
fib_go(n, 0, 1)
}
fn fib_go(n: usize, a: usize, b: usize) -> usize {
match (n, a, b) {
(0, v, _) => return v,
@asaaki
asaaki / README.md
Last active April 23, 2020 13:44 — forked from twooster/README.md
Create scrolling text gifs for Slack

(Forked fork, that works on macos, too)

Makes little scrolly text jiffs in Flywheel colors.

Prerequisites

  • macos: brew install fontconfig imagemagick gifsicle
  • Linux: sudo apt install fontconfig imagemagick gifsicle

Usage