Skip to content

Instantly share code, notes, and snippets.

// Somewhere earlier:
session = jsch.getSession(cvlUsername, cvlHost, 22);
session.setPassword(cvlPassword);
session.setConfig("StrictHostKeyChecking", "no");
session.connect();
session.setServerAliveInterval(1000);
session.setServerAliveCountMax(30);
commandOutput = sendCommand(session, "uptime", true, launcherLogWindowTextArea);
@carlohamalainen
carlohamalainen / blammo.py
Created December 11, 2012 03:59
thread timing issues with CallAfter
"""
Typical failure, about 70% of the time on a Debian Squeeze 32bit VM (in VirtualBox, with Debian Squeeze 64bit host OS).
Exception in thread Thread-1:
Traceback (most recent call last):
File "/opt/sw/32bit/debian/python/2.7.3/lib/python2.7/threading.py", line 551, in __bootstrap_inner
self.run()
File "blammo.py", line 49, in run
myappMainFrame.loginThread.boo = 42
AttributeError: 'MyAppMainFrame' object has no attribute 'loginThread'
@carlohamalainen
carlohamalainen / callafter-01.py
Created December 10, 2012 23:13
callafter thread debugging
# Debugging for a threading/ui problem. Sometimes get stuck in an infinite
# loop just after the line "logger.debug('AAA 6')"
import logging
from StringIO import StringIO
# The top-level logging object. We call this with things like
# logger.debug(...), logger.error(...), etc.
@carlohamalainen
carlohamalainen / launcher-08a.py
Created December 10, 2012 20:49
GUI threading printing thread ident
# Debugging for a threading/ui problem. Sometimes get stuck in an infinite
# loop just after the line "logger.debug('AAA 6')"
import logging
from StringIO import StringIO
# The top-level logging object. We call this with things like
# logger.debug(...), logger.error(...), etc.
@carlohamalainen
carlohamalainen / launcher-06.py
Created December 9, 2012 22:57
Debugging threading problem in launcher.py
# Debugging for a threading/ui problem. Sometimes get stuck in an infinite
# loop just after the line "logger.debug('AAA 6')"
import logging
from StringIO import StringIO
# The top-level logging object. We call this with things like
# logger.debug(...), logger.error(...), etc.
@carlohamalainen
carlohamalainen / install_wxWidgets_2.9.4.sh
Created November 24, 2012 07:21
Install wxWidgets 2.9.4 on Debian Squeeze
#!/bin/bash
set -x
set -e
module load python/2.7.3
mkdir -p /opt/src
cd /opt/src
@carlohamalainen
carlohamalainen / gist:4128947
Created November 22, 2012 01:37
Fiddling with STM and processes
-- Fiddling around with STM and shell processes.
-- Carlo Hamalainen <carlo.hamalainen@gmail.com>
import Control.Concurrent
import Control.Concurrent.MVar
import Control.Concurrent.STM
import Control.Concurrent.STM.TChan
import Control.Exception
@carlohamalainen
carlohamalainen / tunnel.py
Created September 29, 2012 12:06
check ssh tunnel from Python
"""
From the man page for ssh:
-f Requests ssh to go to background just before command execution. This is useful if ssh is going to ask
for passwords or passphrases, but the user wants it in the background. This implies -n. The recommended way
to start X11 programs at a remote site is with something like ssh -f host xterm.
If the ExitOnForwardFailure configuration option is set to “yes”, then a client started with -f will wait
for all remote port forwards to be successfully established before placing itself in the background.
@carlohamalainen
carlohamalainen / shrink_pdf.sh
Created November 8, 2011 00:46
Shrink a PDF file by transferring to DJVU, then PS, then back to PDF.
#!/bin/bash
set -o nounset # explode on undefined variables
set -e # explode if any command fails
# Best way to shrink a PDF of scanned pages without losing quality. Found on
# http://ubuntuforums.org/archive/index.php/t-1133357.html
# example: ./shrink_pdf.sh big_file.pdf 600 small_file.pdf
(ns blerp
(:require [clojure.xml :as xml])
(import (java.io ByteArrayInputStream)))
(def xml-data "<body> <myheader> <author> bob </author> </myheader> <data> d1 </data> <data>d2</data> <data>d3</data> </body>")
(def xml-parsed (let [input-stream (ByteArrayInputStream. (.getBytes xml-data))]
(xml-seq (xml/parse input-stream))))
(let [name-blob (for [x xml-parsed