Posts

How to be an idiot at coding part infinite + 1

2023-11-20 range, headers,, ruby

We had some code read partial responses from a server. This code was tested thoroughly and worked as intended. We got the amount of bytes we needed from the head of a file, and then were able to parse that data as a binary blob.

One of those "I just needed to deploy"-days

2023-09-25 diary

It all began when I had to deploy a change, that needs to go live today.

Pretty Print json in vim

2023-06-29 json, vim, pretty-print

I hand edit json many times a week. For that reason the vim command for doing a quick pretty printing of json in current buffer usually is muscle memory for me; however I mistyped it twice today, and decided to make a command and a keybinding for it instead. (Even though I will probably forget it in a couple of days, and revert to typing the command by hand).

Our most simple transcoding service

2022-04-27 transcoding, hdr, sdr, ffmpeg, videos, sqs

At Fliva we had an issue; customers kept uploading iPhone footage in HDR formats with varying framerates, and our software could not handle it. The colors looked washed out, and just plain wrong.

Writing a Progress Bar Overlay Shader

2022-03-11 glsl, shader, videos, fliva

Some of our customers in Fliva want to show a simple progress bar inside their video. You see this a lot nowadays in social media videos, where the progress of the video is embedded inside it so that you, as the consumer of the video, know how much more you need to watch.

Writing a Hubot Adapter for Bitrix

2022-03-10 hubot, chatbot, bitrix

Back in the day, we installed hubot on our Hipchat developer chat. When hipchat got sold to Atlassian we jumped ship and chose Slack instead. Years later the company chose to invest heavily in having a shared system across all division handling tasks and CRM primarily - but since this tool also had a chat function, we dropped the slack instance, losing access to all the nice Hubot integrations we wrote over the years.

</div>

Corona Beats from Last Year

2022-03-10 corona, hiphop, beat, music

Last year I spent some time one afternoon making a short corona-beat. I never really shared it… Now it’s here…

Decoding Video Frames with ffmpeg/libav

2022-01-04 ffmpeg, c++

Opening the file

Install Datadog in Kubernetes

2021-06-04 kubernetes, monitoring, datadog

First of all, we use helm. So we start here: https://docs.datadoghq.com/agent/kubernetes/?tab=helm

Just Create a Relation

2021-05-18 database, relation

I recently read You might as well timestamp it and today I came across an equal truism

Basic Breakout Game with Raylib

2021-05-17 game, raylib, c++

I have always wanted to write games. Back in the day that was the whole idea why I wanted to be a programmer. And I have worked myself into a new job at Fliva exactly because I wanted to become a game programmer.

Know your assumptions, and test them

2020-02-04 howto, advice, debugging

In my day to day I very often stumble upon yet another issue in one of our software systems that needs fixing. And most often, the issue is rather apparent and easy to fix.

Much more than ten albums that shaped my taste in music

2020-01-29 music, taste, album

My wife began this challenge on Facebook. Each day post an image of an album cover of music that shaped your taste in music… The rules states that you should say why, just post the image (and the rules) and tag someone new each day. (My wife as a good Facebook-citizen of course denied to do that last part)

A ring buffer for audio samples

2020-01-21 audio, programming

At Fliva we work with audio (we have a c++ library that essentially works as a audio sequencer), video (we have a rendering engine which basically works as a scriptable After Effects clone) and we do transcoding, muxing and all that jazz…

Formatting Xml Files with xmllint

2017-05-10 xml, xmllint

I am currently working on a project where I need to parse Open Xml files comming from the Office Suite. As you may already know this involves opening what is essentially a zip file full of xml files.

Using tcpdump to Spy on Webservers

2016-11-10 tcpdump

I recently had to debug an error where stuff that should have been returned through a server to server call did not work correctly. Both servers -

</div>

How to Read a File in C#

2016-11-08 polyglotbits, csharp, read-a-file

Csharp was probably the first compiled language I really loved. When the first version of .net came out I wrote a small CMS using C# and the new runtime. (A big step up from old school asp)

How to Read a File in Lua

