Skip to content

Instantly share code, notes, and snippets.

View thwarted's full-sized avatar
🥓
increasingly at large

Andy Bakun thwarted

🥓
increasingly at large
View GitHub Profile
package main
// A simple go iterator implementation.
// Someone could use generics to make this more, well, generic. And
// maybe define a Next() function on a channel receiver to abstract
// away needing the channel <- operator to get the next item and
// and handle the iterator ending cleanly. This uses range which
// already knows how to handle streaming values from channels.
//
// github user: thwarted
@thwarted
thwarted / qbselect.go
Created March 2, 2017 19:21
an experimental query builder that might make it easier to create safe SQL using prepared statements w/ support for variable length IN expressions
package qb
import (
"fmt"
)
func placeHolders(howmany int) (s string) {
s = "?"
for ; howmany > 1; howmany-- {
s += ",?"
@thwarted
thwarted / invoke.sh
Created December 25, 2015 22:52
some simple scripts to invoke steam as a separate user for non-robust filesystem isolation
#!/bin/bash -x
if [[ -z "$XTXAUTH" ]]; then
echo "XTXAUTH not set, was this invoked correctly?"
exit 1
fi
unset XAUTHORITY
server=$( echo "$XTXAUTH" | awk '{ print $1 }' )
xauth add $XTXAUTH
@thwarted
thwarted / bash-multiassign.sh
Last active June 10, 2022 22:31
defines a function `assign` that allows returning multiple values from a function/command
#!/bin/bash
# assign var1 varN... = c arg...
# execute c and assign captured values to the list of variables
#
# values can be output from c by redirecting/writing to:
# >${outvar[x]}
# >&x
# where x is the index of the variable you want to return the value
# in
@thwarted
thwarted / httppause.sh
Created August 3, 2015 21:58
test case for "An error occured on select: 4" in typhoeus/ethon; start httppause and then run makerequest.rb
#!/bin/bash
if [[ "$NESTED" ]]; then
IFS=$( echo -e '\r' )
while read line; do
[[ -z "$line" ]] && break
done
sleep 10
@thwarted
thwarted / zipcode.go
Created February 3, 2015 19:37
example of matching a format and returning an error in go from JSON parsing
type ZipP4 string
func (z *ZipP4) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf(`"%s"`, *z)), nil
}
func (z *ZipP4) UnmarshalJSON(b []byte) (err error) {
if z == nil {
return errors.New("ZipP4: UnmarshalJSON on nil pointer")
}
@thwarted
thwarted / simple-iscsi-setup-in-linux.md
Created January 16, 2015 20:57
Simple ISCSI setup in Linux

Mostly gleaned from the instructions at https://wiki.archlinux.org/index.php/ISCSI_Initiator to setup the initiator.

Overview of the steps:

server1 is serving the targets and has IP 10.1.1.1/24 desktop1 is initiator. Both machines are in the 10.1.1.0/24 subnet.

  • installed netbsd-iscsi (yum install netbsd-iscsi in my case for Centos 6.5)
  • updated the netmask in /etc/iscsi/targets to be 10.1.1.0/24.
  • created the empty file that would be the backing store for the target with dd if=/dev/zero of=/tmp/iscsi-target0 bs=1024 count=100000 (this matches what's in the sample config in /etc/iscsi/targets)
@thwarted
thwarted / portserve
Created November 19, 2014 05:39
portserve - simple script used to test haproxy healthcheck settings
#!/bin/bash
if [[ "$2" ]]; then
msg="serving port $1"
size=$( echo "$msg" | wc -c )
read request
while /bin/true; do
read x
if [[ "$x" == "" ]]; then
break
@thwarted
thwarted / pipe-to-dgram
Created November 19, 2014 05:38
pipe-to-dgram
#!/bin/bash
exec 3> >( while /bin/true ; do socat -t0 -T0 -u STDIN UDP:172.28.128.3:8888 ; done )
while /bin/true; do
while read line; do
echo "$line"
echo "$line" >&3
sleep 0.1
done < /vagrant/testlog
done
@thwarted
thwarted / transmission.initd
Created September 19, 2014 17:23
control script for transmission; you'll need to roll your own settings.json
#!/bin/bash
TRHOME=$( readlink -f $( dirname $0 ) )
# mkdir -p complete config incomplete logs torrents
PIDFILE=$TRHOME/logs/transmission.pid
dostart() {
cd $TRHOME
transmission-daemon \
--config-dir $TRHOME/config \