Skip to content

Instantly share code, notes, and snippets.

View rksm's full-sized avatar
🏗️

Robert Krahn rksm

🏗️
View GitHub Profile
@rksm
rksm / sequenctial_id_alloc.rs
Created August 27, 2024 23:53
generic SequentialIdAlloc
use bitvec::prelude::*;
/// A simple sequential id allocator.
///
/// The allocator will allocate new ids sequentially from 0 to u8::MAX. Unlike
/// other bitmap / slab allocators, freed ids will not be reused right away,
/// only when the next id pointer wraps around.
pub struct SequentialIdAlloc<const MAX: usize, T = u8, U = BitArr![for 255, in u8]> {
next_ptr: usize,
@rksm
rksm / clonezilla.md
Created March 11, 2024 23:07
clonezilla

Using Clonezilla to create and restore a hard drive snapshot is a multi-step process that involves booting into a Clonezilla environment, creating the image, and then later restoring it. Clonezilla should handle copying the EFI partition and setting up the bootloader, but additional steps may be required if you're restoring to a new drive. Here’s how you do it:

Creating a Snapshot:

  1. Download Clonezilla: Go to the Clonezilla website and download the appropriate Clonezilla live CD/USB image.
  2. Create Bootable Media: Burn the downloaded ISO to a CD or use a tool like dd or Rufus to create a bootable USB stick.
  3. Boot Into Clonezilla: Insert the bootable Clonezilla media into your computer and boot from it. You may need to select the boot device or change the boot order in your BIOS/UEFI settings.
  4. Choose Language and Keyboard: Select your preferred language and keyboard layout in the Clonezilla menu.
  5. Start Clonezilla: Select "Start Clonezilla".
  6. Select Mode: Choose "de
@rksm
rksm / streaming-command.rs
Created March 9, 2024 12:04
streaming rust command with tokio
async fn run_speechpipeline_command(
job: Job,
) -> Result<(
mpsc::Receiver<Either<String, Result<Response>>>,
tokio::sync::oneshot::Sender<()>,
)> {
let payload = serde_json::to_string(&job)?;
let payload = shellwords::escape(&payload);
let cmd = format!(
@rksm
rksm / elpy-fixes.el
Created January 6, 2024 04:28
Fix for `M-x elpy-doc`
(use-package elpy
:ensure
:demand flycheck
:init (elpy-enable)
:config
(advice-add 'elpy-doc :around #'rk/elpy-doc-fallback-to-help))
;; help from python, see https://github.com/jorgenschaefer/elpy/pull/1509 and
;; https://github.com/jorgenschaefer/elpy/issues/1507
(defun rk/elpy-doc-get-docstring-from-shell ()
@rksm
rksm / init-org-ai.el
Last active April 18, 2023 10:30
init script for org-ai.el: https://github.com/rksm/org-ai
;; -*- no-byte-compile: t; -*-
;; -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;; org-ai-mode
(use-package org-ai
:ensure t
:commands (org-ai-mode
org-ai-global-mode)
:init
(defun rk/get-ffmpeg-device ()
"Gets the list of devices available to ffmpeg.
The output of the ffmpeg command is pretty messy, e.g.
[AVFoundation indev @ 0x7f867f004580] AVFoundation video devices:
[AVFoundation indev @ 0x7f867f004580] [0] FaceTime HD Camera (Built-in)
[AVFoundation indev @ 0x7f867f004580] AVFoundation audio devices:
[AVFoundation indev @ 0x7f867f004580] [0] Cam Link 4K
[AVFoundation indev @ 0x7f867f004580] [1] MacBook Pro Microphone
so we need to parse it to get the list of devices.
The return value contains two lists, one for video devices and one for audio devices.
@rksm
rksm / time_limiter.rs
Created August 19, 2022 12:08
Frequency counter / limiter
use std::time::{Duration, Instant};
/// Records the time when [`TimedLimiter::too_frequent`] was called. If this
/// gets called `N` times with a duration of less then `delay`, this method will
/// return `true`, otherwise `false`.
///
/// This is useful to make sure something does not get invoked too frequently.
pub(crate) struct TimedLimiter<const N: usize> {
delay: Duration,
last_changes: [Option<Instant>; N],
let req = ListenRequest {
database: db.clone(),
labels: HashMap::new(),
target_change: Some(TargetChange::AddTarget(Target {
target_id: 0x52757374,
once: false,
target_type: Some(TargetType::Documents(DocumentsTarget {
documents: vec![users_collection],
})),
resume_type: None,
@rksm
rksm / main.rs
Last active October 27, 2021 15:34
rust firestore streaming
use anyhow::Result;
use myclient::gcloud;
use firestore_grpc::tonic::codegen::InterceptedService;
use firestore_grpc::tonic::metadata::MetadataValue;
use firestore_grpc::tonic::transport::{Channel, ClientTlsConfig};
use firestore_grpc::tonic::{Request, Status};
use firestore_grpc::v1::firestore_client::FirestoreClient;
use firestore_grpc::v1::listen_request::TargetChange;
use firestore_grpc::v1::structured_query::CollectionSelector;
@rksm
rksm / init.el
Last active May 31, 2021 23:47
small init.el
(defvar rk/backup-dir (expand-file-name "backup" user-emacs-directory))
(unless (file-exists-p rk/backup-dir)
(mkdir rk/backup-dir))
(setq
backup-by-copying t ; don't clobber symlinks
delete-old-versions t
kept-new-versions 6
kept-old-versions 2