Skip to content

Instantly share code, notes, and snippets.

View michelesr's full-sized avatar

Michele Sorcinelli michelesr

View GitHub Profile
@michelesr
michelesr / hexdump.c
Last active October 4, 2025 19:38
Simple xxd like implementation of hexdump in ANSI C
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdint.h>
#include <errno.h>
int main(int argc, char *argv[]) {
FILE *file = stdin; /* file to read, default to stdin */
char text[17]; /* text representation of the 16 bytes line */
int n; /* number of bytes read in the line */
@michelesr
michelesr / colima-setup.sh
Created April 6, 2025 18:36
Colima docker+k3s+ingress+dns setup script
# NOTES
# minikube is used as internal domain for ingress, feel free to change it
# it's just to make it work with apps that were using that domain in minikube
# but it could be anything really
echo 'Installing colima'
brew install colima
echo 'Starting VM'
colima start --cpu=8 --memory=8 --disk=100 --vm-type vz --kubernetes --network-address
@michelesr
michelesr / lambda_calculus.scm
Created January 16, 2025 00:27
Boolean logic and Church numerals in Scheme
(define (true a b) a)
(define (false a b) b)
(define (not b) (b false true))
(define (and a b) (a b false))
(define (or a b) (a true b))
(define zero (lambda (f) (lambda (x) x)))
(define one (lambda (f) (lambda (x) (f x))))
(define two (lambda (f) (lambda (x) (f (f x)))))
(define three (lambda (f) (lambda (x) (f (f (f x))))))
@michelesr
michelesr / lamdba_calculus.py
Created January 15, 2025 22:41
Boolean logic and church numerals in python
# Boolean logic
def true(a, _):
return a
def false(_, b):
return b
def not_f(b):
return b(false, true)
@michelesr
michelesr / epoll_tcp_server.c
Last active August 8, 2024 20:19
Example epoll event loop based TCP server
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <sys/epoll.h>
#define BUFFER_SIZE 256
@michelesr
michelesr / nvidia_on.sh
Created March 19, 2022 21:11
Turn NVIDIA discrete card on
#!/bin/bash
set -ex
CONTROLLER_BUS_ID=0000:00:01.0
DEVICE_BUS_ID=0000:01:00.0
sudo tee /sys/bus/pci/devices/${CONTROLLER_BUS_ID}/power/control <<<on
sleep 1
sudo tee /sys/bus/pci/rescan <<<1
@michelesr
michelesr / nvidia_off.sh
Created March 19, 2022 21:10
Turn NVIDIA discrete card off on Linux
#!/bin/bash
set -ex
CONTROLLER_BUS_ID=0000:00:01.0
DEVICE_BUS_ID=0000:01:00.0
if sudo lsof /dev/nvidia0 ; then
echo 'Some processes are still using the card, aborting.'
exit 1
fi
@michelesr
michelesr / refresh-minikube-ecr-credentials.sh
Last active April 19, 2021 12:35
Update minikube registry-creds plugin to use latest temporary credentials from MFA profile
#!/bin/bash
# Use the temporary credentials from the MFA profile to update the
# registry-creds plugin credentials used to pull images from AWS Elastic
# Container Registry
#
# NOTE: the script won't request fresh credentials, make sure your credentials
# are not expired before running this script
# retrieve the profile from the credentials file
content=$(grep -F -A 5 '[mfa]' < ~/.aws/credentials)
@michelesr
michelesr / gist:8c5bae9d840b00a1bcf7a4fdef7f0632
Last active January 5, 2021 16:23
Update EKS managed nodegroups
#!/usr/bin/env bash
set -eux
# used to process output with awk
export AWS_DEFAULT_OUTPUT=text
disable_cluster_autoscaler() {
# delete the tag from the autoscaling group
aws autoscaling delete-tags \
--tags ResourceId=$1,ResourceType=auto-scaling-group,Key=k8s.io/cluster-autoscaler/enabled
@michelesr
michelesr / find-orphan-pods.rb
Last active March 6, 2020 11:29
Find pods which IP is not part of a ENI attached to the one of the cluster EC2 instances (for AWS CNI plugin)
#!/usr/bin/env ruby
require "json"
require "aws-sdk-ec2"
# Usage: bundle exec ruby find-orphan-pods.rb <cluster-name>
# NOTE: make user to point kubectl to the right context!
#
# Returns a list of pods which aren't using an attached ENI and so don't have
# network connectivity