Mar 01

Closing Down PolyGlotBits

I had a great idea at some point: Write about how to do small simple tasks in a lot of different programming languages to try to teach the differences and similarities between different languages.

Nov 10

Using tcpdump to Spy on Webservers

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 - in development mode at least - was on my local machine. But since I had to hack either an external dependency or the sending server to find out what was actually being sent between the servers - I realized this was a great time to utilize the tcpdump tool.

Nov 08

Simple ANSI Library for C++

For some time I have had the idea that when I have written enough lowlevel mini-tutorials about how to do the most basic things in every language I have ever worked with on Polyglot Bits I would begin doing small projects.

Nov 08

How to Read a File in C#

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)

Oct 28

How to Read a File in Lua

Reading a file in lua is pretty straight forward.

Oct 25

How to Read Program Arguments in Lua

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

Oct 21

I Wrote a Pong Game with My Son using Cocos Creator

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

Oct 18

Project Ideas I want to Work On

An alternative to Omnifocus and Todoist

Oct 04

How to Read a File in C++

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

Oct 04

Creating a Plugin System with C++

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

Sep 27

Writing ANSI Escape Strings With C++

The other day I saw Gary Bernhardts live streaming - ok I didn’t see it live, but anyway - of writing an editor in Ruby. It made me think that it would be a great topic for my other blog polyglotbits.com. So while I pondered how to write a very basic editor in every language on the site I continued watching Gary’s stream, and look at his program selecta which he referenced quite a lot in the cast.

Sep 19

How to parse JSON in Rust

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

Sep 16

How to parse JSON in C++

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

Sep 13

How to read a file in Java

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.

Sep 10

How to parse JSON in GO

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

Sep 06

How to parse JSON in Elixir

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

Sep 05

How to Create your own Keyboard Shortcuts in HyperTerm

NOTICE: This may be obsolete. I stopped using HyperTerm again! (Too many things failed). The project has been renamed (to “Hyper”). And the special handling for danish keyboards seems to have been fixed. All in all - you may learn a bit about how to create keyboard shortcuts - but the specifics are probably unusable now.

Aug 31

Watching the Social Network Lets Me Focus on Work

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.

Aug 23

How to Write to a file in JavaScript

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

Aug 23

Printing C++ Objects to 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).

Dec 04

How to Solve Euler 1 in JavaScript

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.

Dec 03

How to Write to a file in PHP

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.

Dec 02

How to Read from stdin in Haskell

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.

Dec 01

How to Read from stdin in Cpp

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

Nov 30

How to Write to a file in C

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.

Nov 27

How to Read a file in JavaScript

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).

Nov 26

How to Read a file in Go

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.

Nov 25

How to Read from stdin in Lisp

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.

Nov 24

How to Read program arguments in Lisp

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.

Sep 11

How to Write Json in Ruby

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.

Sep 10

How to Parse Json in Ruby

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)

Sep 09

How to Write Json in PHP

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.

Sep 08

How to Parse Json in JavaScript

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

Aug 31

How to Read from stdin in Java

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.

Aug 28

How to Read from stdin in Ruby

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

Aug 24

How to Write a TCP Echo Server in Ruby

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.

Aug 21

How to write a TCP Echo server in Javascript

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

Aug 21

How to Write a TCP Echo Server in C

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.

Aug 20

How to Read from stdin in JavaScript

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.

Aug 19

How to Read from stdin in PHP

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

Aug 18

How to Read a file in Elixir

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.

Aug 17

How to Write Xml in Ruby

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.

Aug 15

How to Read Program Arguments in Perl

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.

Aug 15

How to Read Program Arguments in PowerShell

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:

Aug 14

How to Read Program Arguments in C#

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.

Aug 14

How to Read from stdin in Elixir

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.

Aug 13

How to Write Json in JavaScript

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.

Aug 13

How to Parse Json in PHP

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.

Aug 13

How to Read a file in PHP

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).

Aug 12

How to Read from stdin in C

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.

Aug 12

How to Read from stdin in Go

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.

Aug 11

How to Read a file in Ruby

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.)

Aug 11

How to Read a file in C

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).

Aug 10

How to Read Program Arguments in Haskell

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.

Aug 10

How to Read Program Arguments in Rust

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();

Aug 09

How to Read Program Arguments in Go

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).

Aug 08

How to Read Program Arguments in Elixir

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

Aug 07

How to Read Program Arguments in JavaScript

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.

Aug 06

How to Read Program Arguments in Java

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

Aug 05

How to Read Program Arguments in Ruby

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.

Aug 05

Rendering Sprite Sheet in Canvas

A couple of months back I wanted to live stream some code. I ended up starting a breakout clone in Html5 / Canvas / Js - but never got past figuring out the basics of how to render items from a spritesheet into a canvas as seperate sprites and some animation stuff before my life as a parent got in the way. I will not be live streaming anything in the near future - and the code has not moved forward in four months, but I thought that the code should serve as a lesson somehow.

Aug 04

How to Read Program Arguments in PHP

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

Aug 04

How to Read Program Arguments in C

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

Aug 03

Yapaf Introduction - how to write your own mvc in PHP

Back in the day before Symfony, ZF, Cake, Yii, Typo3 Flow and Laravel (and all the others) - you had to roll your own framework if you wanted to do something big in php. I had an app that I needed to write, and none of the early versions of MVC frameworks in PHP was appealing to me. I decided to write my own. Even though that framework was never released, and never intended to be used for anything else - I believe it has taught me (and a couple of other people) a bit or two about how to (and how not to) build mvc’s in php.

