Skip to content

Instantly share code, notes, and snippets.

View dangra's full-sized avatar
🦖

Daniel Graña dangra

🦖
View GitHub Profile
#include <assert.h>
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
void *handle;
int (*nvmlInit)(void);
char *error;
@dangra
dangra / remote
Created December 8, 2023 18:24 — forked from tavianator/remote
Remote access mkinitcpio hook
#!/bin/bash
add_user() {
getent passwd "$1" >>"$BUILDROOT/etc/passwd"
getent shadow "$1" >>"$BUILDROOT/etc/shadow"
getent group "$(id -Gn "$1")" >>"$BUILDROOT/etc/group"
}
build() {
add_systemd_unit cryptsetup-pre.target
@dangra
dangra / merge_vs_rebase_vs_squash.md
Created December 7, 2023 21:03 — forked from mitchellh/merge_vs_rebase_vs_squash.md
Merge vs. Rebase vs. Squash

I get asked pretty regularly what my opinion is on merge commits vs rebasing vs squashing. I've typed up this response so many times that I've decided to just put it in a gist so I can reference it whenever it comes up again.

I use merge, squash, rebase all situationally. I believe they all have their merits but their usage depends on the context. I think anyone who says any particular strategy is the right answer 100% of the time is wrong, but I think there is considerable acceptable leeway in when you use each. What follows is my personal and professional opinion:

Top
https://openwrt.org/toh/views/toh_available_16128?dataflt%5BWLAN%205.0GHz%2A~%5D=ax&dataflt%5B0%5D=device%20type_%3DWiFi%20Router
Belkin RT3200
https://openwrt.org/toh/linksys/e8450
Turris Omnia
https://openwrt.org/toh/turris/turris_omnia

Autofill OpenVPN OTP

On MacOS with Tunnelblick.

brew install oath-toolkit
mkdir ~/Documents/my-vpn.tblk
cp ~/Downloads/profile.ovpn ~/Documents/my-vpn.tblk/
printf "#!/bin/bash\n/usr/local/bin/oathtool --totp -b -d 6 {OTP_KEY_HERE}" > ~/Documents/my-vpn.tblk/static-challenge-response.user.sh
chmod +x ~/Documents/my-vpn.tblk/static-challenge-response.user.sh
@dangra
dangra / prom-k8s-request-limits.md
Created November 9, 2021 01:31 — forked from max-rocket-internet/prom-k8s-request-limits.md
How to display Kubernetes request and limit in Grafana / Prometheus properly

CPU: percentage of limit

A lot of people land when trying to find out how to calculate CPU usage metric correctly in prometheus, myself included! So I'll post what I eventually ended up using as I think it's still a little difficult trying to tie together all the snippets of info here and elsewhere.

This is specific to k8s and containers that have CPU limits set.

To show CPU usage as a percentage of the limit given to the container, this is the Prometheus query we used to create nice graphs in Grafana:

sum(rate(container_cpu_usage_seconds_total{name!~".*prometheus.*", image!="", container_name!="POD"}[5m])) by (pod_name, container_name) /
import scrapy
import asyncio
import aioredis
class MySpider(scrapy.Spider):
name = "asyncspider"
async def start_requests(self):
self.redis = await aioredis.create_connection("redis://localhost")
#!/bin/sh
set -e
SPIDER=$(echo "$SHUB_JOB_DATA" |jq -r .spider)
ARGS="$(echo "$SHUB_JOB_DATA" |jq -r '.spider_args|to_entries|.[]|"--\(.key)=\(.value)"')"
echo "$SPIDER" $ARGS
foo1 :~$ pip install 'https://github.com/scrapinghub/python-scrapinghub/archive/sc1467-1.zip#egg=scrapinghub==1.10.0dev0'
Processing ./Library/Caches/pip/wheels/d0/e8/cd/dab62ee79e76d94ca30817e60aeeba39eb33d6f52e0124720c/scrapinghub-1.10.0.dev0-py2-none-any.whl
Collecting six>=1.10.0 (from scrapinghub==1.10.0dev0)
Using cached six-1.10.0-py2.py3-none-any.whl
Collecting retrying>=1.3.3 (from scrapinghub==1.10.0dev0)
Collecting requests (from scrapinghub==1.10.0dev0)
Using cached requests-2.13.0-py2.py3-none-any.whl
Installing collected packages: six, retrying, requests, scrapinghub
Successfully installed requests-2.13.0 retrying-1.3.3 scrapinghub-1.10.0.dev0 six-1.10.0
You are using pip version 7.1.2, however version 9.0.1 is available.
494 "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36"
278 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36"
242 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36"
206 "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36"
192 "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36"
192 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36"
168 "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36"
148 "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36"
94 "Mozilla/5.0 (Window