Saturday, August 07, 2010

Resetting the root password for Blastwave's MySQL 5 on Solaris 10

Recently I needed to reset the root password for Blastwave's MySQL 5 package.
Normally I would just follow these instructions, however in this install I needed to make sure that Blastwave's svc manifest started and stopped the database for me. Here are the steps I too, executed as the system's root user:

1. Stop the MySQL server:
# svcadm disable network/cswmysql5

2. Edit the Bastwave svc manifest
# vi /opt/csw/lib/svc/method/svc-cswmysql5

by adding the following line, save and exit:

3. start up the MySQL server again
# svcadm enable network/cswmysql5

4. connect to the server
# /opt/csw/mysql5/bin/mysql -u root mysql

5. set the new root password
mysql> UPDATE user SET password=PASSWORD('new password') WHERE user='root';
mysql> \q

6. Disable the MySQL server again
# svcadm disable network/cswmysql5

7. Once again, edit the Bastwave svc manifest
# vi /opt/csw/lib/svc/method/svc-cswmysql5

and remove/comment out the line we just added in step 2:

8. Fire up the MySQL server, once more
# svcadm enable network/cswmysql5

9. and finally try connecting to the server, using your new root password
# /opt/csw/mysql5/bin/mysql -u root mysql -p

Thursday, June 03, 2010

AVR ASM First Steps

Hey Gang,

I finally got some time to get my AVR ASM tool chain up and running on Mac OSX. I'm posting my first hand written ASM code for making an LED blink, using a Mega8 (PD4, aka pin 6 on the meaga8). Let me know if you have any questions about getting your toolchain up and running. It is a bit of work to get it all set up, but it can be very satisfying to see your first program run on a $2 computer!

.include "" 

.def temp = r16
.def delay1 = r17
.def delay2 = r18
.def delayv = r19
.equ led = 4 ; PORTD bit number to blink LED on

.org 0x0000 ; the next instruction will be written to 0x0000
rjmp main ; jump to main:

clr delay1 ; set delay1 to 0
clr delay2 ; set delay2 to 0
ldi delayv, 10 ; set delayv to 50

dec delay2 ; decrement delay2, if 0, dec will set delay2 back to 255
brne delay_loop ; delay_loop: again if delay2 is not 0
dec delay1 ; decrament delay1, if 0, dec will set delay1 back to 255
brne delay_loop ; delay_loop: again if delay1 is not 0
dec delayv ; decrament delayv
brne delay_loop ; delay_loop: again if delayv is not 0
ret ; go back to where we came from

ldi temp, low(RAMEND) ; initiate the stack in the build in SRAM. Stack operations
out SPL, temp ; are always necessary when subroutines or interrupts are called.
ldi temp, high(RAMEND) ; By calling the subroutine or interrupt handling routine the actual adress
out SPH, temp ; is written to the stack in order to later jump back to the code where the
; interrupt or call occurred.

sbi DDRD, led ; connect PORTD pin 4 to LED

cbi PORTD, led ; turn PD4 high
rcall delay ; delay for an short bit
sbi PORTD, led ; turn PD4 low
rcall delay ; delay again for a short bit
rjmp loop ; recurse back to the start of loop:

Many thanks to leon, theusch, and srinivasandelta over at AVR Freaks for helping me get started.


Labels: , , , ,

Thursday, March 18, 2010

Cassandra, Thrift, and Hackage

Last week, I posted a quick 'hello world' example of inserting into and selecting data out of a Cassandra database. To get this example working, I first needed to download and compile the Thrift compiler, which also ships with a Haskell lib, which was already packaged in the Cabal format, but not uploaded to the Hackage repository, so I posted their Thrift to Hackage.

The second dependency my example has, was the Cassandra interface lib, which is compiled from the interface/cassandra.thrift file included in the cassandra 0.5.1 release.Since this code needs to only be generated once, I packaged them as the cassandra-thrift package, and posted them to Hackage.

Hopefully this helps other Haskell developers get Cassandra code up and running quickly, as we'll no longer need to mess around with thrift to talk to a running Cassandra server.

Next up: We need a better (high level) Cassandra Haskell API built on top of this plumbing... More on that soon.


Labels: , , ,

Saturday, March 13, 2010

Haskell & Cassandra: First Steps

Ok, so I had a few hours to finally sit down and try getting a 'Hello World' example put together for interacting with a Cassandra database from Haskell.
I used the following:
Mac OS 10.6.2
GHC 6.12.1
apache-cassandra-0.5.1 (JDK 1.6 from Apple)
thrift-incubating-0.2.0 (Compiled using GCC 4.2.1 and Boost 1.41 from MacPorts)

I uses a stock Cassandra install, and did not customize the included example schema, starting the server with
$ cd apache-cassandra-0.5.1
$ bin/cassandra -f