2016-10-28 polyglotbits, lua, read-a-file

Reading a file in lua is pretty straight forward.

How to Read Program Arguments in Lua

2016-10-25 polyglotbits, lua, read-program-arguments

Lua is among the programming languages - that I write about here - I have used the least.

I Wrote a Pong Game with My Son using Cocos Creator

2016-10-21 family-time, game, pong

My son (Toke, 7 years old) and I have long talked about making our own computer game.

How to Read a File in C++

2016-10-04 polyglotbits, c++, read-a-file

Reading a file in C++ is almost identical to how it’s done C.

How to create a plugin system in C++

2016-10-04 c++, plugins

To create a plugin system in C++ you need three things.

How to parse JSON in Rust

2016-09-19 polyglotbits, rust, parse-json

To parse json in Rust you need a library. The one used here is called rustc-serialize.

How to parse JSON in C++

2016-09-16 polyglotbits, c++, parse-json

In C++ there are no built-in ways to handle json. However there are many open source libraries to help you.

How to read a file in Java

2016-09-13 java, read-a-file

Java is - off course you might joke - rather verbose when it comes to reading files. However most of the verbosity has to do with importing the functionality from the standard library.

How to parse JSON in GO

2016-09-10 polyglotbits, go, parse-json

The go standard library has all you json needs covered. The JSON package has methods for both encoding and decoding to/from JSON.

How to parse JSON in Elixir

2016-09-06 elixir, parse-json

Parsing JSON in elixir requires an external tool - and you’ll need to define the types the data needs to be parsed into.

Watching the Social Network Lets Me Focus on Work

2016-08-31 movie, productivity

I love working to some kind of (controlable) background noise. Something I can mostly ignore while working, but that I can focus on when loosing my train of thought. Mostly I use music but lately I have found that (some) movies helps me as well.

How to Write to a file in JavaScript

2016-08-23 polyglotbits, javascript, write-to-a-file

Writing a file in Javascript is as easy as using the built-in method fs.writeFile, and as such matches the read file method quite well

Printing C++ Objects to stderr/stdout

2016-08-08 c++,, stderr,, stdout

When your C++ projects grow a little, you may find yourself needing to log the state of objects. There are two ways of doing this (assuming that you’ll want to log the data the same way each time).

How to Solve Euler 1 in JavaScript

2015-12-04 polyglotbits, javascript, euler-1

The Euler 1 problem is fairly simple to solve. Most people intuitively know how to do it. Here is how I would do it in JavaScript.

How to Write to a file in PHP

2015-12-03 polyglotbits, php, write-to-a-file

The simplest way of writing to a file in php is using the file_put_contents function. This implicitly calls fopen, fwrite and fclose, as we know from e.g. c.

How to Read from stdin in Haskell

2015-12-02 polyglotbits, haskell, read-from-stdin

In haskell there are two ways to read the stdin stream. Which one to use depends on what you’re trying to accomplish I guess.

How to Read from stdin in C++

2015-12-01 polyglotbits, c++, read-from-stdin

Reading from stdin in C++ is surprisingly concise. Only 12 lines of code (including includes and empty lines).

How to Write to a file in C

2015-11-30 polyglotbits, c, write-to-a-file

Writing to a file in c is surprisingly simple. Most of the steps in c can be found in most other languages as well. In c you open a file, write to it and close it again. In most languages you either do the same exact steps - or have a higher level construct that does the same thing for you - but every language will ultimately make the same sys-calls that the c languages shows us directly.

How to Read a file in JavaScript

2015-11-27 polyglotbits, javascript, read-a-file

Reading a file in Javascript (again, nodejs) is as easy as using the built-in method fs.readFile (however it needs to be required first).

How to Read a file in Go

2015-11-26 polyglotbits, go, read-a-file

In go you will sometimes write more code than you are used to in e.g. most higher level languages (think php, ruby, python) - but will have a lot more control over how it is done.

How to Read from stdin in Lisp

2015-11-25 polyglotbits, lisp, read-from-stdin

