Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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'
// 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);
(defn create-session [hostname username password]
(doto (. (new JSch) getSession username hostname 22)
(.setPassword password)
(.setConfig "StrictHostKeyChecking" "no")
(.connect)
(.setServerAliveInterval 1000)
(.setServerAliveCountMax 30)))
(defn sleep [seconds]
(. Thread (sleep (* 1000 seconds))))
@carlohamalainen
carlohamalainen / ReadNovaList.hs
Created February 19, 2013 03:10
Uses Parsec to read the results of "nova list".
import Control.Applicative hiding ((<|>),many)
import Control.Monad
import Control.Monad.State
import Text.Parsec
import Text.Parsec.String
import Data.Functor.Identity
import Safe (headMay)
data Network = Network { networkCell :: String
, networkIP :: String
@carlohamalainen
carlohamalainen / Simple.hs
Last active December 14, 2015 12:38
Response to Immanuel Normann on haskell-cafe thread "simple parsec question"
{-# LANGUAGE FlexibleContexts #-}
import Text.Parsec
import Control.Applicative hiding ((<|>),many)
-- Example input:
{-
top 1:
@carlohamalainen
carlohamalainen / ioaction.py
Created March 6, 2013 02:36
Pretend IO actions in Python
# IO actions on integers:
#
# data IOAction = Return Int
# | Put Int (IOAction Int)
# | Get (Int -> IOAction Int)
#
# Implement using nested lists, e.g.
#
# [Return, 3] == Return 3
#
@carlohamalainen
carlohamalainen / cvl.sh
Created March 15, 2013 03:31
Install basic packages for a CVL system.
#!/bin/bash
# Author: Carlo Hamalainen <carlo.hamalainen@gmail.com>
# Use at your own risk :)
set -e
set -x
sudo yum -y install vim