Skip to content

Instantly share code, notes, and snippets.

View guss77's full-sized avatar

Oded Arbel guss77

View GitHub Profile
@guss77
guss77 / reset-tb
Last active April 11, 2024 05:11
Script to reset the XHCI of a Thunderbolt connection in case the kernel stops it
#!/bin/bash
# As described in https://bugs.launchpad.net/bugs/1766076
### Installation Instructions:
# 1. Install file into `/usr/local/bin/reset-tb`
#
# 2. Optional: allow password less sudo by creating a file `/etc/sudoers.d/allow-reset-tb` with the following content:
# ----8<-----
# <your username> ALL = NOPASSWD: /usr/local/bin/reset-tb
# ----8<-----
#
@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
#!/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() {
@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
#!/bin/bash
function usage() {
(
echo "usage: $0 <auth-token> <group-address> <mbox-dir>"
echo "To generate an auth token go to https://developers.google.com/oauthplayground/ and get an access token for Google Groups migration"
) >&2
exit 5
}
@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 / 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 / mongo_db_recover_delete_record-2.4.py
Last active August 26, 2022 05:52
Try to recover deleted documents from a mongodb 2.4 data file. Based on https://gist.github.com/egguy/2788955 with help from https://yazadk.wordpress.com/2015/07/15/a-forensic-perspective-on-recovering-deleted-data-from-big-data-systems/#MongoDB . Make sure to change `decode_chunk` so it properly detects the objects you are trying to recover - i…
#!/usr/bin/python
"""A little script to recover deleted recording of a mongoDB db file
There's no optimization but it work and has saved me
"""
import struct
import bson
import pymongo
@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 / cloud-formation-computed-variables.yaml
Last active February 18, 2022 15:45
Computed variables for CloudFormation using an identity function, as by @claude on StackOverflow (https://serverfault.com/a/812040/6438)
##
#
# Custom resource setup to provide an identity function that can be used to
# implement "custom variables".
# See: https://serverfault.com/a/812040/6438
#
# Usage:
#
# After deploying the below code to your stack, you can define computed
# variables thus: