Wednesday, March 14, 2012

How to update enum property value in Coherence CohQL

It took me awhile to work this out on our Coherence-based project, but the answer is actually in the documentation, just without an example.

The right side of the assignment must resolve to a literal, a bind-variable, a static method, or a new Java-constructor with only literals or bind-variables.

The key is in the ability to use a static method.  For example:

UPDATE MyCache SET favouriteFruit = com.fruits.Fruits.valueOf("APPLE") WHERE name = "FRUITFLY"

Wednesday, October 5, 2011

How to change your own password in SQL Server using ALTER LOGIN

This isn't documented very well.  If you are using ALTER LOGIN to change your own password, you need to supply your existing password as OLD_PASSWORD:

Alter Login [my_login] WITH PASSWORD = 'newpassword' OLD_PASSWORD = 'oldpassword'

Thursday, September 8, 2011

Fixed-point combinator in Java

Well it's not short enough to fit in a twitter post, ala Haskell, fix f = f (fix f).  But I enjoyed this post on Stream of Unconsciousness.

Thursday, December 23, 2010

Running out of syslog space on sybase

dump tran db_name with no_log

Sunday, July 5, 2009

Haskell telnet client to run a command on a remote system

I've written a very simple little program using the Haskell Network.Socket library, that logs in to a remote system via telnet and runs a single command. It's the first Haskell that I've written in quite a long time, and it's nothing very impressive. In fact the hard part was getting the Socket library built on Windows Vista, it was all quite simple on Ubuntu.

Anyway, here's the current version of the code:

module Main where
import Control.Concurrent
import Data.Char
import Network
import Network.Socket
import System.IO
import System(getArgs)

telnetIAC :: Int
telnetIAC = 255

telnetWONT :: Int
telnetWONT = 252

newtype Credentials = Credential (String, String)

password :: Handle -> String -> IO ()
password h pwd = do
char <- hGetChar h
case char of
':' -> do hPutStrLn h pwd
hFlush h
otherwise -> password h pwd

login :: Handle -> Credentials -> IO ()
login h c@(Credential (user, pwd)) = do
hPutStrLn h user
hFlush h
password h pwd
putStrLn "Logged in"

declineHandshakeOption :: Handle -> Credentials -> IO ()
declineHandshakeOption h c = do
ignoreChar <- hGetChar h
optionChar <- hGetChar h
hPutChar h $ chr telnetIAC
hPutChar h $ chr telnetWONT
hPutChar h $ optionChar
hFlush h
handshakeAndLogin h c

handleHandshakeInput :: Handle -> Char -> Credentials -> IO()
handleHandshakeInput h char credentials
| ord char == telnetIAC = declineHandshakeOption h credentials
| char == ':' = login h credentials
| otherwise = handshakeAndLogin h credentials

handshakeAndLogin :: Handle -> Credentials -> IO ()
handshakeAndLogin h credentials = do
char <- hGetChar h
handleHandshakeInput h char credentials

main :: IO ()
main = withSocketsDo $ do
args <- getArgs
addrinfos <- getAddrInfo Nothing (Just (args !! 0)) (Just "23")
let serveraddr = head addrinfos
sock <- socket (addrFamily serveraddr) Stream defaultProtocol
connect sock (addrAddress serveraddr)
putStrLn "Connected"
h <- socketToHandle sock ReadWriteMode
hSetBuffering h (BlockBuffering Nothing)
handshakeAndLogin h $ Credential (args !! 1, args !! 2)
hPutStrLn h (args !! 3)
hFlush h
putStrLn "Command sent"
threadDelay 1000000
To compile:
ghc -package network -o TelnetClient TelnetClient.hs

To run:
./TelnetClient localhost username password "./"

Problems building Haskell packages on Windows

I made a silly mistake today, and wasted quite a long time trying to build the Haskell network package using "cabal install" via cygwin. I eventually found out that in most cases you should use MingW and MSYS rather than cygwin (

Sunday, June 14, 2009

Where does Eclipse store its launch configurations?

It's a simple question, and the answer is out there on the net, but it took me awhile to find it. Eclipse launch configurations at the workspace level are stored in .metadata\.plugins\org.eclipse.debug.core\.launches.

I had assumed they were in org.eclipse.jdt.core and completely bypassed the debug package while searching around for it on my filesystem. Obviously that was a mistake!

Note that this refers to launch configurations saved by Eclipse as you work. You can also save your configurations to an external file, using the "common" tab of the run dialog, and saving to a "shared file".