Skip to content

Instantly share code, notes, and snippets.

View MikaelFangel's full-sized avatar
🐮

Mikael Fangel MikaelFangel

🐮
View GitHub Profile
@MikaelFangel
MikaelFangel / getIndexesOfLetters.kt
Last active November 28, 2022 10:36
Get the indexes of all letters in a given word as a list of integers
/**
* Searches for all indexes of a given character in a word. The search is not case sensitive.
* @param c the char to search for
* @param word the word to look in
* @return list with indexes where the char matches
*/
fun getIndexesOfLetters(c: Char, word: String): List<Int> {
return word
.lowercase()
.withIndex()
@MikaelFangel
MikaelFangel / fork_exec.c
Last active December 26, 2022 23:09
Unix fork-exec technique
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
void fork_exec(void)
{
switch (fork())
{
case -1: // Error
@MikaelFangel
MikaelFangel / print_range.awk
Created February 3, 2023 11:53
Print a range of columns in a csv file using awk
#!/usr/bin/awk -f
BEGIN {
FS=",";
first_index = 1;
last_index = 3;
}
{
for(i = first_index; i <= last_index; i++) {
@MikaelFangel
MikaelFangel / search_path.sh
Created February 8, 2023 18:25
Search the path environment variable in bash with find
find $(echo $PATH | sed 's/:/ /g') -type f -name 'ls'
@MikaelFangel
MikaelFangel / null-ls.lua
Created April 9, 2023 20:57
Nvim Go null-ls configuration with lsp, linter and auto imports
local present, null_ls = pcall(require, "null-ls")
if not present then
return
end
local b = null_ls.builtins
local sources = {
b.formatting.gofumpt,
@MikaelFangel
MikaelFangel / lockscreen.sh
Last active April 10, 2023 20:08
Blurred lockscreen using swaybg
#------------------------------------#
# Get the blurred lock screen effect #
# using swaybg, grim and ffmpeg on #
# wayland. #
#------------------------------------#
#!/bin/env bash
path=/tmp/tmpbg.png
pathout=/tmp/tmpbgblur.png
@MikaelFangel
MikaelFangel / read2DCharArray.fs
Last active September 11, 2023 14:46
How to read 2D array from console in F#
open System
// Create a rectangular array of chars
let read2DCharArray rowCount colCount =
let rows = [| for _ in 1 .. rowCount -> Console.ReadLine() |> Array.ofSeq |]
Array2D.init rowCount colCount (fun i j -> rows[i][j])
// Create a jagged array of chars
let read2DCharArrayJagged rows =
[| for _ in 1 .. rows -> Console.ReadLine() |> Array.ofSeq |]

makeWrapper and wrapProgram

Nix generally assumes run-time dependencies is a subset of the build-time dependencies.

This means many Nix builder functions try to automatically scan the output for runtime dependencies and "rewrite" them for runtime usage.

However shell scripts which are often exported by packages do not get this automatic scanning treatment.

This means you have to use the makeWrapper package and use either the makeWrapper or wrapProgram utility functions.

@MikaelFangel
MikaelFangel / oldclifix.md
Last active October 2, 2023 14:05
HowTo: Use old Nix-Cli on flakyfied system

Fix for one command only

nix-build flake:nixpkgs -A hello
nix-build -I nixpkgs=flake:github:NixOS/nixpkgs/nixos-23.05 '<nixpkgs>' -A hello
NIX_PATH=nixpkgs=flake:nixpkgs nix-build '<nixpkgs>' -A hello

Fix it decleratively

@MikaelFangel
MikaelFangel / flake.nix
Last active November 24, 2023 10:58
Simple F# devshell for direnv
{
description = "F# DevShell";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils, ... }@inputs:
flake-utils.lib.eachDefaultSystem (system: