Edit files quickly with Vim on Windows

Vim has always been my favorite text editor on Mac and Linux. But since I spend quite some time on Windows lately I figured it’s time to see how things are now with Vim in the Windows Department.

But first, why Vim? For me the most important reason is that I get to edit files quickly without leaving the terminal.
And that’s a big win. Besides, it’s easy on the eyes too!

Install Vim and ConEmu with Chocolatey

Choco, what else!
We need a decent terminal emulator for PowerShell so let’s install ConEmu as well.

choco install conemu -y
choco install vim -y

Now we can start vim with the vim command. But of course plain vim is ultimately boring, so let’s start configuring it.

Where are the config files

In ConEmu, open a Powershell shell and enter vim. This wil start Vim.
Then type

:version

Vim looks for configuration in a ‘vimrc’ file.
Now we get to see the environment settings of Vim so we know where to put our config.

system vimrc file: "$VIM\vimrc"
user vimrc file: "$HOME\_vimrc"
2nd user vimrc file: "$HOME\vimfiles\vimrc"
3rd user vimrc file: "$VIM\_vimrc"
user exrc file: "$HOME\_exrc"
2nd user exrc file: "$VIM\_exrc"
defaults file: "$VIMRUNTIME\defaults.vim"

Let’s continue using the second entry and create the vimrc file:
Exit Vim by typing

:q

And in your Powershell prompt enter:

echo $null >> ~/_vimrc

Next let’s add some plugins and modifications to our vimrc file.

Install Pathogen

With Pathogen installing Vim plugins is a breeze.

At the PowerShell prompt type:

mkdir ~/vimfiles/bundle;mkdir ~/vimfiles/autoload
Invoke-WebRequest https://tpo.pe/pathogen.vim -OutFile ~\vimfiles\autoload\pathogen.vim

Then install some plugins by cloning them to the bundle folder you just created:

cd ~\vimfiles\bundle
git clone https://github.com/scrooloose/nerdtree.git
git clone https://github.com/Valloric/MatchTagAlways.git
git clone https://github.com/vim-airline/vim-airline
git clone https://github.com/vim-airline/vim-airline-themes
git clone https://github.com/lukaszb/vim-web-indent.git
git clone https://github.com/altercation/vim-colors-solarized.git

Create your vimrc

Copy and paste this into your vimrc:

set laststatus=2
set number
set wrap
set linebreak
set expandtab
set shiftwidth=2
set softtabstop=2
set clipboard=unnamedplus
set paste
syntax on

execute pathogen#infect()

filetype plugin indent on

