Category Archives: geek

indent selected lines with tab in vim

.vimrcOne thing that annoyed me about using Vim was how much keystrokes it took to indent or un-indent a few selected lines of code. My (probably less than ideal) way of doing that was to go into visual mode, select the lines with the movement keys J or K, then use the keys to change the indenting which are < or >.
To indent another level, pressing dot after this would work.

In Visual Studio or a typical Windows text editor I’m used to simply selecting the lines by holding shift & moving the cursor keys up or down, then pressing TAB to indent and shift-TAB to un-indent.

I’m so used to using the cursor keys for text manipulation that it’s hard to unlearn this, so I was looking for key mappings to do the same thing in Vim.
Luckily this turned out to be rather easy. If you add the following to your vimrc file, you can shift-tab away to indent your code:

" TAB-mappings to allow indenting of selected text instead of using < & >
vnoremap <Tab> >
vnoremap <S-Tab> <

warmup your site or wordpress blog with a single command line statement

mother

GNU Wget is a powerful tool when it comes to downloading files from the web or mirroring sites. It’s command line features can be daunting and not very obvious. With some experimentation, reading the (f..) manual and some Googling you can get it to do some pretty neat tricks for you.
All of that is from the command line too, which is great if you want to schedule this kind of magic or use it in a script.

For example, you might want to warm-up your site or WordPress blog so your homepage and all posts linked from it are present in your cache when a visitor arrives. I’m assuming you are using a caching on your site otherwise this is pretty pointless. For WordPress you can use a caching plugin like W3 Total Cache for example.

With Wget, it goes like this:

wget.exe http://n3wjack.net --spider --no-directories --level=1 --recursive 
         --accept-regex=n3wjack.net/20[1..9].*

The command line parameters (in order) mean something like:

  1. Crawl n3wjack.net.
  2. Crawl it like a spider (follow the links).
  3. Don’t create directories for downloads.
  4. Crawl 1 level deep (so anything linked on the homepage is OK, but don’t go deeper).
  5. Do this recursively (so it actually goes 1 level deep).
  6. Follow only links that start with "/201..." to "/209..." (it’s a regular expression).
    This one is a trick to have it only follow links to blog-posts because my URL scheme begins with the year of the post (2015, 2016, …). It’s good until 2099, which should do the trick I guess. :)
    This way I’m also avoiding it loading all tag, category or page links.

If your site has a different URL scheme you’ll have to change the accept regex pattern to fit your scheme.

You can download Wget from the GNU site. It’s Open Source and is available for Windows, Mac and various Unix systems.
For Chocolatey users, there is a wget package available to install it on your system.

verifying an md5 file hash with just powershell

Tools
You see this possibility for a lot of software downloads but if you’re like me you hardly ever end up doing it: verifying an install file’s MD5 or SHA-something hash.
For Open Source software this is however recommended if you aren’t downloaded from the official mirror (and even then) and certainly if it’s anything related to security (like Keepass for example).

But to verify that MD5 hash you probably need to install yet another piece of software you’re hardly going to need, so you end up not bothering at all.

Hold on a second.

If you have a recent Windows system with PowerShell installed, you probably have all you need to verify that MD5 hash.

Try this in the PowerShell command prompt:

Get-FileHash .\KeePass-2.30-Setup.exe -Algorithm md5

It should print out something like this:

Algorithm       Hash
---------       ----
MD5             CD430EB0F108BB192D2155C68EB7BB48

Which happens to be exactly the MD5 hash code listed on the site for that version of the Keepass installer. Yay!
Without that -Algorithm parameter it prints out the SHA-256 hash by default, but that’s longer and harder to compare visually even though it’s more precise.

That was easy and required no additional software.
Pretty damn sweet.

Photo by Julien Dumont, cc-licensed.

disabling Dell software without uninstalling

Yes, a cat. Cause it's the internet after all.

You know how it goes. You get this new and shiny computer from big computer company X and with it you don’t only get your OEM licensed Windows OS but also some “super handy” tools X happened to install just for you.

Dell is no different so mine come with Dell Data Vault, Dell SupportAssist and Dell Update Service. All of this is (of course) for your own benefit to update your machine to the latest drivers and blah blah blah, even though anything crucial is sent through Windows update anyway.

The downside is that these things are constantly running and using up your precious CPU and memory, while you’ll probably never need them. Ever. Oh, and they also come with some security vulnerabilities apparently, which is always a good reason to kick their butt.

I don’t know what Dell Data Vault even does and don’t care to either (it’s backup software probably). To make things worse it even causes my system to lag sometimes which I notice as my audio glitches up when that happens. I don’t always listen to breakcore you know, so I do noticed that sometimes.

I also noticed that uninstalling Dell Data Service is pointless as (I think) the Dell UpdateService will just reinstall it. Which sucks.

So I see two options.

  1. Uninstalling all Dell related software. This is kinda drastic and you might want that stuff if you need support after all.
  2. Disable the software and prevent it from starting up altogether.

So how do you stop those services from starting up automatically? Here’s how:

  1. On you desktop, press WindowsKey-R, this brings up the Run prompt.
  2. Type services.msc and hit enter. This brings up the list of services installed on your machine.
  3. Look for the Dell ones in the list.
  4. Open them, one by one, and in the General tab select the startup type “Disabled”.
  5. Hit “OK” to save.