Just as with reading program arguments - lisp looks a bit weird when reading from the stdin stream. That is until you get the hang of it.

How to Read program arguments in Lisp

2015-11-24 polyglotbits, lisp, read-program-arguments

Lisp is a completely different way of looking at programming than e.g. ruby is. Where in Ruby everything is an object - in lisp everything is a list. Which makes sense, since lisp is an acronym for LISt Processing.

How to Write Json in Ruby

2015-09-11 polyglotbits, ruby, write-json

Just like when parsing json in ruby you need to require the json library to write hashes and arrays to json strings. Unlike Javascript and PHP you don’t call a function with one parameter representing the data you want to convert to json - instead you can call to_json on the object you want to convert.

How to Parse Json in Ruby

2015-09-10 polyglotbits, ruby, parse-json

In Ruby you parse json by first including the json library (either the one provided with the language - or any one of the gems that provide the same functionality)

How to Write Json in PHP

2015-09-09 polyglotbits, php, write-json

In PHP JSON stringify and parse are part of the core libraries - however in PHP they are called json_encode and json_decode respectively. The latter was shown in the post about parsing json in PHP.

How to Parse Json in JavaScript

2015-09-08 polyglotbits, javascript, parse-json

As already stated in the post about how to write json in javascript, JSON is an integral part of the JavaScript language.

How to Read from stdin in Java

2015-08-31 polyglotbits, java, read-from-stdin

Reading from stdin in java looks like in most languages. Standard in is bound to System.in - and must be opened as if it where a file just like in c.

How to Read from stdin in Ruby

2015-08-28 polyglotbits, ruby, read-from-stdin

Reading from stdin in ruby is as easy as calling STDIN.read

How to Write a TCP Echo Server in Ruby

2015-08-24 polyglotbits, ruby, write-a-tcp-server

In ruby you have lowlevel access to all the same methods that you do in C. But you also have some higher level sugar on top of that - and a program that does the same as the c version, is almost as concise as it is in javascript. You get no free concurrency here though - you still need multiple processes or threads to achieve that.

How to write a TCP Echo server in Javascript

2015-08-21 polyglotbits, javascript, write-a-tcp-server

If c is the most verbose way to write a tcp server. Javascript (nodejs) is probably the least verbose way.

How to Write a TCP Echo Server in C

2015-08-21 polyglotbits, c, write-a-tcp-server

In c you are as close to the metal - or at least as close to the os - as possible in a high-level language. This shows in the verbose code you need to make a simple tcp server which echos messages back to the client. Furthermore this implementation of the server will only ever accept one client - and when that client disconnects, the program exits.

How to Read from stdin in JavaScript

2015-08-20 polyglotbits, javascript, read-from-stdin

In javascript (nodejs anyway) stdin can be read as a stream of bytes. Therefore you need to tell node which encoding it is (utf-8 in our instance). We do the reads on the readable event, and read as much data as we can and print it to stdout.

How to Read from stdin in PHP

2015-08-19 polyglotbits, php, read-from-stdin

Reading from stdin in PHP is just like reading a file. The only difference is that the file to read is called php://stdin

How to Read a file in Elixir

2015-08-18 polyglotbits, elixir, read-a-file

Reading files in elixir is pretty straight forward - especially if you just want the content of a file you know exists. And that case it is a oneliner just like in php.

How to Write Xml in Ruby

2015-08-17 polyglotbits, ruby, write-xml

In Ruby there is no built-in support for parsing and writing xml. There are however a couple of gems (packages) that allow you to do exactly this. If you are working in Rails - you have this for “free” with ActiveSupport (which you could also just require as a standalone package). This gives you a to_xml on a hash which is dead easy to use. There is also the xmlsimple gem which is a port of the same library from perl.

How to Read Program Arguments in PowerShell

2015-08-15 polyglotbits, powershell, read-program-arguments

I don’t know much about PowerShell to be honest. It sounds to me like it is some kind of a windows version of bash/zsh. Nevertheless, IISResetMe wrote up a quick hello arguments script - and let me share it with you:

How to Read Program Arguments in Perl

