Skip to content

Instantly share code, notes, and snippets.

View craig-m's full-sized avatar
💾

C craig-m

💾
View GitHub Profile
@craig-m
craig-m / block hosts
Last active November 27, 2020 23:38
methods on linux to block a host/network
# some methods on *nix systems to block a host/network
# set a bogus arp address (for IPs in local subnet only)
arp -s 192.168.1.10 00:00:00:00:00:01
# blackhole this subnet
ip route add blackhole 192.168.2.0/24
@craig-m
craig-m / apparmor_uboot.txt
Last active June 30, 2020 05:54
Enable AppArmor in Debian/Ubuntu on BeagleBone and Lime boards
--------------------------------------------------------------------------------------------------------
# Enable apparmor in Debian on BeagleBoneBlack. Tested on
#
# image: bone-debian-9.5-iot-armhf-2018-10-07-4gb.img
# system: BeagleBone Black (AM335x 1GHz ARM® Cortex-A8)
root@beaglebone:~# apt-get install -y apparmor apparmor-utils
root@beaglebone:~# aa-status
@craig-m
craig-m / slack_mp3_log_post.sh
Created November 27, 2018 02:47
tail a file and post to a slack chan
#!/bin/bash
tail -n0 -F "/var/log/mpdscribble/play.log" | while read LINE; do
(echo "$LINE" | grep -e "$3") && curl -X POST --silent --data-urlencode \
"payload={\"channel\": \"#mp3-play\", \"username\": \"my-jukebox\", \"icon_emoji\": \":speaker:\",\"text\": \"$(echo $LINE | cut -d " " -f2- | sed "s/\"/'/g")\"}" "https://hooks.slack.com/services/zz/zz/zz";
done
@craig-m
craig-m / gist:df4250bd95849581cbcfb9eaf690bb65
Created November 27, 2018 02:44
disable onboard LEDs on beaglebone
sudo sh -c "echo none > /sys/class/leds/beaglebone\:green\:usr0/trigger"
@craig-m
craig-m / ufw_install.sh
Last active December 12, 2018 13:18
simple inbound/outbound UFW for debian linux
#!/bin/bash
apt-get install -y ufw;
# default
ufw default deny outgoing
ufw default deny incoming
# inbound
ufw allow 8080/tcp
@craig-m
craig-m / .screenrc
Created February 8, 2018 02:29
A screenrc file. top bar for info, bottom bar for shell tabs.
# ~/.screenrc
#
# look and feel
caption always "%{= bb}%{+b w}%h ${USER}@%H %= %c %{=b rw} %l %{= db}%{= dg}"
hardstatus alwayslastline "%-Lw%{= BW}%50>%n%f* %t%{-}%+Lw%<"
#
# skip the startup message
startup_message off
#
# go to home dir
@craig-m
craig-m / gist:714a465d7e7e4ae739ff1311850a9228
Created February 6, 2018 02:04
a setuid c wrapper for /sbin/reboot
Setuid reboot wrapper script
The reboot_setuid.c file (11 lines):
```
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
@craig-m
craig-m / gist:0ebb7c70b37436d254858db7dc089c38
Created February 6, 2018 01:58
curl unix socket request
pi@host:~ $ curl -X GET --unix-socket /opt/path/some.socket http/hello/curltest
<!DOCTYPE html>
<html>
<head>
<title>Hello from flask</title>
<link rel="stylesheet" type="text/css" href="/static/style.css">
</head>
<body>
<h1>Hello curltest!</h1>
</body>
@craig-m
craig-m / hugo_webdev_playbook.yml
Created December 16, 2016 10:47
single page ansible playbook for gohugo.io webdev
---
# everything needed for n0de.cloud Hugo web dev
#
# $ ansible-playbook webdev_playbook.yml -i localhost
- name: hugo webdev complete
hosts: localhost
connection: local
@craig-m
craig-m / drop_memcache.sh
Created November 22, 2015 10:50
Drop cached memory
#!/bin/bash
#
# Writing to this will cause the kernel to
# free pagecache, dentries and inodes.
# This causes that memory to become free.
#
# non-destructive & safe for production:
# ref: https://www.kernel.org/doc/Documentation/sysctl/vm.txt
freebefore=`free -k | awk '/^Mem:/{print $4}'`