Blog posts, page 2

A little bit more about git cherry-pick


In one of the previous posts I talked about a way to copy a bunch of commits from one git branch to another one. Today had to copy commits again, but for a different reason.

Several days ago I started a new project in a new repository. I made several commits on my master branch when I realized that I needed to create a pull request to perform a code review. What I had:

A -- B -- C -- D -- E                                          master

What I’d like to have:

X                                                              master
  A -- B -- C -- D -- E                                        feature
Continue reading

Easy JSON analyze with spray-json

Scala, Akka, Spray, DSL

If you use Spray or Akka HTTP to create a REST service, possibly you need to work with JSON objects. Both Spray and Akka HTTP have built-in support of spray-json.

In most cases you have a fixed set of fields in your JSON API, so the proposed way to work with spray-json is to create model case classes and marshallers/unmarshallers for them:

case class Person(name: String, age: Int, title: Option[String])

trait PersonRoutes extends DefaultJsonProtocol with SprayJsonSupport {
  implicit val personFormat = jsonFormat3(Person)

  val route =
    put {
      path("people") {
        entity(as[Person]) { person =>
          // Store to db
Continue reading

Batch cherry-picking with git


Today I came to work and found that I have to move 18 commits from my development git branch to the old release. I’ve worked on one feature for several weeks, and kept my branch up to date with master, so the history looked like this:

               Z -- Y -- X -- W -- V -- U -- T -- S            feature
              /         /              /
-- A -- B -- C -- D -- E ----- F ---- G -- H                   master
     R -- Q                                                    release

So, my goal is to create a feature' branch on top of the release and copy the commits Z, Y, W, V, T and S there:

Continue reading

Draft posts with Hakyll

Hakyll, Haskell

If you’d like to write a long posts in your Hakyll blog, you often can find that you’d like to commit a post (or several posts), but you’re are not going to deploy it on server. Here is my solution inspired by this post. Now I can call Hakyll with --with-drafts and it will use both posts and drafts directories to collect posts data.

There are several issues I had faced with when I was solving this problem:

  1. Detect what program is running in the draft mode.
  2. Pass posts to Hakyll.
  3. It is safer to have a separate folder for generated site while running in the draft mode to avoid the draft articles deploying by mistake.
  4. Hakyll itself uses cmdargs package which checks if the command is executed with proper options.
Continue reading

Fixing nvidia-drivers-340.76 build with kernel 4.0

Gentoo, NVidia

After upgrade to gentoo-sources-4.0.5 I’ve found what I cannot install drivers for my good old GTS-250. This card is pretty old, so it supports only in 340.x branch of NVidia drivers. Unfortunately NVidia is not really fast in fixing of such kind of problems ( They just provide a link to the patch in Ubuntu. But, AFAIK Gentoo maintainers doesn’t take such patches as well (I suppose it is break older kernels compatibility).

The cool thing I’ve never used before called epatch_user allows you to add custom patches to any ebuild supporting this feature. And actually this is the way, proposed to solve such issues. So, all you need to do is to create folder /etc/portage/patches/x11-drivers/nvidia-drivers-340.76 and place there following patch:

--- kernel/nv-pat.c.orig    2015-08-17 21:46:15.541979210 +0300
+++ kernel/nv-pat.c 2015-08-17 21:47:17.180978210 +0300
@@ -35,8 +35,8 @@
     unsigned long cr0 = read_cr0();
     write_cr0(((cr0 & (0xdfffffff)) | 0x40000000));
-    *cr4 = read_cr4();
-    if (*cr4 & 0x80) write_cr4(*cr4 & ~0x80);
+    *cr4 = __read_cr4();
+    if (*cr4 & 0x80) __write_cr4(*cr4 & ~0x80);
@@ -46,7 +46,7 @@
     write_cr0((cr0 & 0x9fffffff));
-    if (cr4 & 0x80) write_cr4(cr4);
+    if (cr4 & 0x80) __write_cr4(cr4);
 static int nv_determine_pat_mode(void)

Putting posts content on the index page

Hakyll, Haskell

Once you have created a Hakyll based site the first page contains only the titles of your posts. It can be acceptable if your first page contains another content, but if there are only the latest posts it looks weird. Let’s check how does it works.

Default index page template includes post-list.html template which contains following code:

      <a href="$url$">$title$</a> - $date$
Continue reading

Installing Hakyll on Gentoo Linux

Hakyll, Gentoo

I have been using Gentoo Linux as my primary OS since 2004. So, it usually important for me to choose software which available in Gentoo portage. And there is no Hakyll in portage :(

Of course, it is possible to install Hakyll from cabal using cabal-install, but according to the wiki this is not recommended. Instead of this, we can install this package fro the Gentoo Haskell overlay. So, first of all it required to add this overlay using layman (of course if you didn’t do it before).

$ emerge layman
$ layman -a haskell
$ echo "/var/lib/layman/make.conf" >> /etc/portage/make.conf
Continue reading

Why Hakyll?


Well, I thought about personal blog for a quite long time, but to be honest I’m really lazy. And the second thing, I don’t like most of CMS I’ve ever seen. So, the idea of static generation is looking much more suitable for this kind of stuff. But I never tried it before (to be honest I’ve never heard about it, except 1C Bitrix. At least I thought it generates a lot of static pages, but it still requires PHP).

Finally, I found out that there several solutions for site generation (thanks Vitaly Repin), like (Jekyll, Hakyll, Middleman). The interesting thing, is that if you try to google something like “Jekyll vs Hakyll”, there will be several posts about migration from Jekyll to Hakyll. Of course, it doesn’t mean that Hakyll is better, but it seems like it is more flexible.

Another reason why I’ve chosen Hakyll is Haskell. Haskell was a language which bring me to the functional programming world. It was like a magic for me (and it steel so, since I’ve never participated a real projects in Haskell). It feels like you just have written your first program, and it’s working (of course if you was able to compile it :)).

So, the first impression is “I like it”. Even thought, it’s not strictly required to know Haskell, and all of this stuff (like Monads and Monoids), this knowledge gives you some advantages, and it gives me a hope that I’ll be able to make this blog much better that it is now :)

My first blog post


This is my first post in this blog, just to be sure that Hakyll is working.

Checking a syntax coloring for Haskell:

-- factorial
fac n = foldr (*) 1 [1..n]

main = do
  putStrLn "Hello, World"

And for Scala:

// Hello world
object Test {
  def main(args: Array[String]) = {
    println("Hello, World!")

And that’s all falks!