Skip to content

Instantly share code, notes, and snippets.

View algesten's full-sized avatar
😀
barcelona!

Martin Algesten algesten

😀
barcelona!
View GitHub Profile
@algesten
algesten / tmux.conf
Created May 14, 2017 08:30
A tmux.conf with pbcopy
# propagate titles to the window
set -g set-titles on
# Minimalist window title "0:bash"
set -g set-titles-string "#I:#W"
# show colors
set -g default-terminal "screen-256color"
@algesten
algesten / blah.rs
Created August 7, 2022 13:22
Unhelpful tracing macro error
use tracing::{info_span, Span};
pub struct Blah {
pub span: Span,
}
impl Blah {
pub fn new(name: &str) -> Self {
Blah {
span: info_span!(name),
stokast v0.1.0 (/Users/martin/dev/stokast)
├── alg v0.1.0 (/Users/martin/dev/alg)
│ ├── gcd v2.0.1
│ └── log v0.4.14
│ └── cfg-if v1.0.0
├── arrayvec v0.7.1
├── cortex-m v0.6.7
│ ├── aligned v0.3.5
│ │ └── as-slice v0.1.5
│ │ ├── generic-array v0.12.4
@algesten
algesten / aws.rs
Last active June 1, 2021 09:00
ureq aws sign
use chrono::{DateTime, Utc};
use hmac::{Hmac, Mac, NewMac};
use once_cell::sync::Lazy;
// notice this is percent_encoding=1.0.1 since I haven't bothered to
// fix this for latter versions of the crate.
use percent_encoding::{define_encode_set, utf8_percent_encode, SIMPLE_ENCODE_SET};
use sha2::{Digest, Sha256};
use std::env;
use std::fmt::Write;
@algesten
algesten / start-tmux.sh
Created May 14, 2017 07:59
start tmux in bashrc
# TMUX
# test if tmux is available
if type tmux >/dev/null 2>&1; then
# if not inside a tmux session, and if no session is started, start a new session
# I only want this on my mac laptop.
if [ -z "$TMUX" -a `uname` == Darwin ]; then
# attach to session "martin" if there
exec tmux -2 -f ~/.tmux-osx.conf new-session -A -s martin
fi
fi
@algesten
algesten / README.md
Last active April 10, 2018 12:17
Investigate CTFontCopyDefaultCascadeListForLanguages

Apple provides CTFontCopyDefaultCascadeListForLanguages to get a set of fallback font names for a certain ISO language code. I want to know how much these vary.

main.swift is a quick hack to dump a JSON of all codes with the fallbacks. The test assumes Menlo 12.0 as the starting point.

output.json is the full output from running the swift hack.

Finally I used nodejs to crunch the json to buckets that have different lists of fallbacks. code is in crunch.js

buckets.json has the result of running the crunch.

# Stateful
class MyComponent extends React.Component
constructor: (props) ->
super
render: =>
div class:'mycomponent', ->
span 'Hej'
const MyThing = () => {
return _react2.default.createElement('div',
_react2.default.createElement(Title),
_react2.default.createElement(Counter, {panda:42}),
_react2.default.createElement(ButtonCounterInc),
_react2.default.createElement(ButtonTitle)
);
};

Rust type conversions String, &str, Vec and &[u8]

From &str

  • &str -> String has [many equally valid methods][stringh]: String::from(st), st.to_string(), st.to_owned().
    • But I suggest you stick with one of them within a single project. The major advantage of String::from is that you can use it as an argument to a map method. So instead of x.map(|s| String::from(s)) you can often use x.map(String::from).
  • &str -> &[u8] is done by st.as_bytes()
  • &str -> Vec<u8> is a combination of &str -> &[u8] -> Vec<u8>, i.e. st.as_bytes().to_owned()

From String

@algesten
algesten / _stream-forensics.md
Last active November 27, 2016 11:22
Stream Forensics

Stream Forensics

A quick analysis of the event order for interconnected nodejs streams.

Whilst the events themselves are well documented, We wanted to find out exactly in what order events happen for interconnected streams where the readable stream ends (since this is different from reading from a never-ending input such as stdin).

input.pipe(middle).pipe(output)