Stitching and Appending Images (Screenshots / Memes) Vertically with Imagemagick

Stitching or stacking images can be relevant for publishing them to some websites. Meme sites like 9gag or similar have a specific layout format for โ€œlongpostsโ€ (very long images) that are displayed without scaling and are often used as a format for webcomics or a compilation of images.

I was wondering if anyone on there was interested in photography and decided to stack some of my yet unpublished pictures of the Axel Towers in Copenhagen. Turns out nobody really cares about photography there, but hey, if you have more appropriate material, Iโ€™m sharing the imagemagick command here.

Continue reading “Stitching and Appending Images (Screenshots / Memes) Vertically with Imagemagick”

Music Monday: Combichrist

Combichrist has been on my track list for a while, I think over the past six years on and off. Only recently I’ve watched a couple of interviews and become aware of the controversy around one of the drummers of the band. I don’t condone racist or homophobic statements what so ever.

The contents of the lyrics and music videos are quite offensive as well, but for me that’s booked under freedom of speech and expression, similar to Rammstein (see later in the post). As stated in interviews, interpreting the band should be closer to watching a horror movie and not to take it was any kind of political statue or direction.

If you’re into dark or dance themes like Rob Zombie, Rammstein or the like, give them a listen.

Continue reading “Music Monday: Combichrist”

How to use iOS Safari localStorage and sessionStorage in Private Mode

In short, you can’t, but you can set a cookie via JavaScript ๐Ÿ˜‰ Safari on iOS supports localStorage, but in Private Mode it simply throws an error when you try to save anything to it, which is not great. Also it breaks the behaviour of your app on iPhones and iPads. Long story short: You can’t use it, but you’ll not know until it’s too late.

So the error message Safari throws when you attempt to save anything to localStorage is the following:

Error: QUOTA_EXCEEDED_ERR: DOM Exception 22

Sessionstorage on Safari in private mode will not help us either, because the data saved to it will not persist through a page switch. Common use cases for saving in localStorage could be user preferences that affect your JavaScript UI when you’re using Vue.js, React, Angular or when you implement an age gate somewhere on your site.

I believe I only ran into this because I used localStorage directly instead of using some kind of wrapper around it, which you easily can do with Persist.js which supports the following stores:

  • flash: Flash 8 persistent storage.
  • gears: Google Gears-based persistent storage.
  • localstorage: HTML5 draft storage.
  • globalstorage: HTML5 draft storage (old spec).
  • ie: Internet Explorer userdata behaviors.
  • cookie: Cookie-based persistent storage.

That sounds pretty great!

If you for any reason want to roll your own cool thing or you literally only need to save a string or two in case of private Safari on iOS and keep the more complex stores to sane browsers (I’m not kidding, Firefox, Chrome and even edge get this) you can just write a fallback.

A common practise is to save a JavaScript object to localStorage and to read it on page load like so:

Let’s imagine we want to save the awesome status:

localStorage.jonathan = JSON.stringify({awesome:true});

Now on the next page load, we would love to know the value of awesome. One could be tempted to simply do this:

var savedValue = JSON.parse(localStorage.jonathan);

Don’t! It will just give you the following error message if

  1. the user has never even seen your site (first page load ever)
  2. the user uses Safari in private mode
  3. the user uses a devices that has 0kb free space (can’t write without space)
  4. the user has cleared their cache
Uncaught SyntaxError: Unexpected token u in JSON at position 0
    at JSON.parse (<anonymous>)
    at <anonymous>:1:6

Instead, if you don’t want this to crash your app, always try/catch JSON.parse, always:

var savedValue = {};
try {
    savedValue = JSON.parse(localStorage.jonathan); // get from localStorage if it exists
} catch (e){
    console.log('Something bad happened while trying to parse the localStorage!');
    console.log(e); // if you want to read the error
    savedValue.awesome = false; // assign default value
}

If you’re in a position where you can afford to do silly things for the sake of science, team building or you just want to annoy your sloppy coder colleagues, open a I didn’t try/catch JSON.parse jar instead of a swear jar. You’ll have pizza money until the end of your days.

Let’s take care of Safari once and for all. localStorage doesn’t work and neither does sessionstorage, but you still can set a cookie. More precisely you can set a session cookie, not one that persist until after the browser tab is closed, but that’ll do for a lot of cases, I mean that’s as far as we’ll go without GPU fingerprinting or other shady things that might be illegal in some countries.

Since I’m a lazy person and I don’t enjoy writing a ton of stuff for weird old implementations of things, I recommend you have a look at Cookies.js for all your cookie saving and reading needs. Also interesting is the Mozilla page and their simple cookie framework.

The framework is really simple to use and I suggest you use it after a test if localStorage saving works fails:

Cookies.set('awesome', 'true'); // note that this is a string, not a boolean

That’s it! Let me know if you’ve experienced other fun issues with Safari ๐Ÿ˜‰

SQL Dump Probing

I witnessed this attack recently, basically it’s just some web crawler trying different file names that somebody could have given a mysql dump that they by accident left inside a public directory of a web project.

Disclaimer: What’s explained in this post could be used in dual use cases. Explaining how the attacker works will ultimately help everybody preventing attacks and raise awareness for the attacks.

Continue reading “SQL Dump Probing”

A Comical Guide to Webpack, Vue.js 2, Gulp and WordPress [Tutorial]

Building WordPress themes and plugins is a big market and it gets a lot of people into web development, so I named this post like I did, but it really works for most CMS, no matter if you want to write a theme for WordPress, Drupal, GHOST, Magento or what ever else is out there. I’m going to show a simple webpack config that helps you transpile your JavaScript and develop your themes as usual.

TLDR; Here’s how to do stuff and me rambling in between. Use one of these links to get to your preferred headline:

Continue reading “A Comical Guide to Webpack, Vue.js 2, Gulp and WordPress [Tutorial]”

Best Programming Language (and Tutorials) for Beginners

Which programming language to learn or which one to learn next is one of the eternal struggles of being a developer. For beginners there is a myriadic jungle of choices and every developer they know tells them something different.

The key to learning your first language or which language to recommend to beginners actually is not the language itself, but which path they’re going to take. There is a lot of opinion on which language somebody should learn first, so here’s mine.

Continue reading “Best Programming Language (and Tutorials) for Beginners”

Chester Bennington

News have travelled the internet quickly and the note of Linkin Parks front singers suicide hit me like a truck. Through a Tweet.

Linkin Park were one of the first bands I could basically quote music from in my teenage years and probably one of the reasons why I learned English a lot quicker than I usually would have. To really understand and appreciate their lyrics.

Continue reading “Chester Bennington”

Watched: Arrival

Arrival is a different Alien coming to Earth movie and it was probably one of the best ones I’ve seen so far, along District 9. It’s a thriller and not a horror film and the main plot revolves a lot around how to establish a meaningful channel of communication with the foreign visitors, which is exactly what makes this movie so interesting.

For everybody who’s just a bit into languages, the movie will be interesting. It’s bundled with some very high grade cinematography and very pleasant to watch.

International politics and trigger happy military leaders play an important role in the movie too and how the world in general would react to such a powerful threat.

I really liked it, give it a watch, even though you usually aren’t into Aliens.