Median filtering can be used to join multiple images to get a single image with all moving objects removed. The simple idea is to compare the pixels at the same location on all images and get the median of RGBA values of the pixels to form a new composite image with all moving objects removed.

The image set provided has to be taken by a camera that did not move during the shoot, since the pixels at the same location on all images have to correspond to the same physical location. Otherwise, the median filter will blend all images together…


Part 1 — Utility Functions

I have been interested in image manipulation for some time. Last year I worked on a small package that does simple image manipulation using Go’s standard image package: github.com/KorayGocmen/image

Let’s look at how to read an image from a provided file path and creating an image object. This is what the structs will look like.

// GrayscaleAverage, GrayscaleLuma, GrayscaleDesaturation
// are used by grayscale to choose between algorithms
const (
GrayscaleAverage = 0
GrayscaleLuma = 1
GrayscaleDesaturation = 2
)

// Pixel is a single pixel in 2d…


Nodejs + Sequelize

After using Sequelize in my Express applications for the past 6 years, this is how I write my migrations and models for all my Nodejs applications.

Install sequelize with npm first and initialize the project with “sequelize init”. That should create the “models”, “migrations” and “seeders” folders as well as create the “config/config.json” file.

In our application, we’ll have users and cards. Each user can have multiple cards.

We need a users table and a cards table in our database and users will have a one-to-many relationship to cards.

You can find how those two models are associated using the…


Nodejs + Sequelize

After using Sequelize in my Express applications for the past 6 years, I’ve landed on a database file that I’ve been using for all my Nodejs applications.

Install sequelize with npm first and initialize the project with “sequelize init”. That should create the “models”, “migrations” and “seeders” folders as well as create the “config/config.json” file.

In our application, we’ll have users and cards. Each user can have multiple cards.

We need a users table and a cards table in our database and users will have a one-to-many relationship to cards. …


Timer events in Go

I’ve writing production level Go code for the past 4 years now, something that I’ve been using since the beginning is the timer events in Go.

I use timer events like how I would use cron jobs, to run a function or a script in a certain time interval.

I usually pass the timer interval in a config file to be able to change it quickly without changing the code itself.

I wrote about how I approach configuration in Go projects. You can read more here:

// initVN initializes the refresh timer which will
// refresh all known sites if their…


The default HTTP client in Go uses the default DNS resolver available on the machine. There are some cases where you might want to use a different DNS resolver.

I want to quickly show how you can change the DNS resolver for the default HTTP client. We are using this same method for our custom DNS resolver in my company: Violetnorth

// Changing DNS resolverpackage main

import (
"context"
"io/ioutil"
"log"
"net"
"net/http"
"time"
)

func main() {
var (
dnsResolverIP = "8.8.8.8:53" // Google…


I’m not a big fan of the built-in `dgram` and `net` libraries in Nodejs, but it’s really easy to create sockets and write networking applications with Nodejs. One of the biggest issues I’m constantly seeing is the lack of cleanup functionalities when using the socket libraries in Nodejs.

This code is from our DNS npm package that we use in Violetnorth

You can find the Violetnorth — DNS npm package here: github.com/violetnorth/dns

So I’m going to talk about a quick way to clean up sockets with timeouts and overall error handling when dealing with sockets.

If you don’t implement some…


Single scheduler (conductor) and multiple workers

Part 5— The worker

The entry point of the worker is the worker/worker.go file which contains the init and the main functions. Main functions call 2 functions async, which are to start the GRPC server and to register on the scheduler.

// worker/worker.gopackage main

import (
"fmt"
"log"
"os"
"os/signal"
"syscall"
)

var (
// workerID is the id assigned by the scheduler
// after registering on scheduler.
workerID string
)

func init() {
loadConfig()
}

// Entry point of the worker application.
func main() {

go startGRPCServer()
go registerWorker()

sig := make(chan os.Signal)
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)…


Single scheduler (conductor) and multiple workers

Part 4 — The scheduler

The entry point of the scheduler is the scheduler/scheduler.go file which contains the init and the main functions. Main functions call 2 functions async, which are to start the HTTP server (API) and the GRPC server.

// scheduler/scheduler.gopackage main

import (
"log"
"os"
"os/signal"
"syscall"
)

func init() {
loadConfig()
}

// Entry point of the scheduler application.
func main() {

go api()
go startGRPCServer()

sig := make(chan os.Signal)
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)

for {
select {
case s := <-sig:
log.Fatalf("Signal (%d) received, stopping\n", s)
}
}
}

API uses Juline Schmidt’s HTTP router: github.com/julienschmidt/httprouter

API exposes the 3…


Single scheduler (conductor) and multiple workers

Part 3 — The worker overview

Workers expose a GRPC-server to communicate with the scheduler. The main job of workers is to run specific jobs requested by the scheduler and report on those jobs. Jobs can be ruby/python/bash scripts or any executables available on the worker machine.

// jobsMutex is the lock to access jobs map.
// jobs is the map that holds current/past jobs.
// - key: job id
// - value: pointer to the created job object.
var (
jobsMutex = &sync.Mutex{}
jobs = make(map[string]*job)
)

// job holds information about the ongoing or past jobs,
// that…

Koray Göçmen

University of Toronto, Computer Engineering, architected and implemented reliable infrastructures and worked as the lead developer for multiple startups.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store