2015-08-15 polyglotbits, perl, read-program-arguments

IISResetMe has made another Program Arguments script. This time in perl. Reading perl has always been weird for me. I have never used perl for much myself - but I have written a lot of php and a lot of ruby - and it shows where they have borrowed many of their ideas.

How to Read Program Arguments in C#

2015-08-14 polyglotbits, csharp, read-program-arguments

In C# program arguments (like in most c-based languages) are a part of the main method signature. Like in java this variable is an array of strings.

How to Read from stdin in Elixir

2015-08-14 polyglotbits, elixir, read-from-stdin

Elixir is rather easy - as long as you get past the pattern matching barrier I stumpled into when writing about how to read program arguments.

How to Write Json in JavaScript

2015-08-13 polyglotbits, javascript, write-json

Since json is short for JavaScript Object Notation - it does not come as a surprise that is a natural part of the javascript language. The JSON module has two methods that you’ll use all the time when working with rest (both server and client side). JSON.parse makes a json string into a JavaScript object, and JSON.stringify makes a JavaScript object into a json string.

How to Read a file in PHP

2015-08-13 polyglotbits, php, read-a-file

Reading a whole file is as easy as one function call in PHP. (Especially good if you want to read a small file, and want all the data in memory anyway).

How to Parse Json in PHP

2015-08-13 polyglotbits, php, parse-json

Once again php shows how it is an easy language for beginners. In PHP you don’t have to think about much when you want to parse json. Json parsing and encoding has been part of the core php language for several version now - and before that as an extension with the exact same methods.

How to Read from stdin in Go

2015-08-12 polyglotbits, go, read-from-stdin

Reading from stdin in go is as easy as reading from os.Stdin - the ioutil.ReadAll method reads all bytes into a buffer and allows you to handle the input once it is read. If you need to stream data to a go program you need to read os.Stdin in some buffered way - since ioutil.ReadAll blocks until it receives a EOF.

How to Read from stdin in C

2015-08-12 polyglotbits, c, read-from-stdin

Reading from stdin in c - is exactly like reading from a file. (In unix philosophy - everything is a file after all). This means that the how to read a file program is almost the same when reading stdin.

How to Read a file in Ruby

2015-08-11 polyglotbits, ruby, read-a-file

In ruby you read a file in two steps. First open the file, and then iterate over the contents. (In this instance we loop over the contents of a text file so the built-in each_line is what we want.)

How to Read a file in C

2015-08-11 polyglotbits, c, read-a-file

Reading files in C is very easy. First you need the stdio.h header file included, then you need a pointer of type FILE, and you call fopen on a filename (setting a flag to tell what access you want - here we just want read access).

How to Read Program Arguments in Rust

2015-08-10 polyglotbits, rust, read-program-arguments

Rust reminds me of C in many ways. The program arguments include the program name at the first index, but unlike C you have to make a function call to get the options. let args: Vec<_> = env::args().collect();

How to Read Program Arguments in Haskell

2015-08-10 polyglotbits, haskell, read-program-arguments

This is the one programming language to date where I have had the hardest time doing the little hello world program that prints a hello line per input argument.

How to Read Program Arguments in Go

2015-08-09 polyglotbits, go, read-program-arguments

There seems to be two schools of program options reading in programming languages. Those who have a main method where arguments are explicitly mentioned in the method signature, and those who have another way of reading the data. Go has a main method, but it has no arguments in its signature - you read the program arguments from os.Args (which requires you to import the os package).

How to Read Program Arguments in Elixir

2015-08-08 polyglotbits, elixir, read-program-arguments

Elixir is fundamentally different than many of the programming languages most people use.

How to Read Program Arguments in JavaScript

2015-08-07 polyglotbits, javascript, read-program-arguments

In JavaScript (nodejs) you can access the program arguments in the array process.argv. Like in C it includes the program name but unlike e.g. PHP and Ruby it also includes the path to the intepreter (the path to the node executable). Thus you have to skip two entries in the array to get to the real arguments to the program.

How to Read Program Arguments in Java

