Skip to content

Instantly share code, notes, and snippets.

# 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/
@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"
}
@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
#!/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 / 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))"
@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