Skip to content

Instantly share code, notes, and snippets.

@virullius
virullius / chainable.lua
Created August 7, 2018 14:56
Quick test of chainable methods in Lua (works)
local Thing = {}
Thing.list = {}
Thing.one = function(self)
table.insert(self.list, "one")
return self
end
Thing.two = function(self)
table.insert(self.list, "two")
return self
end
@virullius
virullius / tooltip.sh
Created May 2, 2017 12:44
Random tool tip of any executable on your PATH (GNU/Linux)
echo ">> Tooltip: $(whatis $(ls $(echo $PATH | tr : ' ') 2>/dev/null | shuf -n 1))"
#!/bin/bash
PATCH_ARGS=''
DELIMITER=__DIFF__
REALPATH=$(realpath $0)
DATA=$(tail -n +$(( $(grep -n $DELIMITER $REALPATH | tail -n 1 | cut -d : -f 1) + 1 )) $REALPATH)
printf '%s\n' "$DATA" | patch $PATCH_ARGS
exit 0
__DIFF__
--- one 2016-12-07 13:39:56.974517071 -0600
+++ two 2016-12-07 13:40:28.733159927 -0600
@virullius
virullius / hash-args.rb
Created July 27, 2015 15:56
Dynamic constructor example with hash args
class Thing
attr_accessor :color, :size
def initialize args = {}
args.each_pair do |k,v|
if self.respond_to?(k)
self.send("#{k}=", v)
else
raise ArgumentError.new "unknown property: #{k}"
end
end
@virullius
virullius / cool-tool.sh
Last active August 29, 2015 14:22
interactive shell script with prompt with command history
PROMPT="cool-tool>"
function do_one {
echo "one"
}
function do_two {
echo "two"
}
# as commonly seen elsewhere, -X POST is unneccesary because --data triggers POST method to be used
curl --header "Content-Type: application/json" --data "[\"Testing\":\"Logging\"}" http://example.com/
# view MBR with partition table
sudo dd if=/dev/sda bs=512 count=1 | hexdump -C
# backup MBR without partition table
sudo dd if=/dev/sda of=mbr.backup bs=446 count=1
@virullius
virullius / gist:ecbba5b6c6c82f241e7f
Last active August 29, 2015 14:13
simple clean list of network interfaces and IP (v4) addresses - linux, bash
ip addr show | grep 'inet ' | grep -v -E 'lo$' | awk -F ' ' '{print $NF, "\t", $2}'
@virullius
virullius / gist:0814f91784a519d77ec8
Created January 8, 2015 18:08
run local script on remote server over ssh (bash)
ssh user@host 'bash -s' < /path/to/my-script.sh
@virullius
virullius / other-dns-names
Created January 8, 2015 17:30
lookup other host names for a given hostname - via PTR records
host $(host $THE_DNSNAME | awk -F ' ' '{print $4}')