Author Archives: n3wjack

tweet from the command line

I could've used a screenshot of a command line window but instead you get a nice humming bird. Because, you know, twitter.

It’s so simply it’s hardy worth a blog post, but since a simple tweet isn’t so easy to find using a search engine, I’ll just put it up here anyway.
Let’s say you come up with this brilliant joke or insight and you want to tweet it instantly to the world. Now you have to open up a browser, type in that dreadfully long twitter.com URL, wait for the site to load, type in your tweet and hit send.
Man. That’s a lot of work.

But what if you could just enter this from the command line?

tweet OMG I love tweeting from the command line

Wow. That would be awesome. Because you always have a console window open anyway, being an edgy and trendy developer using all those nifty command line tools right?
You betcha.

So how about that awesome batch script? What does that look like? Well here you go:

@start "" "https://mobile.twitter.com/compose/tweet?text=%*"

That’s all it takes. Save that as tweet.cmd and put it somewhere that it’s in your PATH environment variable so Windows can find it and run it.
It’ll launch the twitter mobile site, and all you’ll have to do is hit “Send”.
So sweet.

cool vim tips and tricks you might not know

Vim has tons of awesome shortcuts and features you pick up over time. Some of those I don’t use every day so I have to write them down so I can look them back up when I can’t remember exactly how it works. Instead of keeping them locked away in a text file, I’ll throw them online here and spread the Vim love. None of these need any special plugins. They should all work right out of the box with plain old Vim.

If you want to know more about a specific command listed here, use the Vim :help command to find out more. There are usually more options and possibilities for each of these commands and the Vim documentation is excellent.

Here we go!

When you are on the command line using a console application and you want to edit the output in Vim right away, or open that long list of possible command line switches in Vim for reference, this one will come in handy.
I’m using GVim here because since that opens in a separate window from your shell, this is the most useful.

ls *.txt | gvim -
docker -h | gvim -
git --help | gvim -

This one is for opening a ton of files in a single Vim instance from Powershell, in different tabs. This means you are running this from a Powershell console of course.

gvim -p (ls *.ps1)

For more Vim command line options run this in your favorite shell environment:

vim -h
gvim -h

How about opening a remote file, or fetch HTML from a page over HTTP using Vim:

:e https://n3wjack.net/

When you work with log files a lot, being able to delete lines containing or not containing a specific word can be just what you need.
These two commands are perfect to filter out obsolete exceptions and figure out what is causing that nasty production issue:

:g/DeleteAll/d
:v/DeleteAllButThis/d

Did you know that Vim has a spell checker? I didn’t know that at the beginning (try :h spell for more details).
To activate/deactivate:

:set (no)spell

