Skip to content

Instantly share code, notes, and snippets.

View berkus's full-sized avatar
🎯
Haptic drift

Berkus Decker berkus

🎯
Haptic drift
View GitHub Profile
@berkus
berkus / anyfile.groovy
Created May 8, 2024 18:00
Groovy/Gradle print object properties
def filtered = ['class', 'active']
println theObject.properties
.sort{it.key}
.collect{it}
.findAll{!filtered.contains(it.key)}
.join('\n')
@berkus
berkus / xbox-one-wireless-protocol.md
Created April 4, 2019 13:21 — forked from alfredkrohmer/xbox-one-wireless-protocol.md
XBox One Wireless Controller Protocol

Physical layer

The dongle itself is sending out data using 802.11a (5 GHz WiFi) with OFDM and 6 Mbit/s data rate:

Radiotap Header v0, Length 38
    Header revision: 0
    Header pad: 0
    Header length: 38
    Present flags
@berkus
berkus / convemoji.md
Last active January 20, 2024 16:11
Conventional Commits with Emoji
@berkus
berkus / pijularize.sh
Created January 21, 2022 08:18
Pijularize a Git repository with all branches
#!/bin/sh
set -e
set -x
reponame=`basename $(pwd)`
echo "#######################################################################################"
echo "# Script to import all local branches from current repository (${reponame}) into pijul"
echo "# Will create a bunch of temp repos for import, so have sufficient disk space"
echo "#######################################################################################"
@berkus
berkus / macro.rs
Last active November 18, 2022 14:09
Rust macro to impl Eq, PartialEq and Ord
// From https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=7febfe900dd6be489692040a93b2f7bd
macro_rules! impl_comparisons {
($ty:ty) => {
impl PartialOrd for $ty {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl PartialEq for $ty {

1. Separation of immutable and mutable logic

Quite a lot of different people have been on the same trail of thought. Gary Bernhardt's formulation of a "functional core, imperative shell" seems to be the most voiced.

"Boundaries" - Gary Bernhardt

"Imperative shell" that wraps and uses your "functional core".. The result of this is that the shell has fewer paths, but more dependencies. The core contains no dependencies, but encapsulates the different logic paths. So we’re encapsulating dependencies on one side, and business logic on the other side. Or put another way, the way to figure out the separation is by doing as much as you can without mutation, and then encapsulating the mutation separately. Functional core — Many fast unit tests. Imperative shell — Few integration tests

https://www.youtube.com/watch?v=yTkzNHF6rMs

@berkus
berkus / AnalogLiterals.hpp
Created September 13, 2021 21:34 — forked from yamamushi/AnalogLiterals.hpp
Multi-Dimensional Analog Literals in C++
/*
Referenced from:
http://web.archive.org/web/20120110153227/http://weegen.home.xs4all.nl/eelis/analogliterals.xhtml
*/
#ifndef ANALOGLITERALS_HPP
#define ANALOGLITERALS_HPP
namespace analog_literals {
@berkus
berkus / playground.rs
Created August 29, 2019 07:34 — forked from rust-play/playground.rs
Code shared from the Rust Playground
#![feature(unboxed_closures, fn_traits)]
fn main() {
let add = |a: i32, b: i32| a + b;
let sqr = |a: i32| a.pow(2);
let add_two = |a: i32| a + 2;
assert_eq!(chain(add, sqr)(2, 3), 25);
assert_eq!(
chain(
@berkus
berkus / playground.rs
Created August 2, 2019 15:24 — forked from rust-play/playground.rs
Code shared from the Rust Playground
use std::collections::hash_map::Entry;
use std::collections::HashMap;
trait EntryExt<'a, K, V>: 'a {
fn or_insert_with2<F: FnOnce(&K) -> V>(self, f: F) -> &'a mut V;
}
impl<'a, K, V> EntryExt<'a, K, V> for Entry<'a, K, V> {
fn or_insert_with2<F: FnOnce(&K) -> V>(self, f: F) -> &'a mut V {
match self {
# See https://news.ycombinator.com/item?id=20213092
FROM python:3
ARG VERSION=2.1.1.0
RUN pip install pytz passlib bcrypt radicale==$VERSION
ENV RADICALE_CONFIG /etc/radicale/config
RUN mkdir -p /etc/radicale
COPY config $RADICALE_CONFIG