How to disable a service from auto-starting.Note that in the screenshot I’m disabling a completely innocent service per demonstration as I don’t have a Dell machine handy with an English version of Windows on it.

From now on those pesky services won’t be wasting your resources anymore, untill the day you might need them again. All you have to do then is go back into the services console and switch the startup type back to Automatic and save.
Then right-click the services in the list and choose “Start”, or simply reboot the machine.

But we’re not quite there yet. There’s still the case of PCDoctor and the SupportAssist client. Those sneaky startups are hidden in the scheduled tasks. You can disable them using the Task Scheduler like this:

  1. Press WinKey-R and type Taskschd.msc, press enter.
  2. In the list of scheduled tasks in the root node you’ll see a “Dell SupportAssistAgent AutoUpdate” or something similar.
  3. Right click the task and choose “Disable”.
  4. Repeat for any other Dell tasks in there.

They don’t all have “Dell” in their name, but if you check the Action tab below the path to the executable will give them away (like in the screenshot). In my case I had some additional PCD (PC Doctor) tasks and one SystemToolsDailyTest task to disable.

Another good tool to disable scheduled tasks if from the CCleaner tools menu, or by using the SysInternals Autoruns tool.The name of the task doesn't tell, but the path to the executable does indicate it's a piece of Dell software.

This worked for me, but as is mostly the case with things you find on the internet… use this info wisely and at your own risk. ;)

Photo by Massimo Regonati, cc-licensed.

chocolatey package update quick reference

gingerbread2011_18

Chocolatey rocks when it comes to updating a bunch of installed software from the command line. If you’re not doing that often however it can be hard to remember exactly what commands you can use to do that quickly. So here’s a little run-down on the most helpful commands when you are updating your system.

First you might want to check what’s installed on your machine.
You can get the list of the local package Chocolatey installed like this:

chocolatey list -localonly

or in short:

clist -localonly

To check if any package have updates available, we can run the update all statement, but not quite for real yet. By adding the -whatif switch, Chocolatey only pretends to update:

chocolatey upgrade all -whatif

or:

cup all -whatif

Ready to update all packages at once? Nice. So let’s disable those confirmation prompts while we’re at it too by adding the -y switch.

chocolatey upgrade all -y

or

cup all -y

Edited 2017-02-26 : replaced deprecated update command with the new Chocolatey 1.0 upgrade command.

Photo by elidr, cc-licensed.

the ultimate android space clearing guide

If you’re running into that annoying problem where you can’t install yet another awesome app on your Android phone because you are running out of space, here’s the ultimate guide to freeing up app space *dramatic music*

1. Clean up app cache

Bansky street cleaner - Chalk Farm

Your phone stores apps on its internal memory card (not RAM, but the disk) including some temporary data for each app. That cached data is the first thing you can go and remove to free up space. Depending on the app, this can be quite some data. Think apps that download resources like video or images, create thumbnails etc.

You can do this manually with the internal app settings screens and go over each app individually. I bet you have better things to do though. Instead you can install ES Task Manager, which has a cache cleaner built-in and does the job for you. Sweet. There are plenty of alternative cache cleaning tools available if you don’t like the ES one.

2. Move apps to the external memory card

Still not enough space? Damn. To free up space on the internal memory card, you can also move some apps to the external card. If you have that option, you can use the application tools to move apps individually. Not all apps support this and it usually doesn’t free up all the space either. There’s always some core files that stay on the internal drive, so don’t expect any miracles. The best way to go about it, is to sort the apps by size and try to move the biggest ones first. But if that doesn’t do the trick you might want to…

3. Uninstall some apps

Yep. Makes sense doesn’t it. The bigger the better too. It sucks, but there’s probably some stuff in there you haven’t used in months. Time to say goodbye and press the delete button. Aah, instant free space.

4. When all else fails.

Still not working? I had that. My internal memory was showing 250MB of free space and I couldn’t get a 40MB app like Chrome to update anymore. Same thing with any other app around that size. They all failed to update.
It doesn’t make sense when you look at the numbers, but my guess is that it’s like with a fragmented disk drive on a PC. At some point there isn’t a large enough open space to fit the update file in one piece. Or that 250MB of free space isn’t just for apps. I’m not sure. But what I am sure is that resetting the phone wipes the internal disk space, and frees everything up again.

Photo by Dan Brady, cc-licensed.

a vim http log file syntax plugin

Log files are dull to look at. Lines and lines of text and no pretty colors to make it nicer to look at and easier to spot those weird errors you can’t simulate on your machine.

Vim rocks and writing a syntax file is supposed to be a breeze judging from the vast amount of syntax plugins out there. I didn’t quite find one I liked for syntax highlighting HTTP log files, so I thought I’d get down and dirty with some vimscript myself and see if I could hack something together.

It turned out alright I think. So to share the fun I’m hosting the logsyntax.vim plugin on Github and the vim.org scripts library for all to use. It highlights dates, HTTP verbs, URLs, IP addresses etc for IIS, W3C extended, NCSA and probably a bunch more typical log formats.

May your logs be pretty and colorful from now on.

The vim log file syntax highlighting plugin screenshot. Look at those pretty colors.