perl -pe ‘s/(\d+)([, ])/ int($1 \/ 2).$2/ge if /floors:/’ -i *html
Tag Archives: snippet
WordPress xmlrpc with a different Host header in Python
If you are ever in a situation where you need to run an xmlrpc request against a specific WordPress server using the python xmlrpc library, it can be somewhat difficult. The Python xmlrpc library doesn’t give you an easy way to override the Host header in the request, so you can only pick the server or the Host, but not both. Luckily, the library allows you to override the HTTP transport class it uses, so you can provide your own. Here’s a transport that seems to work for connecting locally with any given host. It would be fairly easy to modify to connect to any server.
class LocalTransport(xmlrpclib.Transport):
def make_connection(self, host):
self.real_host = host
return xmlrpclib.Transport.make_connection(self, '127.0.0.1')
def send_request(self, connection, handler, request_body):
try:
import gzip
except ImportError:
gzip = None #python can be built without zlib/gzip support
if (self.accept_gzip_encoding and gzip):
connection.putrequest("POST", handler, skip_host=True, skip_accept_encoding=True)
connection.putheader("Accept-Encoding", "gzip")
else:
connection.putrequest("POST", handler, skip_host=True)
connection.putheader("Host", self.real_host)
Setting up new computer notes
I have a i3 config repo on github:
git clone https://github.com/kitwestneat/i3-config.git .i3
setup autostart (not sure if this is necessary)
ln -s ~/.i3/i3.desktop .config/autostart/
pidgin w/ gtalk custom domain:
domain: custom.com
connect server: talk.google.com
clipit is the new parcelite
Fuxing with video: Replace audio, add watermark
# cut the video to match the time of the audio
ffmpeg -i input.mp4 -ss 0 -t
# replace the audio
ffmpeg -i input.mp4 -i input.mp3 -map 0:0 -map 1 -vcodec copy -acodec copy output.mp4
# adding an overlay to the video, replace the 0:0 with x:y coords
ffmpeg -y -i input.mp4 -i image.png -filter_complex 'overlay=0:0' -strict -2 output.mp4
Rotoscoping with autotrace and inkscape
From http://kansenzone.blogspot.com/2008/05/automatic-rotoscoping.html
autotrace file.jpg -output-format svg -color-count 10 -despeckle-level 20 -filter-iterations 10 > file.svg
Sending Crash Sysrq Keystroke to KVM
virsh send-key guest1 KEY_LEFTALT KEY_SYSRQ KEY_C
Testing links to see if they work
The input is a csv where the first column is the URL you want to test. The curl line spits out the response code. -f means curl will return an exit code if the fetch fails.
# test URLs
for x in $(cat "$file" | grep -v URL | cut -d, -f1) ; do code=$(curl -s -w %{response_code} -f "$x" -o /dev/null) && echo "URL OK $code: $x"; done
# convert URLs to nginx redirects
sed -e 's#^http://[^/]*\(/[^,]*\),\(.*\)$#rewrite ^\1$ \2 permanent;#' < "$file" > /tmp/output_redirects
Good times.