Jul 31

Generate Source Files With CMake

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.

Jul 22

Split Strings in Cpp With Boost

Splitting strings in cpp is a bit different from high level languages

Jul 22

Trim Strings in Cpp with Boost

Use the boost library to trim a string in cpp

Jun 23

Quick Docker Hacking with Envy

Jeff Lindsay - also known on twitter and github as progrium - has just released a small tool called Envy.

Jun 15

Git Quick Tip - forgot to create a branch

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 bugfix, 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.

Jun 07

Where I Go To Learn

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

May 17

Almost Halfway - 35 Years on Earth

LIfe is short - and then you die

May 10

Beeminding my Blog Writing

Meta post about beeminding my blog - written because I am derailing in the first week!

Apr 13

Writing Intelligent Keyboard Shortcuts in Elisp

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).

Apr 11

A Walkthrough of My Spacemacs Configuration Files

My two week vacation is comming to an end. I have had one week of doing absolutely nothing productive on the computer - apart from playing around with emacs, org mode and configurations. And then I had a couple of days where I was completely home alone. I have been working on my secret project, as well as live coding some javascript canvas stuff and getting my feet wet in lisp and emacs configuration, literate programming with org-babel (oh is that the only awesome way I have worked with R).

Apr 06

Considering a Switch from Vim to Emacs?!

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.

Mar 19

What my Milk Thermometer Taught me About TDD

Last christmas (yeah I know long time ago, bear with me) I got a Milk Thermometer as a Christmas Present from my In-Laws. Even though they have probably spoken to my wife about that - it still amazes me how awesome they are at picking gifts for that I end up loving.

Mar 11

Why I gave away a domain name

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).

Feb 28

Merge Clover XML Files

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.

Jan 13

Simple Queueing of Requests: a File Lock

We have a system which over the years have scaled up a couple of times. When we first created it, we decided against doing a “real queue” system like ActiveMQ and the likes.

Jan 12

Full Circle and back to Jekyll

I have written a lot of blogposts over the years about which technologies I have used for my blogs, how I use them and why I chose them. This is yet another one of those - however I’ll try to be brief.

Jan 05

Tech Masturbation

Not a day passes without me checking twitter, hackernews and a lot of subreddits on reddit about all the new stuff I ought to learn relating to my work and passion: programming!

Jan 02

How to write a cat (reading files in c)

The basics of how to implement the cat command in c

Nov 17

Tmux Plugin Manager

What is Tmux Plugin Manager

Nov 14

Self Surveillance Dashboard

I am trying to closely monitor my productivity while working. For this reason I have a couple of metrics that I use to show on a dashboard on my iPad.

Nov 13

Typing, you need to practice

I love writing. I do it much. Developers are really just some sort of glorified writers. But while many of us, present company included, are very good at learning new technologies, techniques for building apps and all of that exciting stuff - most of us forget that it is the art and craft of typing that lets us do what we do.

Nov 10

What is love?

This could have been a long essay about the nature of love. Philosophic and deep.

May 02

Sharpen your saw

After a couple of months of only minor maintenance of our php codebases, I have dived deeper into php coding this week. And two things reallly annoyed me (apart from the fact that I was back coding php).

Apr 23

Running rspec Tests From vim in Another tmux Pane

When I write ruby code I usually write it in a tdd/bdd style using rspec as a test framework. I want to run tests directly from vim, but I do not like running tests through guard (don’t ask me why - I have no real answer).

Apr 03

What Makes a Good Side Project?

All developers have had this offer at one point.

Apr 02

Ruby, its about the concise code

Today I reviewed a co-workers code. And in a couple of minutes we rewrote it to be as concise - yet still expressive - as it could be. This is one of the things I love about ruby.

Mar 26

ES6, CommonJS or Amd

TL;DR doesn’t mather - pick one and use that.

Nov 23

Quantified Self and Me

I have become quite serious about this whole Quantified Self movement. I guess as a developer it is easy to be caught up in that. And I have in large periods of time use RescueTime to monitor myself, but at times used more time analyzing the rescuetime data, than I saved from selfmonitoring. (I actually had to set up rescuetime as unproductive in rescuetime).

Oct 21

Combining Concetrate, Moom, iTerm and Tmux

My blogposts are written in markdown - using terminal vim as my editor. Each kind of task I work on occassionally have been created as an activity in Concentrate. I have hooked my concentrate app up to alfred - and thus I can start an activity easily directly from alfred. This enables me to reduce all distractions, and open everything I need to perform the task.

Oct 07

Some Quick Tips for Using Dash

I love dash. It allows me easy access to documentation to different programming languages and frameworks, without needing to be online. And it allows me to easily search for the documentation. This means I can work anytime, anywhere on most of my projects.

Sep 05

Alfred2 Workflow for Controlling Concentrate

Back in march I wrote about how I fought procrastination with my hosts file hack. I have since then abandonned this practice, but bad habits die slowly - and I sometimes need to educate myself a bit. I have had a license for the Concentrate app for years now - and I decided to use that this time around.

Aug 27

Writing Shell Functions in zsh

If you want to customize your zsh experience (and you have oh-my-zsh installed), you should know how to extend your shell with custom functions.

Aug 22

Customizing the zsh Prompt with oh-my-zsh Themes

There are a lot of ready made themes for oh-my-zsh users. You can even get a screenshot of each of the themes from a shared dropbox folder. So why would you ever need to know how to make your own theme?