2012-07-25

Today I Learned: SQL Union

Sql unions allow you to treat a common set of columns between two tables as a unified table, or rather it allows one to group the result sets from two sql queries into 1 result set as if it came from one table.

Vim Again

The pendulum seems to be swinging back toward me using Vi / Vim as my primary text editor. Or rather using Vi style keybindings, sine I was still often using Vim, just with Emacs style keybindings (via vimacs)

I may still use Emacs proper, but I think it will be mainly in the context of working with other programs, or substantial tasks, rather than using it for quick edits.

Standard

2012-07-24

C++ BigInteger class

I’ve been going through the first Project Euler problems again, this time in C++. I’m reaching the point where I need some kind of an arbitrary precision integer math library.

Today, I actually find myself thinking about trying to write my own string integer class. I’m sure this isn’t efficient, and while I’m fairly sure I could deal with large integer addition, I’m not at all sure about subtraction or multiplication or division.

Standard

2012-07-23

The sum of all knowledge

It seems to me that pretty much every paradigm in programming is probably present in some form in one of the following three languages:

  • C++
  • Perl
  • Common Lisp

That makes me wonder if it’s worth studying those three languages to try to have access to the interesting ideas that other smaller languages tend to specialize on.

Programming Language Bundles

These days I often find myself trying to come up with sets of languages that would cover all the application domains that I am interested it.

One bundle that I have often considered is C++, Python, and Haskell. I don’t know that it deals with every area as well as the above combo of C++, Perl, and Common Lisp, but there are some nice overlaps semantically between the languages. I find that I can use a sort of hybrid Haskell and Python notation as a pseudo-code that I can then translate into C++.

There’s enough overlap between Python’s default data structures and STL data structures in C++ that I can mostly mechanically translate a simple Python program into C++.

Standard

2012-07-17

Run with g++

I had a fun realization today.

The simple shell script below which I named "run"

#/bin/sh
g++ $* && ./a.out

would let me compile and run simple programs without it being obvious that there was a compile / link step.

Thus I can just do:

run hello.cpp

and get "hello world".

Standard

2012-07-13

JavaScript As Cross Platform GUI

I’ve been thinking about GUI toolkits the past couple of days. It’s been annoying to realize that the even with the 3 major cross-platform toolkits (Qt, Wx and Tk) you can really only target the major desktop OSes (Windows, OS X, Linux). There’s no way to apply that learning to any of the mobile space.

To my mind JavaScript/HTML/CSS is really the only technology where what you learn in one environment would really transfer to all of the other environments readily.

However, that leads to the question of how you actually do desktop apps in JavaScript/HTML/CSS. Currently I’m thinking that you start a lightweight web server and the use that as the application engine.

If you are interested in being able to deploy the app then it’s important that the webserver be self contained. It also needs to be written in a language that has the libraries / capabilities to interact with whatever host systems you need to connect to (filesystem, database, etc).

The architecture that makes the most sense to me currently is to write a webserver where urls are mapped to functions rather than files, so that each function you need the interface to support is simply a separate url for an http call.

Then the HTML page in the browser just makes an http call for each user action that requires activity from the engine.

Standard

2012-07-10

Current Languages

Here are the current languages that I’m thinking I want to be my staple languages:

  • C
  • Go
  • Perl
  • PHP
  • JavaScript
  • Erlang

Each of these gives something that the others don’t provide. It seems like SML might be trying to sneak in there also. I also can’t totally discount Tcl in the realm of providing things the others don’t. However, I currently find Tcl a little frustrating to program in. But that may be because I tend to push it too hard when I try things in it. I think it excels as a portable command line script engine, but it becomes kind of annoying to me when I try to do intensive processing with it.

Standard

2012-07-08

3-day Weekend

This Weekend I took Friday off so Jayne and I could go to El Campo to visit her extended family and see her aunt and uncle celebrate their 50th wedding anniversary. Aside from visiting, I did the following:

  • Went through "A Tour of Go" – wrote all example programs, but no exercises
  • Wrote a couple Project Euler problems in Go
  • Finished A Little Java, A Few Patterns
  • Finished chapter 1 of Mastering Algorithms with Perl
  • Finished chapter 2 of Minimal Perl

Not much sight seeing, but fairly productive in study and socializing.

Standard

2012-07-05

Python Blog

Continuing my whirlwind tour through scripting languages, Here are the main parts of my site generator redone in Python:

Site Generation

os.chdir("entries")
entries = os.listdir(".")
entries.sort()
entries.reverse()

posts = ""
for e in entries:
  cmd = "markdown %s" % e
  post = os.popen(cmd).read()
  date = e

  post_html = template_post % (date,date,post)
  posts += post_html

main_page = template_master % posts

print main_page

Table of Contents

#!/usr/bin/env python

import os
import sys
import re

output = []
for arg in sys.argv:
    with open(arg) as f:
        for line in f:
            if (re.search(r"^###", line)):
                date = arg
                line = re.sub(r"### ", "", line)
                line = re.sub("\n", "", line)
                output_line = '<a href="index.html#%s">%s</a><br>' % (date, line)
                output += [output_line]

output.reverse()
for line in output:
    print line

Python SimpleHTTPServer

Also serving the site using the below code utilizing Python’s included SimpleHTTPServer package.

import SimpleHTTPServer
import SocketServer
import os
import grp
import sys

PORT = int(sys.argv[1])
user = int(sys.argv[2])
group = int(sys.argv[3])

Handler = SimpleHTTPServer.SimpleHTTPRequestHandler

httpd = SocketServer.TCPServer(("", PORT), Handler)

os.setgid(group)
os.setuid(user)

print "dropped privileges to user: %s group: %s" % (os.getuid(), os.getgid())
print "Serving at port", PORT
httpd.serve_forever()

Favorite Programming Languages

Currently the list of languages that I am most attracted to is:

  • C
  • Go
  • Perl
  • Erlang
  • JavaScript

This is different from the languages that I would actually claim to be somewhat competent in:

  • C (would like to be more so)
  • Awk
  • Tcl
  • Python
  • JavaScript
  • PHP (somewhat)

I feel like I’m becoming competent in Perl, and I am working to become competent in C# and possibly F# since those are languages that are used or potentially used at work.


Emacs Setup

Setting up yet another emacs instance:

Here are the entries in .emacs that I have to have:

(setq-default indent-tabs-mode 'nil)
 (global-set-key [(control h)] 'delete-backward-char)
Standard

2012-07-04

Interesting PHP Things

Two interesting pieces of software written in PHP. I’ll need to check them out further at some point.

  • FatFreeFramework (F3) – here
  • kelpie (psgi/wsgi/rack style webserver in php) – here

update: Also possibly: this

*SGI/Rack Implementations

Here are the different implementations of web server middleware protocols in the wsgi/psgi/rack family

  • Rack – Ruby – Maybe the original?
  • WSGI – Python – Or maybe this was original?
  • PSGI – Perl
  • JSGI – JavaScript
Standard