Thursday, April 9, 2015

Clojure command line script with dependencies

If you want to use Clojure for command line scripts, the easiest way is by using lein-exec plugin. It compiles clj files on the fly and downloads all necessary dependencies that are declared in same file, similarly to Groovy @Grab annotation.

For example, if you have file named download.clj with
(leiningen.exec/deps '[[http-kit "2.1.16"]])
(require '[org.httpkit.client :as http])

(prn (:body @(http/get "http://www.google.com")))


it is possible to run it by:
lein exec download.clj

Sunday, April 5, 2015

My recipe for IntelliJ IDEA distraction free mode

One of the top features in IntelliJ IDEA 14.1 is distraction free mode. I am totally in love with it and not looking back, working 100% of time in it. Biggest concern about it is: loosing tabs. I was happy with tabs before, but it looks like there is a bunch of better options:

  • Recent Files (Cmd + E) - basically dropdown with tabs, but you can also do text search in it.
  • Switcher (Ctrl + Tab) - same as Recent Files, but opens file once shortcut is released. A little faster, but you are loosing search. This is the closest to original tabs.
  • Search Everywhere (Shift + Shift) - acts as Recent Files, but if you type something - also does search for Classes, Files, Symbols, Actions, Preferences. So together with tabs it basically replaces also Cmd + E, Cmd + O, Shift + Cmd + O, Alt + Cmd + O, Shift + Cmd + A.

I chose Search Everywhere as it is most feature rich and is really awesome. I also remapped it to Ctrl + E as it includes Recent Files, but as shortcut Ctrl + E works faster and is easier to reach.

Tabs had another aspect - tabs pinning, I didn't used it a lot, but for occasional use, bookmarks replace them nicely and provide more features as can pin specific line together with file. So use F3 to bookmark and Cmd + F3 to list bookmarks.

Everything else: like splitting, navigation bar, file path, tool windows, etc. is easy accessible via shortcuts or Find Action... (Shift + Cmd + A) if you forgot shortcut.

Wednesday, March 4, 2015

Changing SSH port for dynamic inventory script in Ansible

If you have to write dynamic inventory script in Ansible, but need to use SSH port which is not 22, there is example output of the script output:


{"databases":{
    "hosts":["127.0.0.1"],
    "vars":{
        "ansible_ssh_port":2222
        }
    }
}



Saturday, February 21, 2015

Ansible freezes during start

If Ansible stops for several minutes or so during start without any messages, check if it calls your inventory script, because it might query for additional options using --host parameter and if there are a lot of hosts, it may take some time.

It can be easily fixed by adding this to JSON root:

    "_meta" : {
       "hostvars" : {
       }
    }


More about it here.

Wednesday, February 11, 2015

My Everyday Carry

This will be rare post not about IT. So, apart from programming, my other obsession is EDC, if not familiar: very good intro is here.

Current setup: phone + keys



For long time my EDC kit was phone and keys. I had special phone case, that holds cards and keys hold other essentials like CashStash for bills, Leatherman Squirt PS4 as multitool, TrueUtility pen,
even Utili-key as second multitool, as it is easier to get off keyring. I am still looking for good USB cable (I tried InCharge, but it is another story)

I like this setup very much despite drawbacks. One problem was that it is very tight and there is no place for occasional spare items: checks, change, etc. Other problem is that case holds only 2 cards and e-ticket, but ideally I need more. Final and biggest problem is that my phone gets old
and I want to change it, and wallet cases are not so popular as they used to, and there is no any decent for the new phone I want to buy. So I have to shuffle my items to fit caseless phone.

Saddleback + phone + keys



Saddleback is nice slim wallet, one of the best according to LifeHacker. Holds all cards and bills, and occasional checks. A little fat itself, even without cards, but not too fat. Phone with this wallet is almost as fat as phone with case. My biggest problem is that it is 3 pieces setup. 2 pieces - one item per pocket. With 3 pieces, 2 items should go into single pocket and there is problem that when I take out one item, another can fall out of pocket accidentally.

Crabby wallet + phone



Crabby is best for cards, super slim, holds cards firmly but still convenient to take card even from the middle. But it is not suitable for my keys as I have too many of them. I even got rid of Leatherman and CashStash (not super important as CashStash is not really needed anymore, as there is place for bills now; and Utili-key has most important tools of Leatherman).
First problem: strap is too weak and narrow. It can hold 1 or max 2 flat keys. Second: single strap locks both cards and keys, so if you need keys - cards can fall out, and if you need cards, keys are not locked and it is disturbing. Third: strapping so many keys is always annoying and difficult, and with single strap you have to do it two times more often.
Generally, Crabby is fine, but only if you have small number of keys. They warn about it in their ad, but I still decided to try. Unfortunately, they were right. Another disadvantage is that cards pocket is not zipped, so no coins or occasional small items.

Local wallet with crabby claw phone



Very good setup, wallet has 2 pockets - one puffy for keys and other - larger but tighter - for cards and bills. Both pockets are zipped separately, so everything is safe and independent. Wallet is bigger, but still comfortable for pocket.
Downsides: keys pocket is not intended for keys, so there is no any special ring or strap. I adapted slider to hold crabby claw, but it is not ideal. Also size of the keys pocket is pretty tight, and it is hard to put keys there. Taking keys out of wallet is fine and crabby claw gives some freedom, but putting them back is a little tricky. Other complain is that it is real, soft leather, which gives it great texture, but it is also a little bulkier and heavier.

Chums marsupial with crabby claw + phone



Best setup. Size is almost as small as crabby, but has special pocket for keys, which even has strap (unfortunately it is not retractable, this is my only complain). Cards pocket is zipped, so it can hold occasional change, and size is just right for cards, easily holds about 10 cards, and there is some space left. Special keys pocket is very good. It is open from the short side, It is made from some artificial fabric and is really thin and light, feels like cheap plastic though. I should see if it is durable, hopefully - it is, as I'd like to keep it.


Friday, January 23, 2015

VirtualBox DHCP gives same IP address to different machines

Usually happens after cloning VMs and problem is because there is the same MAC address. Check virtual machine network settings and change as needed.

Friday, January 2, 2015

CanJS and ClojureScript

I don't really like compiled JavaScript languages, but if I had to choose - I like ClojureScript the most. It is big friends with Om MVC framework, which is based on React.js. React is another component framework like CanJS, but is too verbose to my tastes and has less features out of the box, so I like CanJS more. Only problem is that it does not have a lot of integration with ClojureScript. But it is pretty easy to solve, because ClojureScipt and CanJS are both amazing and flexible. There is example of simple component, there is ClojureScript:

(ns myexample
  (:require [domina :refer [by-id set-html!]]
            [domina.css :refer [sel]]))

(.extend can/Component
  #js {:tag "my-component"
       :scope #js {:value 3
                   :increment #(.attr % "value" (inc (.attr % "value")))}})

(set-html! (by-id "my-root") (can/view "my-template" {}))


And HTML:

<html>
<body>
  <div id="my-root"></div>
  <script type="text/mustache" id="my-template">
    <my-component>
      Value: {{value}} <input type="button" can-click="increment" value="Increment"/>
    </my-component>
  </script>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.js"></script>
  <script src="http://canjs.com/release/latest/can.jquery.js"></script>
  <script src="base.js" type="text/javascript"></script>
  <script src="myexample.js" type="text/javascript"></script>
  <script type="text/javascript">goog.require("myexample");</script>
</body>
</html>