Skip to content

Instantly share code, notes, and snippets.

View guss77's full-sized avatar

Oded Arbel guss77

View GitHub Profile
@guss77
guss77 / lunar-base.list
Created September 19, 2023 11:11
Ubuntu lunar sources
deb http://archive.ubuntu.com/ubuntu lunar main restricted
deb-src http://il.archive.ubuntu.com/ubuntu/ lunar main restricted
deb http://archive.ubuntu.com/ubuntu lunar-updates main restricted
deb-src http://il.archive.ubuntu.com/ubuntu/ lunar-updates main restricted
deb http://archive.ubuntu.com/ubuntu lunar universe
deb-src http://il.archive.ubuntu.com/ubuntu/ lunar universe
deb http://archive.ubuntu.com/ubuntu lunar-updates universe
@guss77
guss77 / powerdraw
Last active March 8, 2024 13:43
Show total current power draw of the PC on Linux, using powercap
#!/bin/bash
#
# Installation:
# 1. put this script somewhere in your path - `/usr/local/bin/powerdraw` is probably
# a good idea.
# 2. Give the script execution permissions, e.g. `sudo chmod a+x /usr/local/bin/powerdraw`
# 3. Optional - add a sudoers file to allow users to execute this file without typing their
# password over and over. For example, create `/etc/sudoers.d/allow-powerdraw` with the
# following content:
# %admin ALL = NOPASSWD: /usr/local/bin/powerdraw, /usr/local/bin/powerdraw -f
@guss77
guss77 / read-plasma-wallpaper
Last active March 13, 2023 20:53
Bash script that reports the currently set KDE Plasma wallpaper, on the specified (or current) activity and screen. Supports the Image and Slideshow plugins and can complain correctly about the POTD plugin.
#!/bin/bash
##
# Helper to find the user configured name of an activity, by its ID
function getActivityName() {
qdbus org.kde.ActivityManager /ActivityManager/Activities \
org.kde.ActivityManager.Activities.ActivityName "$1"
}
##
@guss77
guss77 / RateLimiter.java
Last active July 19, 2023 06:47
Counter based rate limiter class for Java.
package coil.geek;
import java.util.concurrent.atomic.AtomicLong;
/**
* A token-based rate limiter, inspired by https://stackoverflow.com/a/55349487/53538
*
* The original implementation boasts an O(1) time complexity as well as O(1) space complexity, but controls
* concurrency using synchronization. This implementation uses atomic operations to offer lock-less concurrency
* and reentrancy.
@guss77
guss77 / VertxFutureTest.java
Created August 14, 2022 16:30
Vert.x Future onSuccess/onFailure do not propagate errors
package testing;
import io.vertx.core.Future;
import io.vertx.core.Promise;
import io.vertx.core.Vertx;
public class VertxFutureTest {
static Object waiter = new Object();
static boolean done = false;
@guss77
guss77 / vertx-hazelcast-cluster-on-fargate-ecs.md
Last active November 18, 2021 17:26
Vert.x Hazelcast Cluster on AWS Fargate

Introduction

I ran into a some problems trying to deploy a Vert.x based HTTP service, using Hazelcast as the cluster manager, on AWS ECS Fargate (a container orchestration service where you deploy docker containers without worrying about the underlying virtual machines - kind of like Kubernetes, but simpler perhaps?).

Some Problems

Hazelcast has good documentation on their website on using Hazelcast on AWS ECS, but all of it assumes that you are configuring the cluster with their YAML configuration language - which unfortunately doesn't

@guss77
guss77 / sevenboom2.cpp
Created August 7, 2021 13:10
"Improved" seven boom by `hasSeven()` being a one op and only the first digit tracking divisibility
#include <memory>
#include <ranges>
#include <iostream>
class Digit {
unsigned char val;
std::unique_ptr<Digit> moreSignificant;
static unsigned int sevens;
public:
Digit(unsigned char startVal) : val(startVal) {}
@guss77
guss77 / sevenboom.cpp
Last active August 7, 2021 13:09
Seven boom game by tracking each decimal digit separately instead of looking at the actual number and computing
#include <memory>
#include <ranges>
#include <iostream>
class Digit {
unsigned char val, sevenCount;
std::unique_ptr<Digit> moreSignificant;
public:
Digit(unsigned char startVal) : val(startVal), sevenCount(startVal % 7) {}
void inc() {
@guss77
guss77 / azure-rest-api-auth.sh
Last active April 19, 2021 22:05
Create a shared key for Azure storage REST API
#!/bin/bash
# Based on https://docs.microsoft.com/en-us/azure/storage/common/storage-rest-api-auth
function GetCanonicalizedResource() {
local address="$1" storageAccountName="$2"
echo -n "/${storageAccountName}$(cut -d? -f1 <<<"$address")"
cut -d? -f2- <<<"$address" | tr '&' '\n' | (while IFS="=" read key val; do printf '\n%s:%s' "$key" "$val"; done)
}
#!/bin/bash -e
verbosity=info
tokfile="/tmp/tok-$$"
domlist_pfx="/tmp/doms-$$-"
doctl_tokens=(
# Place all your DO personal access tokens here in this array as simple text, preferably one per line
)
function log() {