Skip to content

Instantly share code, notes, and snippets.

View sassman's full-sized avatar
🦀
rust ❤️

Sven Kanoldt sassman

🦀
rust ❤️
View GitHub Profile
@sassman
sassman / cargo-bump
Last active June 21, 2024 10:54
update rust dependencies minor versions made easy
#!/usr/bin/env bash
## USAGE:
## - put this file into your $PATH e.g. /usr/local/bin
## - make it executable: chmod a+x /usr/local/bin/cargo-bump
## - in your rust project just call: cargo bump
BAK_BRANCH=$(git branch --show-current)
B=chore/update-minor-versions-$(date +'%Y-%m-%d')
@sassman
sassman / stuff.sh
Created December 20, 2020 20:47
Useful ssh-key stuff
# convert an ssh key to pem format
ssh-keygen -f ~/.ssh/id_rsa.pub -e -m pem > ~/.ssh/id_rsa.pub.pem
@sassman
sassman / get-win.c
Created October 4, 2020 22:08
[MacOS] How to retrieve the window list and print all dict values
#include <Carbon/Carbon.h>
// compile with:
// clang -framework carbon get-win.c -o get-win
int main(int argc, const char *argv[]) {
CGWindowListOption options = kCGWindowListOptionOnScreenOnly | kCGWindowListExcludeDesktopElements;
CFArrayRef windows = CGWindowListCopyWindowInfo(options, kCGNullWindowID);
CFIndex count = CFArrayGetCount(windows);
@sassman
sassman / App.svelte
Last active February 21, 2023 22:19
Timer in svelte
<script>
let s = 0;
let m = 0;
let active = false;
let timer;
function setActive(a) {
active = a;
if(!active) {
clearInterval(timer)
@sassman
sassman / list_for_article.rs
Created May 3, 2020 14:51
little rust starter hint series: lifetimes made easy
#[derive(Debug)]
pub struct List {
head: Link,
}
#[derive(Debug)]
pub struct Node {
next: Link,
data: i32,
}
@sassman
sassman / Dockerfile
Created February 26, 2020 12:04
Rust webapp dockerization template for static binary with musl libc
FROM rust:latest as builder
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
musl-tools
RUN rustup target add x86_64-unknown-linux-musl
RUN rustup component add clippy
WORKDIR /x
@sassman
sassman / alphabet_position_test.rs
Created September 8, 2019 22:29
rust tdd: test/alphabet_position_test.rs
// test/alphabet_position_test.rs
use dev_challenge_47::alphabet_position; // <-- we don't have this function yet
#[test] // <-- how to define a test in rust
fn it_should_replace_the_a_with_1() { // <-- we express the requirement as name
let replaced = alphabet_position("a");
assert_eq!(replaced, "1"); // <-- we assert that the both are equal
}
@sassman
sassman / lib.rs
Created September 8, 2019 22:29
rust tdd: src/lib.rs
// src/lib.rs
pub fn alphabet_position(s: &str) -> String {
String::from("Hello")
}
@sassman
sassman / lib.rs
Created September 8, 2019 22:28
rust tdd: src/lib.rs
// src/lib.rs
pub fn alphabet_position(s: &str) -> String {
s.chars() // <-- get an iterator over all chars
.map(|x| -> u8 { x as u8 - 'a' as u8 + 1 }) // <-- substract the ascii value of 'a'
.map(|x| -> String { x.to_string() }) // <-- convert the char to a String
.collect::<Vec<String>>() // <-- collect a Vector of String
.join(" ") // <-- join the Strings by whitespace
}
@sassman
sassman / alphabet_position_test.rs
Created September 8, 2019 22:27
rust tdd: test/alphabet_position_test.rs
// test/alphabet_position_test.rs
#[test]
fn it_should_replace_the_capital_a_with_1() {
let replaced = alphabet_position("A");
assert_eq!(replaced, "1");
}