2012-11-30

favorite vim colorschemes

i prefer colorschemes where the syntax highlighting for particular constructs is essentially the same in both the gui and terminal versions of vim.

here are the pre-installed ones i like.

  • delek
  • morning
  • blue

i’ve also created several that are the same terminal and gui wise.

(search for stingray, montz, or reloaded on http://www.vim.org)

Standard

2012-11-15

Bookmark App In Ruby

Here’s a little app I wrote using Ruby and Sinatra to keep track of links that I want to come back and read.

It displays the newest links at the top of the page kind of like a stack.

Code is a little messy, but it works.


#!/usr/bin/env ruby
require 'rubygems'
require 'sinatra'

get '/' do
  page = <<EOHTML
<html>
<head>
<title>bookmarks</title>
</head>
<body>
<p><a href="/add">add new bookmark</a></p>
#{htmlize}
<h6>powered by Sinatra</h6>
</body>
</html>
EOHTML

  page
end

get '/remove/:id' do
  remove(params[:id])

  page = <<EOT
<html>
<head>
<title>bookmarks</title>
</head>
<body>
<p><a href="/add">add new bookmark</a></p>
<h2>Bookmark Removed</h2>
#{htmlize}
</body>
</html>
EOT
end

get '/add' do
  page = <<EOT
<html>
<head>
<title>bookmarks - add</title>
</head>
<body>
<form action="/add" method="post">
  <input type="text" name="link">link<br>
  <input type="text" name="topic">topic<br>
  <input type="submit" name="submit" value="submit">
</form>
</body>
</html>
EOT
end

post '/add' do
  add(params[:topic], params[:link])

  page = <<EOT
<html>
<head>
<title>bookmarks</title>
</head>
<body>
<p><a href="/add">add new bookmark</a></p>
<h2>Bookmark Added</h2>
#{htmlize}
</body
</html>
EOT

end

def add(topic, link)
  outfile = open("bm.data", "a")
  outfile.puts "#{topic}\t#{link}"
  outfile.close
end

def show
  infile = open("bm.data", "r")
  infile.each { |line| puts line }
  infile.close
end

def list
  infile = open("bm.data", "r")
  contents = infile.readlines
  infile.close
  contents
end

def htmlize
  output = ''
  lines = list
  id = lines.length + 1
  output << "<table>\n"
  lines.reverse.each do |line|
    id = id - 1
    output << "<tr>\n"
    (topic, link) = line.chomp.split(/\t/)
    output +=<<EOT
<td><a href="/remove/#{id}">[X]</a></td>
<td>#{topic}</td>
<td><a href="#{link}">#{link}</a></td>
EOT
    output << "</tr>\n"
  end
  output << "</table>\n"
  output
end

def remove(id)
  infile = open("bm.data", "r")
  outfile = open("bm.data.new", "w")
  count = 0

  infile.each do |line|
    count = count + 1
    outfile.puts line unless id.to_s == count.to_s
  end

  infile.close
  outfile.close
  File.rename("bm.data.new", "bm.data")
end

arbitrary precision arithmetic in c and c++

here are the packages i have found easiest to deal with for doing arbitrary precision integer arithmetic in c and c++. i have used ttmath with c++ the most. it’s not technically an arbitrary arithmetic library since you have to declare the bit size of the integer you want to support. but you can make that bit size as large as you want.

for c it seems like the bn library that is included in openssh is the easiest to work with. i’ve looked at gmp a bit, but it’s a lot of complexity if you don’t need it’s features.


current books

i seem to be working my way through learn ruby the hard way at the moment. so i’m actually reading three books right now.

  • unix shell programming
  • simply scheme
  • learn ruby the hard way
Standard

2012-11-13

current books:

i’m considering setting aside classic shell scripting for the moment and instead focusing on unix shell programming.

so at the moment the books i’m looking at are:

  • unix shell programming by stephen kochan
  • simply scheme by brian harvey and matthew wright

rewrite website generator in pure shell?

considering doing a full version of the site generator in unix shell. mainly as a way to firm up my understanding of shell scripting. i’ve had a shell script to generate the archive listing before, but never the main page.

i don’t know what i would use as the web server if i did that.

Standard

2012-11-12

c++ and c: protothreads

provides linear code execution for event-driven systems.

"lightweight stackless threads"

reminds me of go’s goroutines when go is running under a single cpu core.

see writeup and analysis at following:

actual implementation for c:

implementation for c++:


co-routines in c


continuation passing c


2 books at a time

i think i’m going to try to be reading 1 book about my pragmatic languages list and 1 from my research languages list. at the moment the two books are:

  • practical: classic shell scripting (shell)
  • research: simply scheme (scheme)
Standard

2012-11-11

tcl: fileevent

fileevent or its synonym chan event is a tcl command that basically registers a callback to be executed when a particular channel (which i believe can be a file or a stream or socket) becomes either readable or writable. basically it registers an event handler that get’s executed when the specified channel can either accept or receive data.

Standard

2012-11-10

confidence languages

here are the languages that if i had to build an application myself, and needed high confidence that i could complete that application successfully, these are the languages i would choose from.

  • perl
  • tcl
  • shell (sh / sed / awk)
  • php
  • javascript
  • c++
  • go

2nd tier languages (working knowledge)

here are the languages that i could work on an application written in. i’m sure i could write an application in one of these if i had to, but i wouldn’t plan to choose them for an application that depended entirely on my skill to complete.

  • ruby
  • python
  • java
  • c#
  • c

interest languages

here are languages that i’ve played with, and i understand the concepts of, and may research for insight or interest, but i wouldn’t trust myself to build something complete or successful with.

  • scheme
  • common lisp
  • haskell
  • erlang
  • forth (i have written a couple of minimal or proto-forth interpreters in awk and javascript)
  • lua

future research languages

these are languages that i have interest in researching at some point, but have no practical experience with at the moment.

  • clojure
  • f#
  • sml

avoidance languages

there are languages that for whatever reason i have decided i don’t want to invest time and effort in learning at the current time.

this is not to say these languages aren’t valuable, just that for me to invest in them would represent a major change in direction for me, or more investment than i feel like i would gain back from the language at this point in my life.

  • ocaml
  • scala
  • factor
  • pascal
  • cobol
  • fortran
  • smalltalk

browser caching results

using the go directory server code, i have been unable to prevent browsers from caching old information. i’ve been trying to see if i could use html meta tags in the html pages to prevent caching.

so far, i have been unable to prevent caching across browsers, using any combination of html meta tags that i tried. i think i managed to get chrome to avoid caching, but nothing i tried seemed to work on firefox.

i think i’ll need to investigate sending http headers, however, that is going to require knowing more about the go http framework. that’s going to probably require me to abandon the easy to use go directory server example and end up writing my own server implementation.

seven work languages and seven fun languages

so based on my listing above, i think i want to try to learn or at least study something each day about one of the languages that i would choose if i needed high confidence.

  • perl
  • tcl
  • php
  • javascript
  • shell (sh / sed / awk)
  • c++
  • go

in addition, i think i would like to maybe pick one language a week to read a book on, probably from the following list (mostly of "interest languages").

  • c
  • scheme
  • common lisp
  • haskell
  • erlang
  • forth
  • sml

website serving update

until i can figure out a way to enable proper caching behavior, i’ve gone back to using tcl code from earlier to serve the website. so far it doesn’t seem to cause the problematic behavior.

on the plus side, it is basically written in raw tcl, and is (with modifications i made) only 57 lines. so reading through it again (as i wish to) should be a fairly useful and enlightening experience.

shell : change dos line endings to unix

tr -d '\r'  unix-file.txt
Standard

2012-11-06

20121106

arbitrary editor

i’m experimenting with changing the scripts for this blog generator to use whatever editor is set in the $editor variable.

that way i can switch between vim and emacs depending on my mood 🙂

wanting to create: go binding to tk toolkit

i’ve looked around a couple of times for someone having done this. so far i haven’t found anyone. so i’m beginning to think about trying to do it myself.

i don’t really know where to start, but i’d probably try to take a look at what python did with tkinter.

i don’t know how relevant tk still is with the movement toward mobile, and proprietary gui technologies by apple and microsoft. javascript/html/css seems to be the only really cross-platform technology supported these days, which go has pretty decent support for with it’s included http package.

however, i still like tk, and it might be useful for times that a desktop app is still possible. i suppose i could also look at whether there are cross platform bindings to qt, wxwidgest or gtk from go. i haven’t really liked the look of gtk, but it might have reasonable cross platform support because of the mono guys at this point.

browser caching

i’m trying figure out chrome’s behavior as far as caching with respect to this site. this is a test post.

this is mostly to try to figure out whether the caching is happening in chrome or in the go server.

added meta-tag to hopefully disable caching.

testing meta-tag now. see if firefox works with new tag.

added new expires tag. adding max-age tag. removing expires tag. testing1 testing2 testing3 testing4 testing5 testing6 testing7

Standard

2012-11-05

Go Site Generator

Here is the site generator I wrote in Go:

package main

import (
    "fmt"
    "io/ioutil"
    "os/exec"
    "os"
)

var template_master = `
<html>
<head>
<title>Actually</title>
<style>
    hr { border: 1px dashed #efefef; }
</style>
</head>

<body bgcolor= "#efefef">
    <center><h1>Actually</h1></center>
    <center><h3><i>It's Randolph Connor Berry</i></h3></center>
    <center>
    <i>~~~ A journal of daily thoughts, hopes, and explorations ~~~</i>
    </center>
    <center>
    <a href="toc.html"><i>Archives</i></a>
    </center>
%s
</body>
</html>
`

var template_post = `

    <div style="background-color:white;
                border:1px dashed;
                padding-left: 1%;
                padding-right: 1%;
                margin-left:auto;
                margin-right:auto;
                margin-bottom:10px;
                width:40%;">
        <h2><a id="%s">%s</a></h2>
        %s
    </div>

`

func main() {
    os.Chdir("entries")
    entries, _ := ioutil.ReadDir(".")

    // reverse entries
    for i, j := 0, len(entries)-1; i < j; i, j = i+1, j-1 {
        entries[i], entries[j] = entries[j], entries[i]
    }

    posts := ""
    for _, e := range entries {
        date := e.Name()
        cmd := exec.Command("markdown", date)
        post, _ := cmd.Output()

        post_html := fmt.Sprintf(template_post, date, date, post)
        posts += string(post_html)
    }

    main_page := fmt.Sprintf(template_master, posts)
    fmt.Print(main_page)
}

Table Of Contents In Go

Here is the code that generates the table of contents / archive listing:

package main

import (
    "fmt"
    "os"
    "io/ioutil"
    "strings"
    "regexp"
)

func main() {
    output := make([]string, 1)
    for _, arg := range os.Args[1:] {
        content, _ := ioutil.ReadFile(arg)
        data := string(content)

        lines := strings.Split(data, "\n")

        for _, line := range lines {
            found, _ := regexp.MatchString("^###", line)
            if found {
                date := arg
                line = strings.Replace(line, "### ", "", -1)
                line = strings.Replace(line, "\n", "", -1)
                output_line := fmt.Sprintf("<a href=\"index.html#%s\">%s</a><br>", date, line)
                output = append(output, output_line)
            }
        }
    }

    // reverse output lines
    for i, j := 0, len(output)-1; i < j; i, j = i+1, j-1 {
        output[i], output[j] = output[j], output[i]
    }

    for _, line := range output {
        fmt.Println(line)
    }

}
Standard