2015-08-06 polyglotbits, java, read-program-arguments

In Java like in e.g. C the program options are part of the main method signature.

How to Read Program Arguments in Ruby

2015-08-05 polyglotbits, ruby, read-program-arguments

Ruby has a global ARGV array which contains all arguments. Contrary to e.g. C and PHP it does not, however, contain the script name. This means the hello world program is very concise, since we do not need to handle the no argument / 1st argument issue.

How to Read Program Arguments in PHP

2015-08-04 polyglotbits, php, read-program-arguments

In PHP the program arguments of current script is always available in the $argv variable except when it is not.

How to Read Program Arguments in C

2015-08-04 polyglotbits, c, read-program-arguments

In C program arguments are part of the main method signature.

Generate Source Files With CMake

2015-07-31 cmake, c++, code, generation

Sometimes when writing c++ programs I have some textual data that I want to use in the program that I want to be part of the executable instead of in flat files next to the executable. However while developing it is far easier to have the textual data in separate files - instead of in source files as strings.

Trim Strings in C++ with Boost

2015-07-22 boost, clang, c++, string, trim

One of the biggest grievances with I had when I started writing a lot of c++ code was that a lot of things that we take for granted as built in things in other (primarily dynamic) languages are all a bit harder to do (right) in c++. This means that for things like simple string manipulation you often need outside help. For the most common cases though, there is boost.

Split Strings in C++ With Boost

2015-07-22 c++, boost, split, string

I just wrote about how to trim strings with boost. The code where I first needed to trim a string, was actually very simple naive parser where strings of key value pairs would be split, and then each part trimmed to ensure that both key and value was without leading and trailing whitespace. When you want to split a string in c++ you again probably want to use the boost library - more specifically boost/algorithm/string/split.hpp. This allows you to split a string by a character (or rather a substring) into a vector of strings.

Where I Go To Learn

2015-06-07 books, buffer, hackernews, pocket, podcasts, reddit, screencasts, videos

I try to learn a new thing every day. Sometimes it is a big thing sometimes something small.

So, you forgot to make a git branch?

2015-06-07 git

It happens to me at least once a week. I meant to make a topic branch. But I dove into the code too quickly - and suddenly I am a couple of commits into what at the moment seems like an important feature or bug fix, and I realize - I have committed to the master branch. This is a big no no in our company - bypassing code review, and a push on master most often means instant deploy.

Writing Intelligent Keyboard Shortcuts in Elisp

2015-04-13 emacs, spacemacs, lisp, shortcut, vim, keyboard

In my quest to get better aquainted with my new editor I decided to make some intelligent keyboard shortcuts for my blogging repository. I decided to have one keyboard shortcut that could publish the current draft (with jekyll publish) and one to create a new draft (with jekyll draft).

A Walkthrough of My Spacemacs Configuration Files

2015-04-11 emacs, orgmode, spacemacs

My two week vacation is comming to an end. I have had one week of doing

</div>

Considering a Switch from Vim to Emacs?!

2015-04-06 aptana, eclipse, emacs, homesite, lisp, netbeans, notepad, spacemacs, sublime-text, textmate, vim, visual-studio, zend-studio

People joke about that I change my blogging platform and editor of choice only to have something to write about. And I guess I change both more than most people. My changes of blog engines may be a subject of another post.

Why I gave away a domain name

2015-03-11 domains, give-away, ideas

Like so many of my colleagues I have a disease. I think it could be called “Idea Induced Domain Hogging”. You know that thing that happens in three easy steps. Develop gets idea, developer buys domain, developer proceeds to do nothing. What happens next depends on the individual. Sometimes you realize your mistake after one year, and stop paying for the thing. Sometimes you actually do real work and put something into the world - maybe someone actually uses it … But most often - the domain is forgotten until a reminder is sent (and my registrar sends them a lot).

Merge Clover XML Files

2015-02-28 clover, codeclimate, php, xml

We have a single git repository with a large project that is split into two separate PHP application (api and client). We use travis for running tests and deploying to production and CodeClimate to keep an eye on our code quality.