Skip to content

Instantly share code, notes, and snippets.

View samos123's full-sized avatar
🎯
Focusing

Sam Stoelinga samos123

🎯
Focusing
View GitHub Profile
#!/bin/bash
set -xe
while read host; do
echo "Setting correct dhcp network setting for $host"
ip=$(reclass-salt --pillar $host | grep single_address | grep -Eo "([0-9\.]*)$")
ssh $ip << EOF
if ! grep -q "ens2 inet dhcp" /etc/network/interfaces; then
cat << EOT >> /etc/network/interfaces
@samos123
samos123 / k8s-guestbook-aio.yml
Created October 2, 2017 04:11
k8s-guestbook-aio.yml
apiVersion: v1
kind: Service
metadata:
name: redis-master
labels:
app: redis
tier: backend
role: master
spec:
ports:
#!/bin/bash
NODEID=$1
SALTMASTER=$2
echo "deb https://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3 xenial main" > /etc/apt/sources.list.d/salt.list
apt-get update
mkdir -p /etc/salt/minion.d/
cat > /etc/salt/minion.d/minion.conf << EOL
@samos123
samos123 / ping-check.sh
Created October 6, 2016 04:42
Small script to check connectivity through ping periodically on openwrt routers
#!/bin/ash
today=$(date +"%d-%m-%Y")
time=$(date -I'seconds')
echo "Pinging 8.8.8.8 at $time" >> /var/log/ping-check-$today
ping -c 5 8.8.8.8 | grep -E "round-trip|packet loss" >> /var/log/ping-check-$today
# Optionally create a cron job to execute every minute
# Contrab: */1 * * * * /root/ping-check.sh
@samos123
samos123 / reverse-ssh-tunnel.service
Created June 27, 2016 06:41
/etc/systemd/system/reverse-ssh-tunnel.service to keep a reverse ssh tunnel restarted automatically
[Unit]
Description=Phone Home Reverse SSH Service
ConditionPathExists=|/usr/bin
After=network.target
[Service]
User=sshtunnel
ExecStart=/usr/bin/ssh -NTC -o ServerAliveInterval=60 -o ExitOnForwardFailure=yes -o StrictHostKeyChecking=no -i /home/sshtunnel/.ssh/id_rsa -R 22223:localhost:22 user@remote-ssh-server
# Restart every >2 seconds to avoid StartLimitInterval failure
RestartSec=3
@samos123
samos123 / export-image.sh
Created June 25, 2016 09:49
export images and volume snapshots from OpenStack Ceph RBD
#!/bin/bash
set -xe
imageid=$1
qemu-img convert -f raw -O qcow2 rbd:images/$imageid $imageid.qcow2
@samos123
samos123 / launch-gce-shadowsocks.sh
Last active July 10, 2016 10:15
Shadowsocks on GCE automation scripts
#!/bin/bash
machine_type=f1-micro
image=ubuntu-14-04
gcloud compute instances create shadowsocks-1 \
--can-ip-forward --image $image --restart-on-failure \
--zone asia-east1-b --machine-type $machine_type \
--metadata-from-file startup-script=bin/shadowsocks-startup.sh
@samos123
samos123 / tsinghua_vpn.sh
Last active August 29, 2015 14:26
small bash script to connect and disconnect to tsinghua vpn and manually add routes.
#!/bin/bash
if [ "$1" == "connect" ]
then
sudo pon my_tunnel
until ip a | grep -q 192.168.55.1;
do
#!/bin/bash
if [ $# -ne 2 ]; then
echo "Usage: $0 \$ssid \$passphrase";
exit 1;
fi
wifi_device=wlp3s0
ssid=$1
passphrase=$2
@samos123
samos123 / gist:d383c26f6d47d34d32d6
Created May 30, 2015 13:20
tests.py for feature_extraction on spark
import unittest
import feature_extraction
class FeatureExtractionTest(unittest.TestCase):
def test_extract_opencv_sift(self):
imgbytes = bytearray(open("img.jpg", "rb").read())
result = feature_extraction.extract_sift_features_opencv(("testfilename.jpg", imgbytes))
print result