Skip to content

Instantly share code, notes, and snippets.

View shurikk's full-sized avatar

Alexander Kabanov shurikk

  • San Francisco / Bay Area, CA
View GitHub Profile
@shurikk
shurikk / detach-app-from-current-session1.sh
Last active December 18, 2015 15:08
detach non-daemonized application from current session with user switching
#!/bin/sh
# * script is executed by root
# * will detach from current session
su -p user <<"EOF"
/path/to/app -o option1 > /path/to/app.log 2> /path/to/app-errors.log &
echo $! > /path/to/app.pid
EOF
@shurikk
shurikk / gist:5944995
Created July 7, 2013 21:13
execute shell command with a timeout
#!/usr/bin/env ruby
require 'timeout'
def exec_with_timeout(cmd, timeout)
r,w = IO.pipe
pid = Process.spawn(cmd, {[:err, :out] => w, :pgroup => true})
w.close
[begin
@shurikk
shurikk / tcp_socket_proxy_monkey_patch.rb
Created April 26, 2014 03:22
TCPSocket proxy monkey patch
# Usage:
#
# TCPSocket.socks_server = "socks-proxy.example.net"
# TCPSocket.socks_port = 8888
require 'socket'
class TCPSocket
alias :direct_to :initialize
@shurikk
shurikk / gist:3c7ddd925d4e0eb70054
Created May 12, 2015 00:43
crontab string eval
class Foo
def schedule
# crontab like string, e.g. "5 * * * *"
end
def run?(time)
fields = schedule.split(/\s+/)
!%w(min hour day month wday).map.with_index do |name, i|
fields[i].gsub(/(?:(?![\d\/\*,]).)*/, '').split(',').select do |v|
@shurikk
shurikk / iptables.sh
Created February 10, 2021 18:08
nginx as a transparent SSL proxy using stream module (quick test)
iptables -t nat -A OUTPUT -p tcp -m tcp --dport 443 -m owner --uid-owner root -j RETURN
iptables -t nat -A OUTPUT -p tcp -m tcp --dport 443 -m owner --uid-owner nginx -j RETURN
iptables -t nat -A OUTPUT -p tcp -m tcp --dport 443 -j REDIRECT --to-ports 3130