Getting the thrift compiler built and the Thrift lib installed into GHC proved to be a pain point for me, and will be the topic of a subsequent post if others have a similar experience.

Once the Thrift package is installed in GHC, and you have used the thrift compiler to compile compile the Cassandra interface definition file
$ thrift --gen hs apache-cassandra-0.5.1/interface.cassandra.thrift

You should have the generated Haskell cassandra sources:
-rw-r--r-- 1 kirk kirk 83431 Mar 13 09:57 Cassandra.hs
-rw-r--r-- 1 kirk kirk 16946 Mar 13 09:57 Cassandra_Client.hs
-rw-r--r-- 1 kirk kirk 613 Mar 13 09:57 Cassandra_Consts.hs
-rw-r--r-- 1 kirk kirk 1823 Mar 11 13:02 Cassandra_Iface.hs
-rw-r--r-- 1 kirk kirk 19015 Mar 13 09:56 Cassandra_Types.hs

Unfortunately, there is little API docs to go on here for haskellers, but I was able to finally duplicate the Java example from the Cassandra Wiki using a default Cassandra install and schema:

{-# LANGUAGE DeriveDataTypeable #-}

import Network
import System.IO
import Thrift.Protocol.Binary
import Thrift.Transport.Handle
import Cassandra_Client
import Cassandra_Types

import System.Time

main = do
-- connect to Cassandra running locally
handle <- hOpen ("", PortNumber 9160)

TOD sec usec <- getClockTime -- were using old-time here, but really we jsut need a good
-- Int64 value for the timestamp

let binpro = BinaryProtocol handle
let proto = (binpro, binpro) -- no idea why the Casandra API splits into (in an out proto, but w/e)

-- put some data into the column
proto -- The protocol/transport value
"Keyspace1" -- the KeySpace (typically this will be your app's name)
"kirk" -- The "row" id, or in cassandra-speak, the key
(ColumnPath -- Column paths point to either a colum or a super column
(Just "Standard1") -- The column family
Nothing -- The super column name
(Just "name")) -- The column name
"Kirk Peterson" -- The value to insert into the column
(fromInteger sec) -- The timestamp for the insert
ONE -- The ConsistencyLevel to enforce on the insert

-- pull the value back out
r <- get_slice
proto -- more protocol/tranport stuff
"Keyspace1" -- the KeySpace (typically this will be your app's name)
"kirk" -- again, the key
(ColumnParent -- similar to column path, the column parent.
(Just "Standard1") -- the Column Family
Nothing) -- the super column (not used in our example)
(SlicePredicate -- predicate/filter for row, either by column names and/or by a slice range
Nothing -- Column Names to filter on (not used in ut example)
(Just (SliceRange -- A SliceRange
(Just "") -- Range Start
(Just "") -- Range End
(Just False) -- Results Reversed?
(Just 10)))) -- Result Count
ONE -- The ConsistencyLevel to enforce on the read

putStrLn $ "found " ++ (show $ length r) ++ " record(s)"
mapM_ (putStrLn . show) r

hClose handle

When compiled (or ran from ghci) you should see something similar to the following:
*Main> main
Loading package parsec- ... linking ... done.
Loading package network- ... linking ... done.
Loading package Thrift-0.1.0 ... linking ... done.
Loading package array- ... linking ... done.
Loading package containers- ... linking ... done.
Loading package old-locale- ... linking ... done.
Loading package old-time- ... linking ... done.
found 1 record(s)
ColumnOrSuperColumn {f_ColumnOrSuperColumn_column = Just (Column {f_Column_name = Just "name", f_Column_value = Just "Kirk Peterson", f_Column_timestamp = Just 1268515834}), f_ColumnOrSuperColumn_super_column = Nothing}

Win! Cassandra wrote a record to the datastore, and was able to read it back.
Hopefully this help you get your cassandra app up and running, thats all I have for now, hit me with your questions/ experiences in the comments, and hopefully I can help..


Labels: , , ,

Thursday, March 19, 2009

CS Puzzles

If your in to testing your computer science fu, checkout Project Euler. I'm only 10 problems in, but its a ton of fun.

A fun example of Haskell's newtype

Haskell's newtype keyword allows you to hide an existing type behind a new type definition. in working with them I though of a neat example that would help illustrate how they work:

{-# LANGUAGE GeneralizedNewtypeDeriving #-}

newtype Fahrenheit = Fahrenheit Float
deriving (Eq, Ord, Show, Num, Fractional)

newtype Celsius = Celsius Float
deriving (Eq, Ord, Show, Num, Fractional)

far2cel :: Fahrenheit -> Celsius
far2cel (Fahrenheit far) = Celsius $ (5 / 9) * (far - 32)

cel2far :: Celsius -> Fahrenheit
cel2far (Celsius cel) = Fahrenheit $ (cel * (9 / 5)) + 32

We're declaring two "new types" one named Fahrenheit and the other named Celsius, both are really just Floats. Then we declare two conversion functions, far2cel and cel2far, to handle marshaling a Fahrenheit temperature to a Celsius. We are using the *, -, and + operators from the Num class and the / operator from Fractional, by declaring our Fahrenheit and Celsius newtypes to derive from Fractional and from Num in conjunction with the -XGeneralizedNewtypeDeriving GHC option. Neat

Monday, June 23, 2008

R.I.P George

Tuesday, June 03, 2008

git on a server w/o git

I got stuck trying to share some code to a friend of mine via git, the web server does not currently have git installed. This probably isn't much of a problem to those who use git frequently, but if your new to git, it can be quite frustrating. Luckily, my friend came to the rescue with a great link to a git cheatsheet, with the essential bit as follows:

git clone --bare . /tmp/myproject.git
git --bare --git-dir=/tmp/myproject.git update-server-info
chmod +x /tmp/myproject.git/hooks/post-update
scp -r /tmp/myproject.git

Thanks Trevor for the find.

Wednesday, May 21, 2008

Hitler Plans Burning Man

Haha! Watching the list list of friends drop from 21 to 18 to 9 to eventually 3 over the course the year.. Now I don't even ask people if they are going to come with me this year. If you've never been to Burning Man, you owe it to your self to experience it at least once!

Tuesday, May 20, 2008

Booting from ZFS under Solaris

It looks like booting from ZFS is finally going to make it into the next release of Solaris!

Monday, May 19, 2008

wxhaskell a go go

Ive been trying to get wxhaskell installed and working on mac os running leopard for the past few weeks in my spare time. Unfortunately I couldn't find much information to help me with the process so I thought I would publish a quick step through.

First, install MacPorts 1.6.0
from there:
$ sudo port install ghc wxWidgets darcs

that gets you ghc 6.8.2, and wxWidgets wxWidgets 2.8.7 and darcs 2
we need darcs, due to the latest release of the wxhaskell bindings not working right for wx 2.8 yet in leopard, so we get to check it out from the wxhaskell darcs repo. to do that, get a checkout:
$ darcs get

that should get you a checkout. next we need to configure:

$ ./configure --hc=/opt/local/bin/ghc \
--hcpkg=/opt/local/bin/ghc-pkg \

that should get your installed configured. next make it:
$ make

then install it as root:
$ sudo make install

ok, that gets wx-core installed, next we need to get wx installed.

$ cd wx
$ runhaskell Setup configure
$ runhaskell Setup build
$ sudo runhaskell Setup install

if all went well, you're ghc-pkg list should look something like this:

$ ghc-pkg list
unix-, wx-0.10.3, wxcore-0.10.3, xhtml-3000.0.2.1

woot! wx-0.10.3 and wxcore-0.10.3 installed... now for the real test

$ cd ../samples/wx
$ ghc -package wx -o helloworld HelloWorld.hs
$ /opt/local/bin/macosx-app -v helloworld
$ open

should open the hello world app! Hopefully once wxhaskell gets a new release out, we can get a macport that will make this a bit easier. good hunting :)

Tuesday, March 04, 2008

Binary to Hex String back to Binary in Erlang

A little project i'm working on in Erlang needs to take a byte sequence and write it out into a String to be save as an HTTP cookie. Then, on subsequent HTTP requests, read back in the hex string from the cookie, and convert it back into the byte sequence. I couldn't quite find a module for doing this in Erlang, so I hacked part of it, and cobbled the rest from examples I've found over the last few days.



hex(N) when N < 10 ->
hex(N) when N >= 10, N < 16 ->

int(C) when $0 =< C, C =< $9 ->
C - $0;
int(C) when $A =< C, C =< $F ->
C - $A + 10;
int(C) when $a =< C, C =< $f ->
C - $a + 10.

to_hex(N) when N < 256 ->
[hex(N div 16), hex(N rem 16)].

list_to_hexstr([]) ->
list_to_hexstr([H|T]) ->
to_hex(H) ++ list_to_hexstr(T).

bin_to_hexstr(Bin) ->

hexstr_to_bin(S) ->

hexstr_to_list([X,Y|T]) ->
[int(X)*16 + int(Y) | hexstr_to_list(T)];
hexstr_to_list([]) ->

Thursday, February 07, 2008

Massively Cool Documetary

Dr. Brian Cox does a good job conveying really heavy topics

Abusing Erlang's Pattern Matching

I wrote a simple base62 encoder in erlang tonight. while it appears to be fast, I can't help but wonder if I'm abusing Erlang's pattern matching facilities.

-export([encode/1, decode/1]).

encode(Num) ->
encode(Num, []).

encode(N,A) when N == 0 -> A;
encode(N,A) ->
encode(trunc(N/62), [e(N rem 62) |A]).

decode(S) ->

decode([], V, _) -> V;
decode([H|T], V, D) ->
decode(T, V + (round(math:pow(62,D)) * d(H)), D+1).

e(0) ->$0; e(1) ->$1; e(2) ->$2;
e(3) ->$3; e(4) ->$4; e(5) ->$5;
e(6) ->$6; e(7) ->$7; e(8) ->$8;
e(9) ->$9; e(10) ->$a; e(11) ->$b;
e(12) ->$c; e(13) ->$d; e(14) ->$e;
e(15) ->$f; e(16) ->$g; e(17) ->$h;
e(18) ->$i; e(19) ->$j; e(20) ->$k;
e(21) ->$l; e(22) ->$m; e(23) ->$n;
e(24) ->$o; e(25) ->$p; e(26) ->$q;
e(27) ->$r; e(28) ->$s; e(29) ->$t;
e(30) ->$u; e(31) ->$v; e(32) ->$w;
e(33) ->$x; e(34) ->$y; e(35) ->$z;
e(36) ->$A; e(37) ->$B; e(38) ->$C;
e(39) ->$D; e(40) ->$E; e(41) ->$F;
e(42) ->$G; e(43) ->$H; e(44) ->$I;
e(45) ->$J; e(46) ->$K; e(47) ->$L;
e(48) ->$M; e(49) ->$N; e(50) ->$O;
e(51) ->$P; e(52) ->$Q; e(53) ->$R;
e(54) ->$S; e(55) ->$T; e(56) ->$U;
e(57) ->$V; e(58) ->$W; e(59) ->$X;
e(60) ->$Y; e(61) ->$Z.

d($0) -> 0; d($1) -> 1; d($2) -> 2;
d($3) -> 3; d($4) -> 4; d($5) -> 5;
d($6) -> 6; d($7) -> 7; d($8) -> 8;
d($9) -> 9; d($a) -> 10; d($b) -> 11;
d($c) -> 12; d($d) -> 13; d($e) -> 14;
d($f) -> 15; d($g) -> 16; d($h) -> 17;
d($i) -> 18; d($j) -> 19; d($k) -> 20;
d($l) -> 21; d($m) -> 22; d($n) -> 23;
d($o) -> 24; d($p) -> 25; d($q) -> 26;
d($r) -> 27; d($s) -> 28; d($t) -> 29;
d($u) -> 30; d($v) -> 31; d($w) -> 32;
d($x) -> 33; d($y) -> 34; d($z) -> 35;
d($A) -> 36; d($B) -> 37; d($C) -> 38;
d($D) -> 39; d($E) -> 40; d($F) -> 41;
d($G) -> 42; d($H) -> 43; d($I) -> 44;
d($J) -> 45; d($K) -> 46; d($L) -> 47;
d($M) -> 48; d($N) -> 49; d($O) -> 50;
d($P) -> 51; d($Q) -> 52; d($R) -> 53;
d($S) -> 54; d($T) -> 55; d($U) -> 56;
d($V) -> 57; d($W) -> 58; d($X) -> 59;
d($Y) -> 60; d($Z) -> 61.
Enjoy :)

Thursday, January 31, 2008

Thurday Mornings

Thurday mornings, my work usually has a team meeting. This week, The Boss and The Company Owner are at a conference, one peer is leaving the company today and another is at Jury Duty. My assumption is that we wouldn't have a meeting this week. Wrong! The owner is there, with most of my co-workers, I am 10 minutes late, and I am not prepared.
I receive loot:[Pants Crap of the Belated]

Wednesday, January 30, 2008

Erlang logging example from #erlang

[5:24pm] Toad: anyone have a pointer for a good intro on error logging in production machines?
[5:24pm] Toad: e.g. the various error_logger modules, whether I should implement my own event handlers, etc?
[5:33pm] lisppaste4: archaelus pasted "system config snippet for prod logging" at
[5:33pm] archaelus: Toad: that's what I use - to access logs in production I use rb
[5:34pm] archaelus: erl -remsh prodnode -name consolenode, rb:rescan([{max,10},{type, [error]}]), rb:list() and so on
[5:59pm] Toad: cool, thanks archaelus

{sasl, [{sasl_error_logger, {file, "priv/log/sasl.log"}},
{error_logger_mf_dir, "priv/log/sasl"},
{error_logger_mf_maxfiles, 20},
{error_logger_mf_maxbytes, 524288}, %512Kb log files
{releases_dir, "releases"}

Friday, August 04, 2006

Jon comes to visit for coffee

And then I show him that I have blogger working with flickr, all out of gmail!