Skip to content

Instantly share code, notes, and snippets.

Avatar

Andy Bakun thwarted

View GitHub Profile
@thwarted
thwarted / qbselect.go
Created Mar 2, 2017
an experimental query builder that might make it easier to create safe SQL using prepared statements w/ support for variable length IN expressions
View qbselect.go
package qb
import (
"fmt"
)
func placeHolders(howmany int) (s string) {
s = "?"
for ; howmany > 1; howmany-- {
s += ",?"
@thwarted
thwarted / invoke.sh
Created Dec 25, 2015
some simple scripts to invoke steam as a separate user for non-robust filesystem isolation
View invoke.sh
#!/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 Aug 27, 2015
defines a function `assign` that allows returning multiple values from a function/command
View bash-multiassign.sh
#!/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 Aug 3, 2015
test case for "An error occured on select: 4" in typhoeus/ethon; start httppause and then run makerequest.rb
View httppause.sh
#!/bin/bash
if [[ "$NESTED" ]]; then
IFS=$( echo -e '\r' )
while read line; do
[[ -z "$line" ]] && break
done
sleep 10
@thwarted
thwarted / zipcode.go
Created Feb 3, 2015
example of matching a format and returning an error in go from JSON parsing
View zipcode.go
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")
}
View simple-iscsi-setup-in-linux.md

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 Nov 19, 2014
portserve - simple script used to test haproxy healthcheck settings
View portserve
#!/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
View 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 Sep 19, 2014
control script for transmission; you'll need to roll your own settings.json
View transmission.initd
#!/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 \
@thwarted
thwarted / FOR_EACH.cmacros.h
Created Sep 17, 2014
a FOR_EACH C Preprocessor macro that works under both GNU CC and Visual Studio 2013/MSVC
View FOR_EACH.cmacros.h
/* all this verbosity is required for this to work reliably and predictably
* on both GCC and MSVC
*/
/* because gcc cpp doesn't recursively expand macros, so a single CALLIT
* macro can't be used in all the FE_n macros below
*/
#define FE_CALLITn01(a,b) a b
#define FE_CALLITn02(a,b) a b
You can’t perform that action at this time.