Skip to content

Instantly share code, notes, and snippets.

@qknight
qknight / gist:0ec68e64634e3eb7b9f9d00691f22443
Last active March 27, 2025 13:05
clap + Figment (cli + config file + env variables) in rust
# clap + Figment
for command line switches like: program --help, program --input "asdf" i want to use `clap` and for config file
parsing like `pankat.toml` i want to use Figment.
after studying https://steezeburger.com/2023/03/rust-hierarchical-configuration/ i came up with my solution,
which is quite similar, except it splits the clap arguments into default values and explicit values for the later merge.
now i can either use:
# main.rs
#[macro_use]
extern crate html5ever;
extern crate markup5ever_rcdom as rcdom;
use html5ever::parse_document;
use html5ever::tendril::TendrilSink;
use rcdom::{Handle, NodeData, RcDom};
use std::io::Cursor;
@qknight
qknight / gist:53da44799935790d706a46d92916e72d
Created January 12, 2025 22:17
Using replit.com with ssh from the shell using access token jan-2025
[remote "origin"]
url = https://qknight:[email protected]/nixcloud/pankat-replit
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "main"]
remote = origin
merge = refs/heads/main
afterwards do:
@qknight
qknight / gist:6d2a06a00e03542087cfcbb3704fccb6
Last active December 8, 2024 09:54
This features two textareas in a horizontal layout which adapt their height to the content and sync the height among both textareas. It supports downsizing as well.
// This features two textareas in a horizontal layout which adapt their height to the content and
// sync the height among both textareas. It supports downsizing as well.
// It is also quite a hack but it works!
#[component]
pub fn DescriptionEdit(
description_source: RwSignal<String>,
description_destination: RwSignal<String>,
merge_ui_element_states: RwSignal<HashMap<&'static str, i32>>,
unique_name: &'static str,
@qknight
qknight / main.go
Last active August 1, 2022 14:51
Trying to get GORM with postgres to do relational requests
package main
import (
"fmt"
"gorm.io/driver/postgres"
"gorm.io/gorm"
"gorm.io/gorm/logger"
"log"
)
we want to use the environment you define below to pass in the local.py which contains the configuration for the database for django.
however, you code uses the preStart which we can't support in nixcloud-webservices in a similar way so we play with the environment variable called PYTHONPATH like shown below.
problem: our local.py configuration is never used, so we kindly ask you what we do wrong.
we also tried `manage.py`'s command line arguments as --pythonpath and --settings but we can't get them to work as python errors out because of not finding a module.
# our code
# wanting to package https://github.com/taigaio/taiga-back
pip2nix3 generate -r requirements.txt
/nix/store/363rkdz279i1ppiqha1f8vgh6a5p6xz9-python3.5-pip-9.0.1/lib/python3.5/site-packages/pip/cmdoptions.py:39: RemovedInPip10Warning: --no-use-wheel is deprecated and will be removed in the future. Please use --no-binary :all: instead.
fmt_ctl_no_use_wheel(control)
Collecting git+git://github.com/Python-Markdown/markdown.git (from -r requirements.txt (line 4))
Cloning git://github.com/Python-Markdown/markdown.git to /tmp/pip-gd8bpttj-build
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
# Gemfile.lock update of oj
git diff
diff --git a/Gemfile.lock b/Gemfile.lock
index 1b69af2..22b8fad 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -7,7 +7,7 @@ PATH
em-http-request (~> 0.3.0)
em-websocket (~> 0.5.1)
on ubuntu 18.04 LTS i do this:
gem install slanger
Building native extensions. This could take a while...
ERROR: Error installing slanger:
ERROR: Failed to build gem native extension.
current directory: /var/lib/gems/2.5.0/gems/oj-2.12.14/ext/oj
/usr/bin/ruby2.5 -r ./siteconf20180609-3115-hpt4bd.rb extconf.rb
# This Makefile is for the NetAddr::IP::Util extension to perl.
#
# It was generated automatically by MakeMaker version
# 7.1002 (Revision: 71002) from the contents of
# Makefile.PL. Don't edit this file, edit Makefile.PL instead.
#
# ANY CHANGES MADE HERE WILL BE LOST!
#
# MakeMaker ARGV: (q[PREFIX=/nix/store/gzbb4v0qg5vdfd3gpcjkyf4prkfzrhna-perl-NetAddr-IP-4.079], q[INSTALLDIRS=site], q[PERL=/nix/store/ggb7k5x9855j10dz99467djx4rplg32b-perl-5.24.3/bin/perl], q[FULLPERL=/nix/store/ggb7k5x9855j10dz99467djx4rplg32b-perl-5.24.3/bin/perl])
#