Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
MY_NETWORK="192.168.2.0/24"
# Replace the ip address here with the ip address for your computer. You can use the programs "/sbin/ifconfig", or "/sbin/ip addr show".
MY_HOST="192.168.2.20"
# Network interfaces
IN=enp0s3
OUT=enp0s3
@anthager
anthager / transfer.sh
Last active April 14, 2020 10:40
Script for transferring files over ssh when scp is not available. Right now it only works with single files and single level directories and file permissions are ignored. You could prob do some fancy recursive shit for nested directories
#!/usr/bin/env bash
# $1 (first argument) should be the directory you want to transfer
set -e
tmp_file="tmp-file"
folder=""
path=""
[[ -e $tmp_file ]] && rm $tmp_file
[[ -d $1 ]] && path=$1 && folder=$(echo $path | rev | cut -d '/' -f 2 | rev) && echo "mkdir $folder" >>$tmp_file
@anthager
anthager / shit.c
Last active September 10, 2019 13:22
failed socket api for debug
/********************************************************* -- SOURCE -{{{1- */
/** Translate host name into IPv4
*
* Resolve IPv4 address for a given host name. The host name is specified as
* the first command line argument to the program.
*
* Build program:
* $ gcc -Wall -g -o resolve <file>.cpp
*/
#include <stdio.h>
@anthager
anthager / gcpr.sh
Last active September 3, 2019 21:33
Bash function for opening the url of a new pr of the current branch in the current repo, perfect for .(zsh|bash)rc
gcpr() {
if ! git remote show origin -n &>/dev/null; then
echo Not a repo m8
return 1
fi
open "https://github.com/$(git remote show origin -n | grep "Fetch URL:" | cut -d : -f 3 | cut -d . -f 1)/pull/new/$(git rev-parse --abbrev-ref HEAD)"
}
@anthager
anthager / make-.pem-single-line.sh
Created May 31, 2019 10:23
replace "hidden line breaks in a .pem file with \n"
awk 'NF {sub(/\r/, ""); printf "%s\\n",$0;}' ca.pem
@anthager
anthager / install-docker-debian.sh
Last active May 15, 2020 15:47
installs docker on debian
#!/usr/bin/env bash
set -e
sudo apt-get update
sudo apt-get -y install apt-transport-https ca-certificates curl gnupg2 software-properties-common
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get -y install docker-ce docker-ce-cli containerd.io
@anthager
anthager / commit_check.sh
Created February 25, 2019 22:47
bash script for checking if a folder has been changed since last commit
#!/usr/bin/env bash
cd -- "$(dirname "BASH_SOURCE")"
set -e
# latest commit
LATEST_COMMIT=$(git rev-parse HEAD)
pwd
# latest commit where path/to/folder1 was changed
FOLDER_COMMIT=$(git log -1 --format=format:%H --full-diff $1)
@anthager
anthager / frequency.js
Last active February 12, 2019 13:37
Koduppgift för sommarjobb hos Burt
function frequency(array) {
if (!array) throw new Error('input is not defined')
else if (typeof array !== 'object') throw new Error('input is not an array')
else if (!array.length) return []
const reducedArray = array.reduce((accumulator, current) => {
accumulator[current] = accumulator[current] !== undefined ? accumulator[current] + 1 : 1
return accumulator
}, {})