Git Prepush

I'm not sure how everyone else uses git, but at work we use it in a more centralized manner, just like the subversion I migrated us from some time ago. That means that for our changes we create a branch off of the master branch, known as a "feature branch", make our changes, test said changes, do a quick peer review, and finally merge back into master; rinse; and repeat.

Since there are changes constantly going into the master branch, that means we have to do what I call the git prepush shuffle, which is:
1) checkout master
2) update (pull) master branch
3) checkout feature branch
4) update (rebase) feature branch
5) fix conflicts (if any)

Now the feature branch is ready to push for the review process then be merged into master.

Why am I telling you all of this? Well, I hate having to type all of that stuff out each and every time. One day I wondered if there was a way I could improve this. I knew I could do aliases, so now it became a question of if I could do more than one command within an alias. A little internet searching lead me to this StackOverflow answer, that showed that it was possible.

This brought me to the next hurdle; I knew I needed to switch to the master branch. But then how would I get back to the feature branch? A little more rabbit hole falling got me to this StackOverflow answer, which states that you can go back to the previous branch with the "@{-1}" reference.

The one note I would also like to add before I show you what I did is that I assume that:

  1. [branch]
  2. autosetuprebase = always

is set. WHich I've found really helpful when I'm working on a more centralized manner which multiple committers.

My ultimate "creation" is this:

  1. [alias]
  2. prepush = !git checkout master && git pull && git checkout @{-1} && git rebase master

So if anyone out there does the same dance that I do, feel free to use this alias and save yourself some time and typing.

Connecting to a Riak node using Haskell and viewing Riak buckets

Recently at $DAYJOB I've been lucky enough to start playing with Riak for a couple of projects that I thought it would be great for. So far I've been extremely impressed with Riak's speed, configurability, and overall ease of use, and I look forward to using it more in the future. For capacity planning reasons, I performed speed tests using Bash and Curl, Python and Urllib, and even moved on to using Python and Riak's protocol buffered client. (Also fixed a bug in the documentation, WINNING!). But one day the question came to me, (this shouldn't be a surprise to anyone whose been following this blog): "can I connect to Riak with Haskell?" The answer is "Yes!" you can use the Network.Riak library.

I went looking through the documentation for some quick examples to quickly get started, but I couldn't find any. I guess I'm so spoiled by all the examples within the Python documentation, I just assumed that would exist. So instead I just decided to make my own. I'll be doing a mini-series of posts showing how to do various things using Riak and Haskell. Let's get started.

I'm going to assume that you already have both the Haskell platform and the riak-haskell-client installed (cabal install riak). Also, Riak should be installed and running (basic configuration is fine) on your local machine. If you're not connectingto your local machine, there is a line commented out in the code that will show you how to connect to a remote node.

Let's copy a command from the Riak documentation so we have something to test with:

  1. $ curl -v -XPOST <a href="http://localhost:8098/buckets/test/keys/test_key" title="http://localhost:8098/buckets/test/keys/test_key">http://localhost:8098/buckets/test/keys/test_key</a> \
  2. -H 'Content-Type: text/plain' \
  3. -d 'this is a test'

You should see output similar to:

  1. * About to connect() to port 8098 (#0)
  2. * Trying
  3. * Adding handle: conn: 0xd1f3e0
  4. * Adding handle: send: 0
  5. * Adding handle: recv: 0
  6. * Curl_addHandleToPipeline: length: 1
  7. * - Conn 0 (0xd1f3e0) send_pipe: 1, recv_pipe: 0
  8. * Connected to ( port 8098 (#0)
  9. > POST /buckets/test/keys/test_key HTTP/1.1
  10. > User-Agent: curl/7.33.0
  11. > Host:
  12. > Accept: */*
  13. > Content-Type: text/plain
  14. > Content-Length: 14
  15. >
  16. * upload completely sent off: 14 out of 14 bytes
  17. < HTTP/1.1 204 No Content
  18. < Vary: Accept-Encoding
  19. * Server MochiWeb/1.1 WebMachine/1.10.5 (jokes are better explained) is not blacklisted
  20. < Server: MochiWeb/1.1 WebMachine/1.10.5 (jokes are better explained)
  21. < Date: Sun, 08 Dec 2013 07:42:19 GMT
  22. < Content-Type: text/plain
  23. < Content-Length: 0
  24. <
  25. * Connection #0 to host left intact

And with just a quick verification we know that there is data now in the server:

  1. curl <a href="" title=""></a>
  2. this is a test

Now onto the Haskell part! Copy and paste the code below into a file, riak_get_buckets.hs:

  1. module Main where
  3. import qualified Network.Riak as R
  4. import qualified Data.ByteString.Lazy as L
  6. main :: IO ()
  7. main = do
  8. let client = R.defaultClient
  9. -- If you want to connect to a remote Riak server use this line
  10. -- let client = R.Client "FQDN_or_IP_address" "8087" (L.empty)
  11. con <- R.connect client
  12. buckets <- R.listBuckets con
  13. print buckets

Now run the code:

  1. $runhaskell riak_get_buckets.hs
  2. fromList ["test"]

Viola! You have now gotten a Seq of your buckets. I think the code is pretty easy to explain and should look familiar to anyone who's connected to a database through a programming language before. In the first line you create a connection to the server:

  1. con <- R.connect client

The next line is communicating with the server to get the buckets from the server:
  1. buckets <- R.listBuckets con

Finally, we print the response out:
  1. print buckets

In the next port or two I will show you how to "GET" and "POST" data into Riak using the Network.Riak library.

Now with Piwik Analytics

About two and a half weeks ago I disabled Google Analytics for my site. Today I have installed and configured Piwik . Since there is very little traffic to the site in general these days and this is my fault for not posting anything, I'm hoping this little post might spark a visitor or two so that I can get a better idea of piwik interface.

I'm hoping to have a more indepth review posting about piwik in the future. But until then people are just going to continue to have to be patient while I continue doing wedding "stuff".

I'm still Alive... this site is now Google Analytics free

Sorry for not posting for while, like I said back in March I might not be focusing much on my blog this year because for personal reasons.

Regardless, I wanted to let everyone know that I have decided to remove the Google Analytics from my site. After the whole NSA, PRISM thing and how it relates to Google's information gathering, I didn't feel right using it on my site. I want my readers to feel safe about reading what (little) I have to say. (Next step is an SSL cert.)

Am I over reacting? I don't think so. This is something that I've thought about for a while. The key reason for this change is that I respect you, my reader, and your privacy.

For my US readers, I hope you enjoy your 4th of July holiday. Please take a second to remember what "freedom" and "independence" means to you and who is actually "fighting" for it.

Syndicate content