Skip to content

Instantly share code, notes, and snippets.

View ugovaretto's full-sized avatar

Ugo Varetto ugovaretto

View GitHub Profile
@ugovaretto
ugovaretto / config.toml
Last active May 28, 2023 13:34
helix configuration
theme = "tokyonight"
[editor]
line-number = "relative"
mouse = false
bufferline = "multiple"
rulers = [80]
[editor.statusline]
right = ["diagnostics", "selections", "position", "position-percentage", "file-encoding", "file-line-ending", "file-type"]
# Set prefix (Ctrl+a)
set-option -g prefix C-a
unbind-key C-a
bind-key C-a send-prefix
# Use Alt-arrow keys to switch panes (Alt+left/right/up/down)
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D
@ugovaretto
ugovaretto / result-example.cpp
Last active May 4, 2025 08:02
Rust-style C++ Result implementation, supporting references
// Implementation of Result<Result,Error> type a la Rust.
// author: Ugo Varetto
// License: Zero-clause BSD
// SPDX identifier: 0BSD
#include "result.h"
//-----------------------------------------------------------------------------
Result<int, std::string> Foo(int i) {
if (i == 0) {
return Err(std::string("Error"));
} else {
@ugovaretto
ugovaretto / sha256.c
Last active April 26, 2023 13:56
SHA256 implementation
// sha256.c - SHA256 reference implementation
//
//-----------------------------------------------------------------------------
#include <assert.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//-----------------------------------------------------------------------------
cabal-version: 3.4
-- The cabal-version field refers to the version of the .cabal specification,
-- and can be different from the cabal-install (the tool) version and the
-- Cabal (the library) version you are using. As such, the Cabal (the library)
-- version used must be equal or greater than the version stated in this field.
-- Starting from the specification version 2.2, the cabal-version field must be
-- the first thing in the cabal file.
-- Initial package description 'y' generated by
-- 'cabal init'. For further documentation, see:
@ugovaretto
ugovaretto / heic2jpeg.hs
Created April 16, 2023 14:52
Convert HEIC to JPEG (Haskell version)
import System.Directory
import System.FilePath
import Control.Monad
import System.Process
import Data.Char
main = do
c <- listDirectory "."
f <- filterM (\x -> return (map toLower (snd(splitExtension x)) == ".heic")) c
mapM (\x -> callProcess "convert" [x, (dropExtension x) ++ ".jpg"]) f
@ugovaretto
ugovaretto / hibernate-wol-magic.sh
Created February 11, 2023 11:44
Enable wake-on-lan magic packet before hibernating
#!/usr/bin/env bash
# run with sudo
ethtool -s enp8s0 wol g
systemctl hibernate
@ugovaretto
ugovaretto / 50-wired.link
Created February 11, 2023 11:42
Make Wake-on-line on magic packet persistent
@ugovaretto
ugovaretto / Convert from heic to jpg
Last active November 28, 2022 07:19
heic2jpg.rs
#!/usr/bin/env rust-script
use std::{
env, fs,
io::{self, Error, ErrorKind},
};
fn main() -> io::Result<()> {
let d = env::args()
.nth(1)
.ok_or(Error::new(ErrorKind::Other, "Missing argument"))?;
@ugovaretto
ugovaretto / heic2jpg.d
Last active October 15, 2022 02:21
Convert HEIC to JPG
#!/usr/bin/env rdmd
int convert(string path) {
import std.file, std.algorithm, std.path, import std.parallelism;
import std.process : execute
import std.uni: toLower;
auto dFiles = dirEntries(path, SpanMode.breadth).filter!(f=>f.name.toLower.endsWith(".heic"));
foreach (d; parallel(dFiles)) {
auto f = d.name;
auto status = execute(["convert", f.baseName, f.baseName ~ ".jpg"]);
if (status.status != 0) return status.status;