map  mzgg=G`z


let NERDTreeShowHidden=1
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
autocmd vimenter * if !argc() | NERDTree | endif
map  :NERDTreeToggle

set t_Co=256
set background=dark
let g:airline_theme='solarized'
colorscheme solarized
set fillchars=""

The first section is self explanatory I think. Then this config:
– loads Pathogen
– maps the function key F7 to a command sequence that aligns the code.
– configures the NERDTree to load if you start Vim without a filename.
– The last section is to set the color theme to Solarized and the configure the Airline status bar.

Run Vim!


My Productivity System or How I Get Things Done

One could say: your productivity system can’t be that good because you haven’t written a blog post in ages. True, and here is why: I deliberately put some activities on hold the last 6 months. These ‘activities on hold’ happened to be the public ones: speaking, organizing meetups and blogging.

Why did I do that? Because I switched jobs AND I made a career switch. From an infrastructure architect, I decided to take the plunge and join a company that develops back-ends (API’s) and links and integrates them with all sort of systems. So I needed all my energy to be able to make this switch and in the same time add value to customers. Which is why all extra curricular activities where put on hold.

In the meantime I finally developed a GTD system which fits my needs and works for me. So let me to share that with you.

Why a productivity system?
Because in this day and age there is so much a person has to process and remember. At home there is taxes, bookkeeping, laundry, sports, shopping and so on. At work the customers, the team and the MT should be kept happy (and vice versa, obviously). On top of that I want to spend time with my SO as much as possible, to study and write code and blogs for fun.

With all this stuff going on one could easily become overwhelmed, lose control and end up having a burn-out. So I need to plan. I want to be able to concentrate to the tasks at hand and I want to improve my system over time. And obviously I need an app to help me remember and organise.

Turns out there is no single app that fits my needs do I have to combine three: Omnifocus, Harvest and Focus:

My personal system

So here it is. My personal system is like a funnel: I start collecting and organising all tasks, then I track time for a collection of tasks and I need to focus on a single task (‘deep work’).

This is how it works:

1. Note every single task item you can think of down.
2. Finish every task that will take only 2 minutes.
3. Put the remaining tasks into categories. E.g.: work, client x, sports, study.
4. Assign the tasks a start date or a due date..
5. Focus on your tasks for today and nothing else.
6. Track Time for these tasks
7. For the task at hand that requires deep thinking and concentration use the Pomodoro technique
8. Once a week: review the week and see when and where you were less efficient.

OmniFocus (only for Mac and IOS) fits well for this workflow. It helps you to focus only on the tasks you want (or can) do today, or place or when some condition is true.
This is a screenshot of the forecasting functionality of OmniFocus. For a given day you only get to see the tasks that you will be working on that day. And it has nice calendar integration a well.

OmniFocus does not a good job with time tracking, so in comes Harvest. Harvest is a very cool Time Tracking tool, which helps you see how productive you were on a day, a week and a month.

But Harvest does not let you focus. This is where I use the Pomodoro Technique. So in comes an app called Focus, which let me focus on the task at hand for 25 minutes.

The reason why I picked Focus is because of its integration with OmniFocus.

Mac only and Expensive?
Mac Only? Yes, unfortunately so (except for Harvest). I would love to OmniFocus going cross-platform, but it’s not going to happen.

Expensive? That depends. If you buy Asana or Todoist then you need to pay a monthly subscription to get at least similar functionality as OmniFocus. For the OmniFocus Pro version (and you are going to want that) you pay a whopping $79.99. So OmniFocus might be cheaper in the end. I use the free version of Harvest, and Focus costs around $7,99.

Take Aways
Developing a good productivity system that fits your needs can take months or even years. And in my case there was no single app that supported my needs. So I needed three. But I’m quite happy now. And I can see where I was less productive and why. And improve myself.

A big thank you for Asian Efficieny by the way. Their podcast is awesome and inspiring. Have a listen!


SQL2016 Stretch database. Yes, it’s another linked server

Your manager always wants to keep all the data…now with bigdata being a thing and algoritmes are used more efficient (IOT), people want to hoard data even more, but it needs to be online to be valuable. If you have to restore the data first, your data is not very valuable. But all this extra data also slows down your database performance…and gives the dba’ers extra challenges….but not anymore.! Well, at least when your boss got a big wallet and don’t mind spending it on a SQL buget.

In SQL2016 Microsoft introduced the stretch database. which give you live access to ‘archived’ data and makes it feel like it’s on premise. And  it’s a secretly just a linked server! A linked server between mssql and Azure.LS+azure

How does this work, and is it safe?

Yes! since it works on secure linked server technology and it stores an encryption key on the on-premises sqlserver, it’s suitable for all your cold data, not hot, because it does slow down the query speed, but it will not clogg your network and your data will be available at all times, even when the data is being stretched over to Azure the data still is fully query-able.

First ask yourself, Do you really need to keep this data? If yes, How do you create a stretchdatabase? Well, this is easy!

Hesitations? use this link for info on the MS Stretch database advisor.

I use a simple test database, the adventureworks2016 ctp3.

Before we can start, check if the data archive function is enabled, if not (0) enable it.

####Check status of Remote data archive####
SELECT @@VERSION AS 'SQL Server Version'; 
EXEC sp_configure 'remote data archive'; 
GO 
####Activate Remote data archive####
EXEC sp_configure 'remote data archive' , '1'; 
GO 
RECONFIGURE; 
GO

Next we can create a master key to encrypt all your data locally, this way, the data can’t be read in Azure.
Note: You can also create a masterkey from the stretchdb wizard, it’s up to you. I’ll show both options.

USE AdventureWorks2016CTP3; 
GO 

CREATE MASTER KEY ENCRYPTION BY PASSWORD='stretchdb2016'; 
GO

Next I will create a simple table  and populate it with some data, to keep the demo quick and simple :

CREATE TABLE dbo.Stretchtable
(
FirstName VARCHAR (50),
LastName VARCHAR (50)
);
GO


Use [AdventureWorks2016CTP3]
GO
INSERT INTO dbo.Stretchtable (FirstName, lastName)
VALUES ('Reed', 'Richards'), ('Benjamin', 'Grimm'), ('Sue', 'Storm'), 
 ('Johnny', 'Storm'), ('Victor', 'Von Doom'), ('Willie','Lumpkin');
 GO

Keep your Azure account ready! I use the SQL logical server resource, you need to create a resource before you can stretch the database.

Azure resource

 

Select the table you will be stretching to Azure. Now enable the table for stretching and the wizard will open up.

Enable stretch database

It’s a Hybride archive – You can stretch the whole table or filter out the (c)old data from a massive table.
4_EnableStretchTable

 

Next thing you create a master key, if you didn’t make it before, if you made it already, It will ask you to fill in the master password.Masterkey_StretchTable
10_LoginStretchTable

Fill in the IP range for a firewall rule.IP_Azure

12_EnableStretchTable

Hey Ho, let’s go, that was easy!

Now the table will start to stretch, if you want to see if it stretched yet, try a select query and check the executionplan.
14_EnableStretchTable

Want your data back? No problem, You can bring back the data to your on-premise server, if you don’t want to use Azure. Because, when you delete your azure account, the data will be gone too!

bringbackmydatabringbackmydata2bringbackmydata3

 

Note: Data storage can be expensive on Azure, but this function gives us a positive view on the ever growing databases and it’s possibilities.


Meet the Buttonfactory – September 15

  • tbf_powershellkopieThursday, September 15, 2016

    to

    Beercoo

    Weg en Bos 51, 2661 DL Bergschenhoek

    You are invited to join us at our first meetup!
    There will be 2 presentations. One is about Powershell and the other about SQL Server 2016.

    Planning:

    19:00 A drink and some food

    19:30 Powershell Objects by Jacqueline
    Powershell is an object oriented scripting language, but what does that even mean? In this presentation you’ll get to learn all about objects and how you can supercharge your scripts leveraging them. No Powershell skills required!

    20:15 What is new in SQL Server 2016? By Melanie
    SQL Server 2016 is the biggest leap forward in Microsoft data platform history!
    OK, I copied that line from the Microsoft site. But the coolest new feature is the stretched database. We are going to tell you all about it.

    21:00 Another drink.

    The meetup is free of charge and will be dutch spoken.
    No prior knowledge is required!

    Dutch PowerShell Meetup

    Rotterdam, NL
    26 Powershellerines

    Know Ada Lovelace? Grace Hopper? This group firmly believes that programming, scripting and system administration is for women! But where are you? Let’s get together and learn…

    Check out this Meetup Group →


Docker for impatient newbies part 1: Getting started

If you are one of the few that have not yet taken the plunge into Docker don’t feel ashamed. I haven’t either. I’ve been too busy doing other stuff lately. But yesterday I actually started using Docker because I had a real life use case. I have a Node application that I wanted to ship in a Docker container. And I wanted it quickly.

So here is what you need to package a Node application in a Docker container.

Docker for Mac and Docker for Windows

Step 1 is to install the Docker engine for Mac or Windows. Head over to https://docs.docker.com/engine/installation/mac/ and install Docker for Mac or Docker for Windows.

What happens? You just transformed your machine into a Docker engine. With this Docker engine you can host containers, from images containing your applications.
This is how you get started and start developing. Production environments are better installed in another Docker Engine, somewhere in the cloud or in a datacenter.

Docker on Linux

The Docker Engine on Linux is in its natural habitat and installing it (on Ubuntu Xenial) is as easy as:

sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" | sudo tee /etc/apt/sources.list.d/docker.list
sudo apt-get update
apt-cache policy docker-engine
sudo apt-get install -y docker-engine

sudo usermod -aG docker $USER

First steps

First, check the installation:

docker version

1.12 is the latest version:

Let’s go ahead and create our first image for a Node Express app.

Package a Node.js Express app

Cd into a Node application you want to package, or clone mine. If you clone mine, install Node.js on your platform if you haven’t already. and check if it runs.

git clone https://github.com/jacqinthebox/node-express-starter
cd node-express-starter
npm install
gulp serve

If all is well you will be presented with a static website. The theme is from Black Tie.

First step is to create a Dockerfile.
Assuming you are still in the node-express-starter dir, run:

touch Dockerfile

This will be the folder structure from node-express-starter:

.
├── Dockerfile
├── app
├── bower.json
├── gulpfile.js
├── main.js
├── node_modules
└── package.json

This is how the Dockerfile should look like:

FROM mhart/alpine-node:6.3.0

MAINTAINER Jacqueline

# copy all the files from the Node app to /var/www in the container:
COPY  . /var/www

#set it as workdir
WORKDIR /var/www

#install dependencies from package.json
RUN npm install

# Expose port 3000 from the container to the host
EXPOSE 3000

ENTRYPOINT ["node","app.js"]

What does this mean?

  • FROM: here we need to put the base image for our image. Lots of these images yoy can find on the [Docker Hub](https://hub.docker.com/explore/). I want the image to be as small as possible. So that’s why I’m using an [Alpine](https://github.com/mhart/alpine-node) based image.
  • COPY: I copy all the files from my node project to the /var/www folder on my Docker image
  • WORKDIR: /var/www is the workdir (pwd)
  • RUN: while in /var/www, the npm install is run to install all dependencies of the Node app.
  • EXPOSE: here you can set the port for communication with the outside world. My Node app runs on port 3000
  • ENTRYPOINT: the command ‘node app.js’ will run upon starting the container (not when creating the image of course)

Now create the container image. You should still be in the node-express-starter dir. Run the following command (don’t forget the dot):

docker build -t jacqueline/impatient .

This has created a Docker image with the tag (-t) ‘jacqueline/impatient’.

Now run it

docker run -d -p 8080:3000 jacqueline/impatient

With -d the container instance is ran as a daemon and the -p is the port redirection (3000 we exposed in our image will be forwarded to port 8080)

Now head over to http://localhost :8080 and you should be presented with the Node web application:

Recap:

  • We installed the Docker Engine on our computer
  • We created a Docker image containing our Node app
  • We started an instance of this image

container

Stopping and cleaning up

If you work with containers, lots of harddrive space will be consumed. This is how you clean up stuff.

First, check which containers are currently running with ‘docker ps’:

docker ps

Obviously, the one we just ran is active:
docker
Notice the container ID. You can stop this instance with:

docker stop 45

Next, delete the container. First list all the containers:

docker ps -a

Again, notice the ID:

docker rm 45

Now that the container is deleted, we can go ahead and remove the image. First check which images are present:

docker images

There are 2. I’m only going to remove my own image, not the Alpine one.

docker rmi 78

In the screenshot above notice how I forgot to delete the container, but I could still delete the image with the -f flag.

The End. But will be continued.

Of course now that we took the Docker plunge, we now want to host our container in the cloud. At Digital Ocean, AWS or even Azure. This will be covered in part 2.