To jump to the next / previous misspelled word:

]s
[s

To get a list of spelling suggestions (or use the mouse in GVim, which is quite practical):

z=

You can add a simple XML-tidy shortcut to your .vimrc file by adding the following command.
What it does is setting the file type to XML, removes spaces between opening & closing brackets, add a return character in-between the opening & closing brackets and finally formats the document so it looks all nice and indented.

nmap <leader>ppx <Esc>:set filetype=xml<CR>:%s/> *</></g<CR>:%s/></>\r</g<CR><ESC>gg=G<Esc>:noh<CR>

You can force syntax highlighting in Vim as follows for e.g. HTML, XML and Markdown.
Of course this works for a ton of other file types as well, as long as you can figure out what the extension/file type key is. But that’s pretty easy in most cases.

:set syntax=html
:set syntax=xml
:set syntax=md

I add shortcuts for any files I frequently edit by using the leader key and a letter combination that’s easy to remember.
For example this one to edit my custom .vimrc file when I press the leader key followed by “e” and “v” (edit vimrc).

nnoremap <Leader>ev :tabe ~\vimfiles\nj-vimrc.vim<CR>

That’s about it. For more nice Vim tips check out more Vim posts. Another good resource for bite sized Vim tips is the MasteringVim on twitter and it’s newsletter.

chill and drones 2

TAMT presents F-lithium - ...This Place Could Be My Undoing coverBad Sekta is a bit of an oddball British label releasing all sorts of electronic music, and recently they released 35 minutes of dark drone-y ambient you can download for free.
Since I like free music, I downloaded it through the online shop and gave it a whirl. Turns out this long-piece of dark ambient seems to be putting you into the metal bowls of spaceship flying through dark uncharted sectors of the galaxy. Or something like that. Anyway, it’s great to put up in the background and have it loop a few times, which you won’t notice, and get some work done.
So download Tamt presents F-Lithium, “…This Place Could Be My Undoing” and get spacin’.

Now that where at it, how about revisiting a good source for tons of ambient live mixes recorded to the trusty mp3 format? Remember the Chillits ambient festival? Well they have most of their live sets online, so you can pick and choose between hours of chilled beats, ambient sounds and other down-tempo tunes mixed and selected for your pleasure by top notch ambient DJ’s. If there is such a thing.

You can pick from the 2017 mixes, but mixes from previous editions are available too.
From the 2017 mixes, these are my mostly beat-less favorites: Brian Behlendorf, Dave Espionage, Indy Nyles, Jeremy Meadows, Souls and Cities, Subnaught, and Verdun 1916.
Also check my other ambient posts for more chilled goodness.

windows 10 upgrade on a dell xps 17 / L702x

I clean installed Windows 10 on my Dell XPS 17 L702x a while ago already and this post is merely here to indicate: yes, it works and it’s not even a big deal. This also got rid of Dell software junk preinstalled on my machine which is awesome.

Dell doesn’t support the Windows 10 upgrade though, which is why it scares people and your mileage may vary, but in my case the only thing that didn’t work anymore after the upgrade is my SD card reader. The drivers for that device haven’t been updated since the Windows 7 version and I didn’t find anything more recent. It took me a few months to find out it was broken, so that shows how much I need that thing.

So to summarize:

You can upgrade your OS or do a clean install with Windows 10, but your SD card reader will not work afterwards. If your life depends on that card slot on the left, it’s wise not to upgrade.

As always, be careful with drastic operations like this and backup your data first. For real this time. Plenty of stuff can go wrong and knowing that your data is safe makes it a lot less stressful if shit does happen to hit the fan.

querying Elasticsearch with Powershell with a little help from Kibana

KeyboardKibana is a great dash-boarding tool to easily query an Elasticsearch store on the fly without having to know exactly how to write an Elasticsearch query. For example if you’re using Logstash to dump all your logfiles into an Elasticsearch DB and use Kibana to nail down that specific weird exception you’re seeing.
Kibana is great to show some graphs and give a pretty good overview, but what if you want that query data and do some processing on that? You can’t really export it from the dashboard, but for each of those table or graph panels on your dashboard you can click the “Inspect” button and see what Elasticsearch query is used to get the data for the panel.

It looks something like this:

curl -XGET 'http://yourserver:9999/logstash_index_production/_search?pretty' -d '{
"query": { ...
}'

This is a curl statement and contains all you need to run the same query using PowerShell. The easiest thing to do is to copy the whole JSON statement into a text file and strip out the curl bit and the URL. You keep the URL handy because that’s the URL you’ll need to target in the Invoke-Restmethod call.
If you refactor it into something like the statements below and save it as a .ps1 file you can run it from the command-line and get the results back as PowerShell objects parsed from the JSON result. Yes. PowerShell is that cool. ;)

$elasticQuery = @"
{
"query": { ... }
}
"@

$elasticUri = 'http://yourserver:9999/logstash_index_production/_search?pretty'
Invoke-Restmethod -uri $elasticUri -method POST -Body $elasticQuery

To store the results in a local variable you just run it like this:

$r = .\RunElasticQuery.ps1

Now you’re free to run all sorts of funky processing on the data or perhaps dump it to a CSV file.

If you’re good enough at the Elasticsearch DSL you can even skip the Kibana query shortcut and modify the query itself in your PowerShell script.

Photo by Jeroen Bennink, cc-licensed.

stop the EU from destroying your internet freedom

The EU Parliament will debate and vote on Article 13 & 11. Time to fire up your email and social media devices and let yourself be heard again, which is why I’m resurfacing this post about the what and the why.
The fight is still not over so sign the petition and let yourself be heard.

Yep. They are at it again, those pesky governments. If it ain’t the US trying to destroy net neutrality it’s the EU trying to setup a link tax and an automated content filter/surveillance/censorship machine.

I’m talking about the copyright reform law the EU is trying to get through in a few days.

Article 11 is bad. It tries to setup a link tax, meaning you cant link or post snippets to e.g. news articles on your site. A similar law was passed earlier in Spain and it causes Google news to simply pull back out of Spain. If the same happens to the whole of the EU, that would suck mayor balls.

Article 13 is far worse though. That’s the content filter, which means any site where content can be uploaded e.g. Facebook, Twitter, Instagram, Imgur etc will be forced to automatically scan your upload and filter it if it isn’t allowed. The claim is that they want to stop terrorists and bad people from spreading illegal content on the internet. The reality will be that those bad guys will find ways around it and the rest of us will be stuck with a filter that’s going to block our uploads because of flawed algorithms and bureaucratic decisions. Internet memes use copyrighted content, but will the filter be able to detect sarcasm? I don’t think so.

Hey look, a meme, with a copyrighted image. I guess we won't be able to do that anymore once Article 13 is in effect.

To quote Tim Berners Lee, the inventor of the WWW:

Article 13 takes an unprecedented step towards the transformation of the Internet, from an open platform for sharing and innovation, into a tool for the automated surveillance and control of its users.

So please help out and email, tweet or call your MEP’s and make it clear Article 11 & 13 have to go. The freedom of the internet depends on you!