2015-04-14

caps lock as ctrl and esc

Map your caps lock button to control when held down, and esc if pressed.

This is perfect for vim, and still keeps caps lock as control for any other program that isn't esc centric.

http://askubuntu.com/questions/196277/can-i-map-a-key-caps-lock-so-it-does-one-thing-pressed-alone-and-another-when

https://github.com/alols/xcape

.Xmodmap
remove Lock = Caps_Lock
keysym Caps_Lock = Control_L
add Control = Control_L

$ xmodmap ~/.Xmodmap

then run
$ xcape

2015-04-13

from sublime to vim

So I've decided to try learning vim one more time.

I did one unit in uni on vi, but the lecturer was so monotone and repetitive that the only thing I learned was.
Press esc to exit command mode, to exit command mode press esc. The command mode can be exited by pressing the esc key.

At my first job a few people used vim, but when I asked why they didn't use a modern IDE, they just shrugged and said, "I'm used to it and it's efficient"

The unique concept in vi that no one ever mentioned (or I just didn't understand) was composable commands, especially when combined with modes:

https://medium.com/@mkozlows/why-atom-cant-replace-vim-433852f4b4d1

http://ferd.ca/vim-and-composability.html

Whenever I used vi, the normal/insert/command modes felt like a burden, because I was always in insert mode, and ctrl-s is much easier than esc :w

I learned a couple of normal mode things like :wq :q! r x i d dd dd y p / and regex search and replace, but that's a really awkward way to edit text. I thought of them as unrelated and obscure commands, when really they are verbs. I never bothered to learn about the nouns; text-objects and movements, let alone adjectives.

I used eclipse as and IDE, and actually spent time learning the shortcuts, so I was much more effective with that. ctrl to move over words, shift to select, ctrl+alt to move selected blocks etc.
Almost every editor/IDE I've used since have a similar set of actions with the same keys, and most OSs have them built into every text box, (even blogger).

I used emacs for a few years, after a colleague showed me some of the power and extensibility, compared to IntelliJ IDEA. I was writing macros, had my own custom key-bindings that worked properly with my dvorak keyboard, and I was processing text faster than ever.

I then started working on both an iphone app and a .net web app. both of which required the use of xcode and visual studio respectively.
I stopped using emacs every day, as 3 editors/IDEs was too many to be using every day.

After that I started looking into rails again, and everyone was using sublime text 2. So I thought I'd give that a go.
It seemed to have the power of emacs, with the navigation/editing keys of everything else.

ctrl-P and multiple cursors just blew my mind. (which I hadn't seen before)

I've been using sublime 2/3 for a few years now, and was getting annoyed a little things all the time, but nothing bad enough to look for alternatives.

Then I read this:
https://advancedweb.hu/2015/03/31/why-you-should-care-about-vim/

I finally grokked vim.

If you're always in normal mode, it's easier to diw than it is to ctrl-left ctrl-shift-right del
Being in the normal mode means you don't need all the modifier keys.

Now, it seems weird that I can only enter "normal mode" in other editors by holding down ctrl!

Because it's a language (diw=delete inside word), it ends up being easier to remember than the sequence of ctrl commands.

And if you learn a new modifier y (yank/copy), or a new text-object like p (paragraph), you're extending the knowledge you already have, rather than remember a new combination, or just repeating and existing key.
eg
yip or up, up, up, up, shift+ctrl+up, ctrl+c
yis or ctrl+[left, left], shift+ctrl+ [right, right], ctrl+c

I'm no longer holding down 2,3 (4 on the laptop of end) keys at once to copy a section of text, I just type three letters.

It does help my hand and wrist pain, and it's less keys; sure.
But the more important thing is that I can think about my edits at a higher level of abstraction.
Instead of just characters, lines and pages, I can think about characters, words, WORDS, sentences, blocks, paragraphs, indented sections, tags; All the things that I actually think about when I'm working on code.
eg
delete this html tag = dat
copy the body of a coffeescript function = yii

Just like any programming language, you have methods of combination and methods of abstraction.

http://www.billthelizard.com/2009/10/sicp-notes-from-lecture-1a_04.html

Lots of editors have methods of abstraction: plugins and macros,
and simple methods of combination: ctrl+shift+alt with arrow/home/end/pageup/pagedown keys

but nothing compares to vims verb/adjective/noun form of combining search, editing or movement, with all types of things on the screen.

It's got me thinking about what other kinds of nouns I could add with a plugin.
But I really need to learn the basics before I start learning vimscript.

If you're used to an IDE, vim is something that really needs to be set-up before you start,
as the defaults are based on compatibility rather than state of the art.

This is a great way to learn the basic concepts, and set up a basic config
http://inside.github.io/vim-presentation/#/


I've really only just started learning vim (properly this time)
so where's some links to resources that I've found helpful at this early stage.

This was awesome fun, but US$25 is a bit much for only 6 months
http://vim-adventures.com/

This is almost as fun, and I'm actually learning a lot very quickly US$5 for just vim is a decent price
https://www.shortcutfoo.com/app/dojos/vim

Here's a cheat sheet that's actually compact enough to be useful
http://sheet.shiar.nl/vi

http://stevelosh.com/blog/2010/09/coming-home-to-vim/
http://benmccormick.org/learning-vim-in-2014/

Here's some ways to help vim feel more IDE like, a softer way to make the transition
http://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressively/
http://yannesposito.com/Scratch/en/blog/Vim-as-IDE/

Some issues that I haven't noticed yet
http://andre.arko.net/2013/09/11/vim-is-the-worst-editor/

I'm liking this color scheme at the moment, twilight:
http://www.vim.org/scripts/script.php?script_id=1677

in file search:
https://github.com/ggreer/the_silver_searcher

coffeescript
https://github.com/majutsushi/tagbar/wiki#coffeescript

2015-04-02

new laptop for development

Sony Vaio Pro 13 black
8gb RAM
3.0ghz i7
256GB SSD
13.3" 1920x1080

It came with win 8, which I upgraded to 8.1.
It's fun to use, but to get any real work done I need *nix.

I've always preferred debian based distros of linux, and ubuntu's the current favorite.
I don't have any issue with unity, mainly because all I use it for is to press the super key, then type programs names.

ubuntu 13.10
After creating an ubuntu live usb disk, desktop 64bit.
I completely wiped the HD, and let the install setup it's preferred partitions.
It refused to boot, regardless of UEFI settings, and after trying a bunch of things I found the first comment here https://spicious.com/sony-vaio-pro-11-with-ubuntu.html
essentially it won't boot unless a kernel parameter is set : libata.force=noncq
I had to boot again with the usb stick, edit /etc/default/grub, chroot the target drives, sudo update-grub

arrg, what a pain.

14.04 update:
sudo parted -l

shows sda1 is boot and sda2 is root

in BIOS set : non-secureboot with uefi
boot from the usb drive 14.04 iso

install and run boot-repair
https://help.ubuntu.com/community/Boot-Repair
with default options

then run the following commands
sudo mount /dev/sda1 /mnt
cd /mnt/EFI
sudo mkdir -p Microsoft/Boot
sudo cp ubuntu/* Microsoft/Boot/*
sudo cp Microsoft/Boot/shimx64.efi Microsoft/Boot/bootmgfw.efi
cd ~
sudo umount /mnt
sudo mount /dev/sda2 /mnt
sudo gedit /mnt/etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash libata.force=noncq"
from http://steffankarger.nl/2013/12/10/ubuntu-13-10-on-the-sony-vaio-pro-13


make the fan quiet
cat /sys/devices/platform/sony-laptop/thermal_control
balanced
performance
silent
echo silent | sudo tee /sys/devices/platform/sony-laptop/thermal_control

Time to setup apps:

run software updater

install chrome and login with google account.

install packages:
sudo apt-get install
  kde-config-touchpad # setup the trackpad
  git
  xclip # with alias clip='xclip -se c'
  vlc
  compizconfig-settings-manager # mostly to set super+left windows snapping
  steam

Install using Ubuntu Software Centre:
'Unity Tweak Tool'
'Tweak Tool'

themes:

sudo add-apt-repository ppa:noobslab/themes
sudo apt-get update
sudo apt-get install zoncolor-themes nouvegnome-gray delorean-dark ambiance-crunchy

http://craazyt.deviantart.com/art/Black-Out-GTK-Theme-v1-290897730
http://alecive.deviantart.com/art/ANewStartBLOOD-1-0-273905913
http://gnome-look.org/content/show.php/?content=154296



I like the dark and monochrome themes and icons:
zencolordarknight theme, with noucegnome-gray icon set and zencolor cursor

set caps-lock to be an extra control key:
in tweak-tool, under typing

install:
sublime text 2
jdk
grails ggts

install ruby and rails:
http://ruby.railstutorial.org/chapters/beginning#sec-rubygems


install haskell !!!:
sudo apt-get install haskell-platform


sublime text setup;

package control
https://sublime.wbond.net/

packages
* sublimeREPL
* fileDiffs

make sublimeREPL ruby actually work
* rvm  all do gem install pry

edit SublimeREPL.sublime-settings:
{
    "filter_ascii_color_codes": true,

    "default_extend_env": {
    "PATH": "/usr/local/bin:{HOME}/.rvm/rubies/default/bin/:{PATH}",
    "GEM_PATH": "{HOME}/.rvm/gems/ruby-2.0.0-p247"
    }
}

make bluetooth actually work:
sudo usermod -a -G bluetooth $USER
restart



coming terms

In Rich Hickey's talk The Database as a Value he introduces some specific definitions the following terms, as they'll be used during the rest of his talk.

I think understanding data through these definitions will become more and more important.

Rails app

notes from 2014

Rails app
Rails 4.0
Coffee script
Sass
Backbone front end mv*
Json rest api
Github
Jenkins
Aws
Heroku
Postgres
Newrelic
Airbrake
Cucumber ui tests
Jasmine coffee tests
Rspec unit tests
Gems
User admin devise and cancan
Oauth https://github.com/intridea/omniauth

sublime text 2 editor

notes from 2013

sublime text 2

I recently started using sublime text as my main editor.

It seems to be the main goto editor for ruby devs, so it's worth a shot.

I've used emacs previously, and I've heard that sublime text is extensible but still friendly to use.

ctrl-p is a damn powerful search tool!

rails again

notes from 2013

I've started learning ruby and rails again.
I did a couple of small projects a few years ago, and I've spent the last 6 months or so doing groovy/grails; which has copied a lot from ruby and rails.

http://railsinstaller.org/
2.2.1
ruby 1.9
rails 3.2

http://www.sublimetext.com/

http://ruby.railstutorial.org/chapters

extras needed:
http://nodejs.org/download/
http://stackoverflow.com/questions/4269922/permission-denied-publickey-when-deploying-heroku-code-fatal-the-remote-end


reading:
http://git-scm.com/book



grails for the first time

notes from 2012

http://grails.org/Installation

http://grails.org/Quick+Start


timer event scheduler
http://stackoverflow.com/questions/3812727/how-to-run-a-scheduler-timer-on-server-startup-in-grails
http://grails.org/plugin/quartz
http://www.quartz-scheduler.org/overview/features

An interesting data modelling refactoring that I was unaware of :
"You learned that a M:M relationship is actually just two 1:M relationships with a third class that you haven’t identified yet."
- from http://www.infoq.com/minibooks/grails-getting-started

ORM is actually Hibernate underneath.

There was some weirdness around enabling keyboard shortcuts in STS
http://superuser.com/questions/345667/eclipse-ignores-custom-keyboard-shortcut

"... install the templates early in the development process and customize them before you generate a bunch of code."

authentication plugins
http://grails.org/plugin/authentication
http://grails.org/plugin/openid
http://grails.org/plugin/spring-security-facebook

groovy's functional list features
filter == findAll, map == collect, fold == inject

first time git

notes from 2012

private git repo
http://java.dzone.com/articles/gitblit-little-git-repo

http://gitblit.com/

first couple of basic commands
https://support.cloud.engineyard.com/entries/21009822-introduction-to-basic-git-commands

http://programmer.97things.oreilly.com/wiki/index.php/Put_Everything_Under_Version_Control

http://matthewrupert.net/2011/03/31/use-a-single-version-control-system-for-everything/

eclipse to intelliJ

notes from 2012

new project that I'm working on has an existing java project in intelliJ.

eclipse keyboard shortcuts:
File>Settings>keymap>eclipse

The initial look of intelliJ is pretty damn ugly to me.
A big part of that, is the font they use.
I prefer the Consolas font, which you can setup thusly:
  • editor font Consolas 12
  • File>Settings>Appearance>Look and Feel - JGoodies Windows L&F

I tried out the inconsolata font as well, but it looked pretty dodgy in smaller sizes with clear type on.
I ended up finding a version that does look a lot better:
http://code.google.com/p/googlefontdirectory/source/browse/inconsolata/?r=fffda675769720a297f4d239e7065f751bbe655f

Still, Consolas looks a lot better to me on windows 7.

 useful plugins:
infinitest plugin.

from dot net to mac

notes from 2012

starting ios development at work

requires a mac
=> xcode
=> appleid
=> credit card?

manual install

chrome
aquamacs.org
yemuzip

from the objective-C tutorial
"... dynamic typing is sometimes called weak typing and static typing is called strong typing."
this is incorrect and misleading.

a positive thing, method calls on nil just return nil.

calling a method on an object is more lisp-like than other OO languages.

"Use subtle animation to communicate"

"NS" prefix for everything from NextStep - why no namespaces?


[myRectangle setOriginX: 30.0 y: 50.0]; // This is a good example of
                                        // multiple parameters
method name and first param are conflated

OSX version, xcode version, sdk version, iOS version, iphone/ipad version, all very tightly coupled. There's very little backwards compatibility. The idea that "it just works" is laughable.

from java to dot net

notes from 2012

starting dot net development for work

learning C# and .Net
C# language specification

Visual Studio 10
keyboard shortucts

Hudson integration

wcf rest service

auto generating tostring hashcode equals

http://www.fiddler2.com/fiddler2/version.asp

The real hero - http://www.ncrunch.net/
full review http://visualstudioaddins.svprogramming.net/2012/02/28/ncrunch-continuous-testing-visual-studio-add-in/

closest thing in java (eclipse)
http://www.threeriversinstitute.org/junitmax/
http://infinitest.github.com/

gives simple performance characteristics of every line of code.

possible eclipse equivalents:

http://stackoverflow.com/questions/77090/are-there-any-good-continuous-testing-plugins-for-eclipse-out-right-now
http://infinitest.github.com/
http://ct-eclipse.tigris.org/

Scala Presentation notes

These are notes for a talk I gave at work on scala (in about 2012!)


Scala - SCAlable LAnguage

scalable in terms of building libraries, expanding the language as well as runtime scalability

Scala is a static/strongly typed JVM language, that is a hybrid object oriented / functional language.
Could be a direct replacement for Java.

Java works and there are a LOT of Java programmers, so why change?
Just ask Paul Graham : beating the averages (although he is talking about LISP)

What's wrong with Java?

  • a LOT of boiler plate code, many lines of code not adding any real information
  • difficult to do multi-threaded apps. Pessemistic locking for the complex case, but it doesn't scale very well. JEE helps cover the simple case, but it's too heavyweight for many applications.
  • a LOT of Java frameworks/libraries are hard to work with, due to backwards com lots of xml config instead of code or coding by convention
  • no closures or first class functions
  • not pure OO - primitives, operators, basics arrays, statics work completely separate from objects 
  • It's not evolving fast enough - matter of opinion
  • no multiple inheritence
  • no built in aspect facility 
  • no tuples or multiple return values, can't do pass by value either
  • null checks - anything could be null
  • cloning objects difficult 
  • only external Domin Specific Languages practical (eg ant)
Dynamic Languages answer
Ruby/JRuby, Python/JPython, Groovy, JavaScript
  • dynamic typing reduces boiler plate
  • often pure OO
  • tuples or multiple returns
  • often have first class functions
  • better meta programming to increase expressiveness
  • often a limited form of multiple inheritence
  • evolve reasonably quickly
  • internal and external DomainSpecificLanguages
Problems of their own
  • slow performance
  • dynamic typing makes larger projects more difficult
  • some unit testing required just to replace basic static type checking (in addition to actual unit tests)
  • generally don't scale up well
Functional languages
Haskell, Lisp, Clojure,
  • very concise syntax due to high level components
  • immutable data makes threading easier
  • easier to reason about program, as side effects are reduced
  • extensive meta programming 
  • function composition belies the need for multiple inheritence
  • tuples
  • bottom up programming the normal - ie internal DSL the norm
Even worse Problems
  • very low mindshare - hard to find developers
  • perceived difficult to learn
  • minimal libraries (except Clojure which runs on the JVM)
  • can be overly restrictive (eg no mutable data or no side effects)
    Scala's answer to both
    • same or similar performance to java
    • strong and static typing
    • concise syntax, looks like dynamic language
    • Threads, Actors, Software Transactional Memory
    • 3rd part libraries can be written to feel like language support (eg Actors)
    • functional programming available
    • internal/external DSLs normal
    • Option instead of null
    • still evolving
    Choice is a recurring theme
    • optional type annotations
    • OO and functional
    • threads/actors/stm
    • mutable/immutable 
    • referential transperancy / side effects
     Possible problems

    • it's NOT called Java - even though much of it actually is Java
    • static typing (debatable) - type inference helps
    • Complex language - even though the source code can be simpler than java
    • not true functional language, ie mutable data just as easy as immutable - only haskell people say this
    • language still evolving - faster than Java but slower than C#
    • Clojure - LISP syntax is a barrier for a lot of developers







      Sucess Stories

      Twitter - using ruby front and backend. ruby didn't scale to massive number of transactions. reimplement backend queueing system in scala. http://www.artima.com/scalazine/articles/twitter_on_scala.html

      ...

      Intro for Java Developers
      • hybrid pure OO and functional language
      • strong statically typed - (stronger than java)
      • It IS Java underneath - Runs on the JVM
      • It's basically Java on the surface too - start with Java and make a few tweaks, make things more general
      • Imagine what Java would be like now, if it added new features and allowed breaking backwards compatibility like C#.NET does.
      • Eclipse Netbeans and another popular IDE plugins available - not as good as java, but better than most non-java languages


      Features/Positives

      • can work with Java code directly with zero ceremony
      • Java can talk to scala directly, but the class names will be weird although deterministic
      • local type inference - minimal type annotations, Not as strong as haskell, though
      • Java based syntax - easier to learn than other functional languages, feels like a dynamic java
      • concise syntax - less lines of code, less code to write/read/maintain
      • operator overloading - really just method overloading, but some methods look like operators
      • fast runtime - comparable to java
      • possible to extend the language with libraries that feel like native support
      • Actors - erlang style concurrency, multiple implementations to choose from
      • Lift - rails-like web framework
      • singletons - via object keyword, no statics
      • traits - interfaces, cross-cutting concerns/aspects, module composition, multiple inheritence
      • duck typing - dynamic method calling that's type safe using structural typing
      • consistant and simplified equals / == handling - including the null case
      • XML literals and Xpath like queries
      • regex literals
      • case classes - automatically correct java beans
      • immutable and mutable collections available
      • .Net version - under development
      • no checked exceptions - debatable
      • extensive options for private access - either public (by default) or private (specify a scope)
      • covariance/contravariance made more explicit

      why scala
      Akka actors





      running scala

      • REPL - Read Eval Print Loop - lisp, python - even an online version
      • script - perl, python, shell script
      • compile/execute - java







      http://www.scala-lang.org/node/166#Scriptit


      See hello world example

      http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-1

      See Real world Comparison

      Basics

      • val immutable value - same as final
      • var mutable variable - same as normal variable
      • types taken directly from java - primitives are mapped to a real object type
      • a lot of type annotations are optional, because of local type inference
      • no operators, only methods on objects
      • semi-colon optional, only used to separate statements on a single line 
      • optional method invocation syntax, for single argument methods "obj.meth(args)" or "obj meth args"
      • reverse order for type annotation - allows type to be optional
      • methods/functions and values/fields are not as distinct. both are assigned, both can be assigned from a block or single statement
      See Basics

      Object oriented
      • pure oo language - ie everything is an object or a method on an object - no primitives, no statics, no operators
      • class - same as java class
      • class instance - same as java object
      • object - like a java class with only static members, but it's also a singleton object
      • trait - like a java interface, but with implementation
      • traits allow multiple inheritence - a solution to the diamond problem, using a right-first depth-first search
      • traits allow aspect oriented functions - stackable traits
      • case class - a special kind of class, that will autogenerate Java Bean methods, and can be used in pattern matching
      See Bean
      See Singleton
      See Trait

      functional
      • first class functions
      • function literals
      • higher order functions
      • currying
      • immutable values
      • immutable collection types
      • lazy and strict evaluation
      • pattern matching
      • foreach
      • for comprehensions
      • map
      • filter
      • fold
      • reduce
      • almost everything is an expression. eg try catch block yields a value
      • monads
      • some Tail Call Optimisation
      See functional
      See Pattern Matching

      http://anyall.org/scalacheat/

      Control Structures
      • if else - returns a value like ternary ? :
      • for - more than for loop, returns value
      • match - pattern matching, more than switch
      • while, do while - only used for side effects, not encouraged
      • try catch finally - uses pattern matching to catch, returns a value
      • recursion - some TCO available
      • no break or continue - while loops discouraged, better ways to achieve the same goals
      proper scala way cannot have off-by-one errors, or any other boundary problems.
      It's an implementation agnostic way to apply a function to each item in the list.
      It doesn't use _any_ mutable state at all.



      See JavaLoops
      See Loops
      See ForDemo

      Xml
      • Xml parsing using all java parsing libraries
      • xml literals
      • xpath like queries
      • pattern matching on xml values
      See XML

      http://rosettacode.org/wiki/XML/XPath#Scala




      Actors
      • Taken from Erlang
      • object as thread - or virtual thread
      • method call as async message, 
      • method result as async message response
      • messages are immutable data 
      • messages received via actor's mailbox 
      • no shared mutable state - no locking - no race conditions - no dead locks
      • problems need to be re-structured / re-stated to use actors 
      • 1,000s Threads vs 1,000,000s of Actors   
      three basic ways to send/receive messages. similar to BPEL
      • asynchronous one way . two way can be emulated, but is actually just two separate async one ways
      • synchronous - waits for message response
      • futures - async two way. returns immediately from sending message (like async), but the response is a future object. When you attempt to use the future, it will then wait for the actual response.
      There is a choice between actors that use a thread each, or actors that will share a thread pool.


      See Actors

      http://www.slideshare.net/jboner/pragmatic-real-world-scala-45-min-presentation


      Logger example
      each type of message must be a case class.
      Exit message type used to tell actor to finish
      async messages are processed asynchronously, but message ordering is preserved.
      object singleton ensures only a single message queue.
      async processing means that logging a message doesn't cause main program execution to block