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:

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
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
@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) /
@dangra
dangra / delayspider.py
Created May 24, 2012 14:04
Scrapy - delay requests in spider callbacks
from scrapy.spider import BaseSpider
from twisted.internet import reactor, defer
from scrapy.http import Request
DELAY = 5 # seconds
class MySpider(BaseSpider):
name = 'wikipedia'
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
@dangra
dangra / swpydaybot.py
Created December 26, 2011 01:57
scrapy's pydaybot at scraperwiki
import os, sys
import scraperwiki
from scrapy.spider import BaseSpider
from scrapy.selector import HtmlXPathSelector
from scrapy.contrib.loader import XPathItemLoader
from scrapy.contrib.loader.processor import MapCompose, Join
from w3lib.html import remove_tags, unquote_markup
from scrapy.item import Item, Field