Skip to content

Instantly share code, notes, and snippets.

View michelesr's full-sized avatar

Michele Sorcinelli michelesr

View GitHub Profile
I0526 12:01:28.722410 270 loader.go:242] Config loaded from file /tmp/.kube/config
I0526 12:01:28.722930 270 round_trippers.go:264] GET https://192.168.7.60:8443/oapi
I0526 12:01:28.722944 270 round_trippers.go:271] Request Headers:
I0526 12:01:28.722951 270 round_trippers.go:274] Accept: application/json, */*
I0526 12:01:28.722957 270 round_trippers.go:274] User-Agent: oc/v1.1.4 (linux/amd64) openshift/3941102
I0526 12:01:28.722964 270 round_trippers.go:274] Authorization: Bearer jxtjZKCU-3BJG0OhhZvieFfKQw65j2ucisUNNHANGRc
I0526 12:01:28.990112 270 round_trippers.go:289] Response Status: 200 OK in 267 milliseconds
I0526 12:01:28.990134 270 round_trippers.go:292] Response Headers:
I0526 12:01:28.990140 270 round_trippers.go:295] Date: Thu, 26 May 2016 12:01:28 GMT
I0526 12:01:28.990146 270 round_trippers.go:295] Content-Length: 93
@michelesr
michelesr / vlc-inhibit-screensaver.sh
Created March 24, 2019 20:42
Script to inhibit xscreensaver when VLC is playing
#!/bin/bash
SLEEP_TIME=${1:-4m}
while true; do
if [[ $(qdbus org.mpris.MediaPlayer2.vlc /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlaybackStatus) == 'Playing' ]]; then
# tell xscreensaver to pretend there has been user activity
xscreensaver-command -deactivate
fi
sleep ${SLEEP_TIME}
done
@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
@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 / 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 / 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 / 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 / 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 / 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 / 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))))))