Skip to content

Instantly share code, notes, and snippets.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mingfang
mingfang / screensaver.sh
Created August 31, 2017 05:22
script to turn off and on Raspberry Pi Display by detecting IP or bluetooth device
#!/bin/bash
while true
do
if ping -c 1 -w 3 192.168.2.67 &> /dev/null || hcitool scan | grep -q -E "ming-macbook|Ming's iPhone" ; then
echo "welcome back. turning screen on"
echo 0 | sudo tee /sys/class/backlight/rpi_backlight/bl_power
else
echo "you're gone. turning screen off"
echo 1 | sudo tee /sys/class/backlight/rpi_backlight/bl_power
@mingfang
mingfang / pgcalc.sh
Created August 31, 2017 04:01
script to calculate ceph pg number
#!/bin/bash
#Computes the suggested PG count similar to this http://ceph.com/pgcalc/
#Reguirements:
# - must run on ceph admin
# - depends on awk, wc and bc commands
#Limitations:
# - Assumes same OSD# for all pools
@mingfang
mingfang / gulpfile.js
Created March 9, 2016 16:00
gulpfile.js
// DO NOT CHANGE //
const gulp = require('gulp');
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const gwebpack = require('webpack-stream');
const browserSync = require('browser-sync');
const runSequence = require('run-sequence');
const debug = require('gulp-debug');
const cache = require('gulp-cached');
@mingfang
mingfang / show vm ip
Created September 6, 2015 07:13
show vm ip
virt-cat -d vm1 /var/lib/dhcp/dhclient.eth0.leases
lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL
@mingfang
mingfang / public ip
Created February 23, 2015 21:23
my public ip
curl -s checkip.dyndns.org | sed -e 's/.*Current IP Address: //' -e 's/<.*$//'
@mingfang
mingfang / gist:d7668c6a54079d613f89
Created February 10, 2015 15:34
Iptables rules to defend against brute force ssh attack
iptables -A INPUT -p tcp -m tcp --dport 22 -m state --state NEW -m recent --set --name SSH --rsource
iptables -A INPUT -p tcp -m tcp --dport 22 -m recent --rcheck --seconds 30 --hitcount 4 --rttl --name SSH --rsource -j REJECT --reject-with tcp-reset
iptables -A INPUT -p tcp -m tcp --dport 22 -m recent --rcheck --seconds 30 --hitcount 3 --rttl --name SSH --rsource -j LOG --log-prefix "SSH brute force "
iptables -A INPUT -p tcp -m tcp --dport 22 -m recent --update --seconds 30 --hitcount 3 --rttl --name SSH --rsource -j REJECT --reject-with tcp-reset
iptables -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
#based on https://rudd-o.com/linux-and-free-software/a-better-way-to-block-brute-force-attacks-on-your-ssh-server
@mingfang
mingfang / convert id_rsa to pem
Last active December 12, 2024 12:13
Convert id_rsa to pem file
openssl rsa -in ~/.ssh/id_rsa -outform pem > id_rsa.pem
chmod 600 id_rsa.pem
@mingfang
mingfang / docker registry search
Created December 17, 2014 23:12
docker registry search