We will need this for our server configuration
- Open console
A running example of the code from:
This gist creates a working example from blog post, and a alternate example using simple worker pool.
TLDR: if you want simple and controlled concurrency use a worker pool.
Concurrency is a domain I have wanted to explore for a long time because the locks and the race conditions have always intimidated me. I recall somebody suggesting concurrency patterns in golang because they said "you share the data and not the variables".
Amused by that, I searched for "concurrency in golang" and bumped into this awesome slide by Rob Pike: https://talks.golang.org/2012/waza.slide#1 which does a great job of explaining channels, concurrency patterns and a mini-architecture of load-balancer (also explains the above one-liner).
Let's dig in:
| #include <stdbool.h> | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <unistd.h> | |
| #include <linux/input.h> | |
| #include <fcntl.h> | |
| #include <stdarg.h> | |
| #include <stdint.h> |
| #!/bin/sh | |
| repo_name=$1 | |
| test -z $repo_name && echo "Repo name required." 1>&2 && exit 1 | |
| curl -u '[username]:[password]' https://api.github.com/user/repos -d "{\"name\":\"$repo_name\"}" | |
| git init | |
| git add . | |
| git commit -m "initial commit" | |
| git remote add origin "https://github.com/[username]/$repo_name.git" | |
| git push -u origin master |
| syntax on | |
| set number | |
| set noswapfile | |
| set nocompatible | |
| set autoindent | |
| set backspace=indent,eol,start | |
| set complete-=i | |
| set smarttab | |
| set tabstop=4 |
When hosting our web applications, we often have one public IP
address (i.e., an IP address visible to the outside world)
using which we want to host multiple web apps. For example, one
may wants to host three different web apps respectively for
example1.com, example2.com, and example1.com/images on
the same machine using a single IP address.
How can we do that? Well, the good news is Internet browsers
| package main | |
| import ( | |
| "fmt" | |
| "github.com/gorilla/mux" | |
| "github.com/gorilla/securecookie" | |
| "net/http" | |
| ) | |
| // cookie handling |
| function laiska() { | |
| git add -A | |
| git commit -m "$1" | |
| } |
| groupBy(data, unwindKey, calcKey) { | |
| let output = {}; | |
| // function that we call each item in data | |
| let sum = function(row, index) { | |
| // if not found lets add it to output | |
| if (!(row[unwindKey] in output)) { | |
| output[row[unwindKey]] = row[calcKey]; | |
| } | |
| // Muutoin lasketaan summa |