Skip to content

Instantly share code, notes, and snippets.

@cl4u2
cl4u2 / repomirror.sh
Created July 27, 2020 13:59
One-way mirror of a github repository into a gitlab repository
#!/bin/bash
REPONAME=$1
SRCURL=$2
DSTURL=$3
if [ -z "$DSTURL" ]; then
echo "Usage: $0 <repository name> <github URL> <gitlab SSH URL>"
exit 1
fi
@cl4u2
cl4u2 / findcontainer.sh
Created May 12, 2020 07:40
Find the Docker container running the process with the specified process ID (PID) (as seen from the Docker host)
#!/bin/bash
targetpid=$1
parentpid=0
while [ $parentpid != 1 ]; do
parentpid=$(ps -o ppid= $targetpid)
docker ps -q | xargs docker inspect --format '{{.State.Pid}}, {{.Name}}' | grep "^$parentpid"
targetpid="$parentpid"
done
@cl4u2
cl4u2 / sync-projects
Last active September 27, 2018 14:49 — forked from JonasGroeger/sync-projects
Gitlab: Clone / Pull all projects in a group
#!/usr/bin/env bash
# Documentation
# https://docs.gitlab.com/ce/api/projects.html#list-projects
BASE_PATH="https://gitlab.example.com/"
PROJECT_SEARCH_PARAM=""
PROJECT_SELECTION="."
PROJECT_PROJECTION="{ "path": .path_with_namespace, "git": .ssh_url_to_repo, "namespace": .namespace.full_path }
@cl4u2
cl4u2 / git-log-to-tikz.rb
Last active October 25, 2020 19:42 — forked from lckarssen/git-log-to-tikz.rb
Extract git history to tikz picture - complete latex document and minimal graph
#!/usr/bin/env ruby
# A small ruby script to extract a git history to a tikz picture
# Author: Michael Hauspie <[email protected]>
# Author: Lennart C. Karssen <[email protected]>
# Author: Claudio Pisa <[email protected]>
#
# Not clean code, not always working well, but does its job in most of
# the cases I needed :)
#
#!/bin/bash
TARGET_IPK=$1
if [ -z "$1" ]; then
echo "Usage: $0 <target ipk>"
exit 1
fi
LOCALDIR="$(pwd)"
@cl4u2
cl4u2 / phpipamapitest.py
Created May 7, 2017 15:29
PHPIPAM API usage basic example in Python
import requests
import json
server = "https://ipam.ninux.org"
appid = "appid"
username = "username"
password = "password"
baseurl = server + "/api/" + appid
@cl4u2
cl4u2 / iptablesnet.sh
Last active May 20, 2022 07:36
cheap network emulation with Linux network namespaces
#!/bin/bash
# emulate a 3 nodes network using Linux network namespaces
# n1 -- r0 -- n2
set -x
# cleanup
ip netns del n1
ip netns del r0
#!/bin/bash
DB_ROOT_USER=root
DB_ROOT_PASS=root
set -e
set -x
cat - <<EOF > /tmp/db_test0.sql
DROP DATABASE IF EXISTS vim_test0;
@cl4u2
cl4u2 / mousejail.sh
Created February 10, 2015 09:49
jail the mouse to a specific rectangle. Based on xdotool.
#!/bin/bash
SLEEPTIME=0.2
# JAIL PARAMETERS
MAXX=1024
MAXY=768
BOUNDSCREEN=0
while true; do
@cl4u2
cl4u2 / del_first_lines.lua
Created September 11, 2014 14:55
Delete first n lines of a string
function del_first_lines(astring, n)
-- parameters: string and number of initial lines to be deleted
local result = ""
local deleted = n
local newfirst = true
for line in astring:gmatch("[^\r\n]+") do
if deleted > 0 then
deleted = deleted - 1
else
if newfirst then