2012-11-04

Website Now Served By Go

I’m now serving this website using the following Go code:

package main

import "net/http"

func main() {
    panic(http.ListenAndServe(":80", http.FileServer(http.Dir("/home/cberry/blog/public"))))
}

I had to use setcap with capabilities(7) to get this to work on port 80, since I haven’t been able to figure out how to modify or write the Go code to bind to port 80 and then drop privileges afterwards. Arguably capabilities is the better tool, as it doesn’t require me to switch to root initially to run the process, before dropping privileges. However, it is also less familiar to me, so I’m not as certain that I’m not leaving some other kind of security hole through my ignorance.

Binding Privileged Port with Setcap

Here is the command I had to run to allow an executable to bind to port 80 without running the executable itself as root:

setcap 'cap_net_bind_service=+ep' <executable_file>

I’m not sure whether you would also have to include the "inheritable" flag for it to work on a multithreaded executable or not. Also, the file must be a true executable, it will not work if it is a shell script or file being executed via an interpreter without additional steps.

setcap is in package libcap2-bin in Debian and Ubuntu. It installs in /sbin and setcap itself must be run as root (or via sudo I suppose).

Website Generator Rewritten Using Go

I have now completed the rewrite of my blog generation software in Go. I’ll have more analysis of the comparison with other languages at some point.

C# Release Handle (Pointer)

Here are links to how to release an IntPtr:

Standard

2012-09-27

Why Ruby?

I’m writing this in an attempt to identify why I’ve recently switched focus to Ruby.

I suppose there are several motivations.

The first is the feeling that if I’m going to only have a limited time to be able to work on personal programming, then I want to concentrate on either on languages and environments that give the most effect for the effort expended or on languages that are useful in terms of some concept that I want to understand.

In that line, the languages that seem to me to give the most bang for the buck in terms of time invested vs results are:

  • Ruby
  • Go
  • Tcl
  • shell / Perl
  • JavaScript

Languages that seem good for understanding concepts include:

  • Scheme
  • Haskell
  • SML
  • C

I’ve previously focused more on Python for personal programming. Here is my attempt to understand why I feel like moving away from it. These are all personal reasons, which doesn’t make them wrong, but definitely doesn’t make them right.

Python 2 vs 3 split:

  • I’m tired of wondering when I will be able to actually concentrate on one version of the language.
  • Python 3 seems to have deprecated or removed many of the things that I actually liked about Python 2 such (print as a function, old style format strings, etc). The new focus on everything being keyword arguments seems overly verbose to me.
  • 3rd party libraries in Python are still split along the Python 2 / 3 lines.

Python Concepts:

I’ve recognized that I really only understand a subset of Python.

There are still things like decorators, and list comprehensions, and Python’s version of Object-Orientation, that have been added to Python since I first looked at it, that while I can sort of look at them and tell what’s going on, I never have the urge on my own to really use them. Therefore there are vast swaths of Python’s complexity that are simply useless to me.

Python’s reluctance about Functional Programming:

I actually like functional programming concepts like map, filter, etc. To me, the pythonic insistence on using list comprehensions in place of those functions does not really fit my brain.

Even though I would not argue that Ruby is a more functional oriented language, the practical effect of it’s emphasis on method chaining makes functional style effects (think of shell pipelines but in code) easier to create and use.

Ecosystem:

Mostly it comes down to a frustration with the Python ecosystem and culture of software development. I’m tired of there being so many things that sort of work, but not completely.

Standard

2012-09-26

Blog Now On Ruby (Again)

For the moment at least I’m switching this blog’s site generation software and webserver back to using Ruby.

I don’t have a real reason for the change, other than that I’m moving towards considering using Ruby more these days.

Languages Which Have My Interest Currently

Languages that I find myself attracted to at the moment:

  • Ruby
  • Go
  • JavaScript
  • C

And Possibly:

  • Erlang
  • Haskell
Standard