akuchling: Sherlock Hemlock (Default)
 Apache Zookeeper (http://zookeeper.apache.org/) is a specialized filesystem-like database.
Database features
The database consists of znodes, which are identified by a filesystem-like path, e.g. "/prod", "/solr/status".  Each znode can contain a chunk of content, represented as a string.  It's expected that this content is relatively small, e.g. a few KB and not 600MB.   Unlike a filesystem, a znode can have content and still have children, i.e. /solr can have the value 'active', yet /solr/status, /solr/nodes, etc. can also exist.
It's possible to create an ACL controlling who can read/write a particular node, and also to create a watch that's triggered when a particular node is modified.  This can be used to create data structures inside Zookeeper such as locks or queues.  For example, to create a barrier you might pick a znode path such as /barrier/barrier-id and issue an exists(path) call that also sets a watch.  If exists() returns False, the barrier isn't held and you can create it and then go do your computation.  If exists() returns True, wait for a watch event that tells you the barrier has
been deleted and then try the exists() again.
The database is kept in memory while the server is running.  Changes are logged to disk, so the server can be stopped and restarted as necessary.
Distributed operation
Zookeeper supports distributed operation.  You can configure N zookeeper nodes into a set. Updates made on one node will become visible to clients of all the other nodes in the set.  This is coordinated by a leader node that's elected when the nodes are started.  If the leader node suddenly dies, a new leader is automatically elected.
It was straightforward to set up a 3-node set.  Each node has its own data directory and its own config file.  All the config files have a bunch of settings describing the nodes within the set: 
server.1 = node1:2888:3888
server.2 = node2:2888:3888
server.3 = node3:2888:3888
Each data directory contains a "myid" file that gives the index (1, 2, 3) of which node this is.  Once you start all the servers, they'll elect a leader that will propagate write operations to the other servers.  Clients can connect to any of the servers and should see the same database.
There's a command-line tool, zkCli.sh, that allows running commands on a Zookeeper database.  Example invocation:

zkCli.sh -server zknodeN:2181 ls /
You could use Zookeeper's database to store configuration info, storing data in znodes instead of a set of nested dictionaries as you would in JSON.  This would be primarily a read-only database, but Zookeeper can also be used for applications that need frequent updates.  For example, I've seen references to  using Zookeeper as a status board for a set of servers.  You might run 'apachectl status' on server prod1 every minute and store the output in the znode /apache/prod1.  A monitoring process could then set a watch on /apache and its children, get triggered every time a server updates its status, and then react when one changes from 'running' to 'stopped'.
Zookeeper comes with Java and C APIs.  There's a Python wrapper for the C API, but a more complete package seems to be kazoo (http://kazoo.readthedocs.org/en/latest/).  The README for kazoo says memory management for the C API is difficult, so kazoo is pure Python and supports several different event loops such as gevent and Twisted.  kazoo also has implementations of some common usage patterns such as locks, queues, and elections.
akuchling: Sherlock Hemlock (Default)

Here's what I'm putting on my Hugo nomination ballot. Order is not significant.

Best Novel: "Uprooted", Naomi Novik; "Slade House", David Mitchell; "The Just City", Jo Walton; "Ancillary Mercy", Ann Leckie; "The Shepherd's Crown", Terry Pratchett

Best Novella: "The Pauper Prince and the Eucalyptus Jinn", Usman Malik; "The New Mother", Eugene Fischer; "Waters of Versailles", Kelly Robson; "The Bone Swans of Amandale", C.S.E Cooney; "Inhuman Garbage", Kristine Kathryn Rusch

Best Novelette: "Another Word for World", Ann Leckie; "And Never Mind the Watching Ones", Keffy R. M. Kehrli; "Fabulous Beasts", Priya Sharma; "And the Balance in Blood", Elizabeth Bear; "Our Lady of the Open Road", Sarah Pinsker

Best Short Story: "Loving Grace", Erica L. Satifka; "A Call to Arms for Deceased Authors’ Rights", Karin Tidbeck; "Tear Tracks", Malka Older; "Wooden Feathers", Ursula Vernon "Hic Sunt Monstra", Brian Trent

Best Related Work: "Going Clear: Scientology and the Prison Of Belief", dir. Alex Gibney; "You're Never Weird on the Internet (Almost)", Felicia Day; "The Call of the Sad Whelkfins: The Continued Relevance of How To Suppress Women’s Writing", Annalee Flower Horne, Natalie Luhrs; "Space Helmet for a Cow: The Mad, True Story of Doctor Who", Paul Kirkley; "Guided by the Beauty of Their Weapons", Philip Sandifer

Best Graphic Story: "Shutter vol. 2: Way of the World", Joe Keatinge; "The Wicked and the Divine, vol. 2: Fandemonium", Kieron Gillen; "The Sculptor", Scott McCloud; "Ms. Marvel vol. 2: Generation Why", G. Willow Wilson; "Oglaf" (2015 strips), Bodil Bodilson

Best Dramatic Presentation (Long Form): "Mad Max: Fury Road", dir. George Miller; "Predestination", dir. The Spierig Brothers; "Ex Machina", dir. Alex Garland; "Sense8", season 1, dir. the Wachkowskis et al.; "The Omega Factor", season 1, Big Finish Productions

Best Dramatic Presentation (Short Form) "Trouble's Brewing", Other Space; "Astroburger", iZombie; "World of Tomorrow", dir. Don Hertzfeldt; "Heaven Sent" + "Hell Bent", Doctor Who S9; "Basic RV Repair and Palmistry", Community S6

Best Professional Editor (Short Form): Lee Harris (of Tor); Edmund R. Schubert; Ellen Datlow; Silvia Moreno-Garcia; John Joseph Adams

Best Professional Editor (Long Form): Nick Mamatas; Sheila Gilbert; Jonathan Strahan; Anne Groell; Anne Sowards.

Best Professional Artist: David Palumbo; Jeffrey Alan Love; Forest Rogers; Stephan Martinière; Jon Foster

Best Semiprozine: Uncanny; Andromeda Spaceways Inflight Magazine; Black Gate; On Spec; New York Review of Science Fiction

Best Fanzine: File 770; James D. Nicoll Reviews; SFF World; Rocket Stack Rank

Best Fancast: Vaginal Fantasy, Felicia Day; Sword and Laser, Veronica Belmont; The X-Files Files, Kumail Nanjiani; How Did This Get Made?, Paul Scheer, June Diane Raphael; Who's Round, Toby Hadoke

Best Fan Writer: Philip Sandifer; Alexandra Erin; Natalie Luhrs; Nick Mamatas; James D. Nicoll

Best Fan Artist: Bodil Bodilson; Zach Weinersmith; Morgana M. Wallace; Elizabeth Leggett; Guo Jian

The John W. Campbell Award: Lou Anders; Andy Weir; Usman Malik; Noelle Stevenson

akuchling: Sherlock Hemlock (Default)

Here's what I'm submitting for my nominations. I watched all of the dramatic presentations, and have previously read many of the stories.

Best Novel: "Tarzan in the Forbidden City", Edgar Rice Burroughs; "If This Goes On--", Robert A. Heinlein; "The Wonder City of Oz", John R. Neill; "The Ill-Made Knight", T.H. White; "Typewriter in the Sky", L. Ron Hubbard

Best Novella: "The Mathematics of Magic", L. Sprague de Camp, Fletcher Pratt; "Darker Than You Think", Jack Williamson

Best Novelette: "The Roads Must Roll", Robert A. Heinlein; "The Mound", H.P. Lovecraft and Zealia Bishop; "It", Theodore Sturgeon

Best Short Story: "The Tree on the Hill", H.P. Lovecraft and Duane W. Rimel; "Strange Playfellow", Isaac Asimov; "Thus I Refute Beelzy", John Collier; "Evening Primrose", John Collier; "Tlön, Uqbar, Orbis Tertius", Jorge Luis Borges

Best Graphic Story: Batman #1; Flash Comics #1; All-American Comics #16 (first appearance of the Green Lantern); Doc Savage Comics #1.

Best Dramatic Presentation (Long Form): "Fantasia", dir. Norman Ferguson et. al.

Best Dramatic Presentation (Short Form): "A Wild Hare", dir. Fred Avery; "Black Friday", dir. Arthur Lubin; "The Ape", dir. William Nigh; "The Mummy's Hand", dir. Christy Cabanne; "Dr Cyclops", dir. Ernest B. Schoedsack.

Best Editor, Short Form: John W. Campbell, Jr.; Fredrik Pohl; Raymond A. Palmer; Farnsworth Wright; Mary Gnaedinger

Best Professional Artist: Edd Cartier; Virgil Finlay; H.R. Hammond; Hubert Rogers; J.W. Scott

akuchling: Sherlock Hemlock (Default)
I'm currently reading The Groucho Letters: Letters From and To Groucho Marx. In a letter to Arthur Sheekman dated June 23 1941, Groucho writes:
The Bucks County Playhouse wired and asked me if I would play "Sherlock Holmes" (the William Gillette version) for a week this summer. I read it and thought that it didn't have enough amusing moments to be comic and I felt it wouldn't be safe for me to play it straight so I turned it down.

That's a surprising casting choice!

akuchling: Sherlock Hemlock (Default)
Generally the live-action short films are a depressing bunch; Barb and I tried to guess how many of them would feature dying children, and how many would be set in war-torn countries. There are no terminally-ill children this year -- yay! -- but instead there are 3 children in danger. Two children and one infant, really). I'm a sucker for those few short films that are funny or somehow SFnal/fantastic (it's a good form for compactly presenting a fantasy situation), but there was only one humourous film and nothing with any fantasy. The live-action short films (here's a roundup of how to watch them):
  • Ave Maria: an Israeli family gets in a car accident on the West Bank, and seeks the aid of a convent of nuns. This was funny -- the nuns have taken a vow of silence, and the loud, arguing family could have been designed to irritate them.
  • Shok (Friend) is a harrowing reminscence of 1990s Kosovo, where Albanians are being threatened by Kosovans and two young boys try to earn money from the Kosovan forces. Very glum.
  • Alles Wird Gut (Everything Will Be Okay): a tense story where it becomes clear that a divorced father is planning to kidnap his daughter and flee with her to another country. Will he succeed? A few years back there was a similar short-film nominee, the French "Avant Que De Tout Perdre (Just Before Losing Everything)", with a woman fleeing an abusive husband with her children. I'm also a sucker for Hitchcockian suspense where it's perfectly clear what is going on, and the tension is from whether a plan will succeed or not.
  • Stutterer: a man who stutters very seriously is worried about meeting the woman he's corresponded with online. There's a bit of wry humour here, but it's mostly a character piece. And it wasn't depressing!
  • Day One: a new Arabic interpreter has her first day on the job with US Army forces in Afghanistan (I assume). When I saw the initial set-up, I thought to myself "oh, here we go -- there will be IEDs and a firefight". The story actually goes in a different direction that's more interesting, though it's still unhappy and grim.
My ordering: "Alles Wird Gut", followed by "Stutterer" and "Ave Maria", then "Day One" and "Shok".
akuchling: Sherlock Hemlock (Default)
The animated shorts (here's a roundup of how to watch them):
  • Sanjay's Super Team: a Pixar film in which little Sanjay turns Hindu gods into superheroes. I really liked the luminous design in the battle scene, but overall this felt pretty minor.
  • World of Tomorrow, available on Netflix: my favorite. It's a weird science-fictional story that mixes comedy with existential dread when little Emily is visited by her future clone. This short may need to go on my Hugo ballot, if it's eligible.
  • We Can't Live Without Cosmos: two astronauts-in-training look forward to spaceflight, and then one of them goes while the other stays behind. The drawing style reminded me of Hergé's Tintin books.
  • Bear Story [trailer]: a sad story of family separation when a bear is kidnapped by a circus. Most of this film is rendered as clockwork machinery, and uses surprising camera angles and transitions, so I thought it was very inventive. My second-favorite of the nominees.
  • Prologue: a pencilled-looking rendering of vicious hand-to-hand fighting between (possibly-Greek?) warriors and naked fighters. Good visual style, but there's no plot and not really much to it.
The presentation also includes some non-nominated films, calling them "highly commended".
  • Cordell Barker's "If I Was God..." [trailer] also switches between styles, from Claymation to 2D to papier-maché. I am surprised it didn't make it into the category.
  • Two pieces from French animators, "The Short Story of a Fox and a Mouse" and "Catch It!" (featuring a bunch of meerkats trying to save their precious fruit) are fun little stories; "Catch It!" had really good character design. I expect their directors will be working on the next Shrek movie soon enough.
  • Bill Plympton's "The Loneliest Stoplight" is also fun: a stoplight tells of its one brush with fame.
akuchling: Sherlock Hemlock (Default)
Collects notes for an upcoming sprint where our goal will be to write an SMTP daemon using asyncio. SMTP: RFC 5321


akuchling: Sherlock Hemlock (Default)
(There will be minor spoilers.)

"UNIT: Dominion" is a 4-story set.  Travelling with Big Finish-only companion Raine Creevy, the Seventh Doctor encounters a future self who warns him against helping a particular species of aliens.  #7 does it anyway, and rips open an inter-dimensional corridor that begins to weaken the boundaries between universes.  Bizarre creatures begin to invade Earth across the boundaries: leeches that wipe people's minds, giant floating baby heads (!), lava-spitting spiders, and exploding cubes.  #7 and the Other Doctor have to cooperate with UNIT, especially with their science advisor Elizabeth Klein, to fend off these invasions.  But Klein doesn't trust either of the Doctors...

The four stories have cliffhangers but they're not standalone, so this is in essence a single four-hour-long story, and a very weird one.  The creatures are all really surreal designs -- the floating baby heads seem only possible for audio, because they'd look ridiculous and reminiscent of <cite>Zardoz</cite> in a visual production -- and none of them are fleshed out enough to have much personality.  The highlight of these stories is Alex Macqueen as the Other Doctor, because his performance is so entertaining, mixing buoyant confidence and irritating arrogance and making it plausible that he's a future Doctor.  (I've already listened to BF's later "Dark Eyes" series that also features Macqueen and was so delighted by it that I went back and bought this one.) 

akuchling: Sherlock Hemlock (Default)

Much processing is done on relational DBs: data -> SQL DB -> reporting

  • the structure must be relational
  • I/O heavy to ingest
  • data warehousing and reporting often doesn't care about ACID
  • storage is expensive
  • vertical scaling: to get faster, use faster storage or CPU
  • slow for large amounts of data
Hadoop components:
  • HDFS file system: files are blocks scattered over multiple servers
  • MapReduce: job tracker farms out work to nodes in a cluster
  • Flume: a custom ingester for logs
  • Sqoop: ODBC import and ingestion
  • the hadoop command has various subcommands: can store/retrieve HDFS files
  • Hive: SQL-like query language that is compiled to a multiprocessing job
  • Pig: scripting language for dataflow
  • Impala: SQL-like query language, but runs as an agent at the same level as MapReduce
  • HBase: key/value store built atop HDFS
  • Spark: in-memory Hadoop; it tries to avoid hitting the disk
  • Oozie: workflow manager/scheduler; define a DAG for workflow
Cloudera is a distro for Hadoop. 

Our cluster: 10 nodes; 100Tb raw space -> 30Tb of HDFS space.

akuchling: Sherlock Hemlock (Default)
Since I'll have nominating privileges next year, I've started keeping a list of potential nominees. Otherwise my brain will be blank at nomination time. Inclusion on these lists just means that I heard about them, not that I actually read/watched them or necessarily consider them award-worthy.

Best Related Work: the HBO documentary "Going Clear"; "The Culture Series of Iain M. Banks: A Critical Introduction", Simone Caroti; "Blake's 7: A Critical Guide to Series 1-4", Rodney Marshall; "Gender in Science Fiction Films, 1964-1979: A Critical Study", Bonnie Noonan; "Classical Traditions in Science Fiction", ed. Brett M. Rogers and Benjamin Eldon Stevens, Rolling Stone's piece on Rush; Felicia Day's memoir.

Best Fan Writer: Philip Sandifer's "Guided by the Beauty of Their Weapons: An Analysis of Theodore Beale and his Supporters", Nick Mamatas's "Rocket to the Red Planet" explaining how the Sad Puppies are very Marxist in their thinking; Mike Glyer.

Best Fanzine: File 770

Best Dramatic Presentation (Long Form): Ex Machina, Avengers 2: Age of Ultron, Mad Max: Fury Road, Jupiter Ascending, Jurassic World; Inside Out; Big Finish's The Omega Factor: Season 1.

Best Dramatic Presentation (Short Form): Community S6 E8 "Intro to Recycled Cinema", "Community S6 ep 10 "Basic RV Repair and Palmistry", iZombie ("Pilot", "Virtual Reality Bites", "Astroburger"), Paul Feig's Other Space, Taylor Swift's "Bad Blood" video; the Wachowski's Sense8, Doctor Who season 9, Game of Thrones season 5.

Best Editor (Long Form): Nick Mamatas for Haikasoru.

Best Graphic Story: Oglaf (?).

Best Fancast: The X-Files Files

Links: Partial list of 2015 items from authors who missed out

akuchling: Sherlock Hemlock (Default)
Work has resolved the question of what NoSQL database I should learn: I'm being given a project that will involve Redis as well as PostgreSQL.

Available operations:

  • get the value corresponding to a string-valued key
  • MGET key1 key2 key3: get multiple values, returning them as an array
  • set the value corresponding to a key. Variants: set the value for a key, only if the key is already present or isn't already present.
  • DEL key: delete the value for a key.
  • EXPIRE key delay: cause the key to expire and disappear after 'delay' seconds. Resolution is 1msec. (? correct ?) Can also specify delay when adding the key: SET key value EX delay.
  • TTL key: returns the # of second the key has left before it expires.
  • TYPE key: returns the type of the corresponding value
  • EXISTS key: returns 1/0 based on whether the key exists.
  • Increment/decrement counters atomically. INCR key increments the value by 1; INCRBY key n increments the value by n.
  • GETSET key value: stores a new value and returns the previous value.

Data types for values:

Linked lists:

  • Written as 1,2,3,4.
  • LLEN key returns the length.
  • LPUSH key value adds a value as the head of the list, and runs in O(1) time.  RPUSH key value  adds the value as the tail and is O(n).
  • There are corresponding LPOP and RPOP commands.
  • LRANGE key start end returns an array containing the corresponding values, and is also O(n).
  • Capped lists: LTRIM key start end keeps only the specified range and discards everything else. To keep the 10 most recent items, do LTRIM key 0 9.
  • Blocking pops: BLPOP and BRPOP block if the list is empty, or can take a timeout. Useful for implementing queues. There's even BRPOPLPUSH srckey destkey will pop the rightmost item from list 1 and push it onto list 2.


  • HSET key attr1 value1: set a single key in a hash. For multiple keys, use HMSET key attr1 value1 attr2 value2 ...
  • HGET key attrname: retrieve a key within a hash. HGETALL key returns a flat array of [attr1, value1, attr2, ...].
  • Other commands also have hash variants: HINCRBY, HEXISTS.


  • Are unordered collections of items. Commands include SADD key elem, SISMEMBER key elem to check membership, SPOP key removes a random element and returns it, SCARD key returns the number of elements ('cardinality').
  • Intersection: SINTER key1 key2 ....

Sorted sets: each element has an FP value called its score, and the set is sorted by this score in ascending order.

  • ZADD key score1 elem1 score2 elem2 .... Updates are O(log N).
  • ZRANGE key start end and ZREVRANGE key start end return slices in sorted or reversed order, returning just the elements. Add "WITHSCORES" to also return the scores.
  • To search by score, ZRANGEBYSCORE key min max. min and max are inclusive; you can say -inf or +inf. ZREMRANGEBYSCORE would remove the matching elements.
  • Ranking: ZRANK key elem returns the position of the element in the sorted order.
  • Redis 2.8 can search by the elements as well: ZRANGEBYLEX key [B [P returns elements between B and P.

Bitmaps: bit operations are defined on strings. Size limit is 512Mb = 2**32 bits.

  • SETBIT key bitnum 0/1 sets a bit, and GETBIT key bitnum returns it.
  • Bit operations over entire string: BITOP and|or|xor|not destkey srckey1 srckey2 ... - for NOT, only one srckey can be supplied.
  • BITCOUNT key counts set bits, and BITPOS key 1/0 returns the index of the first 1 or 0 bit (you can also constrain this to a range).

HyperLogLogs: probabilistic data structure for counting # of unique items seen. Has a certain amount of error on the resulting value, but is compact and doesn't grow unboundedly.

  • PFADD key elem1 elem2 elem3 ... stores the elements.
  • PFCOUNT key returns the # of unique elements seen.

akuchling: Sherlock Hemlock (Default)
My reading slow patch, due to working at home and no longer having 2 hours of commuting time per day, continued for a fourth year. I read only 59 books in 2014, the same number as in 2013 and a tie for my lowest-ever figure.

20 of those books (33%) were fiction, which is in the upper-end of the range for me; generally from 25% to 35% of my titles are fiction.

Favorites for the year:

akuchling: Sherlock Hemlock (Default)
There are many JS frameworks out there, and I want to learn one. I chose Backbone.js. (Angular is probably more popular, but also facing a Python 3-ish transition, so I let it slide.)

Backbone.js: one of a bunch of MVC-ish frameworks. Others include Angular, Spine, JavaScript MVC, Ember, Knockout.

TodoMVC is a to-do list app built in several different frameworks so you can compare them.

Backbone provides:

Models: represent domain objects.

  Wine = Backbone.Model.extend();   // Creates a model
  w = new Wine({prop1: val1, prop2: val2, ...})
Collections: a bunch of Model objects. Will apparently infer a REST-ish backend automatically.
 WineList = Backbone.Collection.extend({
   Model: Wine,
   url: "http:..."     // URL for the REST back-end
  wines = new WineList([list of objects used to create Wine instances]);
  wines.each(function (w) {...})
  HomeView = Backbone.View.extend();
  view = new HomeView();

Templates: Backbone uses Underscore for templating by default.

Routes: recording app state in the URL, and moving between different states.

  wineApp = new AppRouter();
  wineApp.routes = dict of string to method name


View.events = dict of event name to method name called when event is triggered.

akuchling: Sherlock Hemlock (Default)
 I created a git repository for Go experiments and wrote my first program, a Go port of a mortgage calculator I used when deciding whether to refinance.
akuchling: Sherlock Hemlock (Default)
Every Go file starts with "package <pkgname>".

package main

func main () {

QUESTION: are braces ever optional?

Variables are declared as: var <name> <type> = <value>, e.g. var a string = "foo".

Or, automatically infer the type: a := "foo"

Basic types: int, uint.  int{8,16,32,64}, uint{8,16,32,64}.  uintptr.  float32, float64, complex32, complex64.  string.  There are no default numeric conversions.  (QUESTION: how do you do conversions?)  (QUESTION: is there a library for a decimal type?)

Data structures: array (fixed-size; like C arrays; rarely seen in APIs); slice (views into arrays; used like Python lists; widely used); map (like a dict); struct; pointer; function; interface; channel.

Type aliases:  type Prefix string

Structures: type Prefix struct { content string, n int }

Creating a structure: S = &Prefix("s", 1) or Prefix{content: "s", n: 1}.

Types also follow the function name:

func <name>(<params>) <type> { ... }

Defining methods: 
func (self *Prefix) Fix(...) { ... }

Invoked as prefix.Fix(...).  Go convention isn't to use 'self', but to use something relevant to the type, e.g. 'pref' for 'Prefix'.  Can attach methods to any user-defined type, even ones that are just alias for 'int32'.

Visibility: methods beginning w/ capital letters (e.g. Printf) are public.  Lowercase letters signal private,  (QUESTION: is this just methods, or also struct variables?)

OO-like features: there is no idea of inheritance.  Instead there's a short-cut for doing composition:

type User3 {
  uid Uid   // regular field
  PrivilegeSet // anonymous field

All of the methods of the anonymous PrivilegeSet will be available as methods of User3; Go will automatically construct wrappers or forward them.

Interface definitions:

type PrivilegeSet interface {
  HasPrivilege (name string) bool
  AddPrivilege (name string)

Control flow

C-like statements: if, for, switch.

No 'while'; write 'for { ... }' instead.  No exceptions: use multiple return values (see below).

Functions are first-class and support closures.

No try...finally: instead, use 'defer'.  e.g.  f, err := os.Open(...) ; defer f.close() .  f.close() will be executed on leaving the function.

Panic/recover: more like exception-raising, but only to be used for serious problems (e.g. out of memory).  panic(value) triggers a panic; calls deferred functions up the call stack.  These functions can call recover() and will get the value passed to panic().

Error handling: functions can return multiple values (QUESTION: just 2-tuples, or arbitrary N-tuples?)

passwd, err := io.ReadFile(...)
if (err != nil) {
  return false, fmt.Errorf("Impossible error: %s", err)
return true, nil  // No error

Can use '_' as the don't-care value, e.g. _, err = something().

Channels: act like typed pipes:

function Flying(res chan bool) {
 res <- true     // Sends the value 'true' down the pipe.
 res <- false

pipe := make(chan bool, 5)   // type of channel is 'bool'; 5 is size of queue or something
go Flying(pipe)       // Starts a goroutine running the function Flying().
result <- pipe   // Reads a value from the channel; will block if value isn't ready.

Data structures: maps:  

  m := make(map[int]string)  // Maps integers to strings
  m[1] = "a"
  m[2] = "b"
  m[3] = "c"
  // Checking for an element
  S, ok := m[4]
  if !ok { ... record not found ... }
  // Looping over the content
  for k,v := range m { ... }


There's a 'testing' package that provides a testing.T interface with logging methods.  The "go test" subcommand will run tests.  Example:

package s_test
import ("testing" "string" ...)

func TestIndex(t *testing.T) {
  value = string.index("bogus", "foo")
  if (value != expected) {
     t.Errorf("Problem with index")

Other methods: t.Fatalf("...") ; t.Logf("...") to print a message with '-v'.  t.Skip("Doesn't work on ARM")

t.Parallel() marks a test as safe for parallel execution.

"go test" reports pass/fail.  "go test -cover" reports coverage.  "go test -coverprofile=cover.out" writes output to a file, and then "go tool cover -func=cover.out" will report on it.  "go cover -html=cover.out" generates an HTML visualization.

"go test -race <pkgname>" adds instrumentation for checking race conditions, and will report on problems.  "go run -race source.go" will execute a file.  "go build -race" and "go install -race" also work.

"go vet <pkgname>" is a static analyzer that reports problems.

Testing HTTP servers

There's a net/http/httptest package in the stdlib.  Usage is something like:

ts := httptest.NewServer(handler_func)
defer ts.Close()
res, err := http.Get(ts.URL)    // Accesses this test server

akuchling: Sherlock Hemlock (Default)
Today's game day was our largest yet, with 10 people in all. We grilled for the second time: veggie burgers, corn-on-the-cob, and one guest brought an unexpected hit, salmon to be baked on the grill wrapped in aluminum foil. As usual we didn't quite coordinate the cooking correctly -- only 5 cobs were done when the burgers were ready -- but breaking the cobs in half meant everyone got something until the second batch was ready. Games I played: while waiting for people to arrive, Barb and I dusted off La Strada for the first time in years. Then I played Carcassonne, Pandemic, and, late at night, Star Trek Catan.
akuchling: Sherlock Hemlock (Default)
In her PyCon 2014 keynote, Jessica McKellar suggested several things that developers can do to help with the educational pipeline. One idea was to just go talk to a local high-school class about software or programming. I thought it was a good idea and something I could do, but after PyCon it never got high enough on the priority list.

Two weeks ago one of our local friends talked to a high school class about her job. That was the final impetus for me to look up the local CS teacher the PG County Schools site and offered to come in.

They started out with my personal background, discussed my current job at Cox, and ended with some general remarks on programming as a career. I tried to keep the formal talk portion short to avoid boring the students. (I won't post my slides because they feature photographs of some of my past and present co-workers.)

It wasn't an optimal time for me to visit because they're already in the middle of final exams. Also, the CS class is largely (only?) composed of seniors who are on the verge of graduating, so the teacher suggested they would be largely in the don't-care-anymore phase. That may well have been true, but their questions were actually quite good. I took a recording of my talk, so I'll try to listen to it and produce a list of what they asked.

After the Q&A, I gave the students URLs for the Architecture of Open Source books and for two PyCon 2014 talks, "Turn Your Computer Into a Server" and "Analyzing Rap Music Lyrics", that I thought would interest them. Two other candidate talks that I considered mentioning were the introduction to the k-Nearest Neighbour algorithm and the game programming tutorial.

I was trying to keep my talk short in order to avoid taking up an entire session, but in the end the teacher would have been perfectly fine with that. It's a shame that wasn't made clear to me, because then I could have shown them a PyCon video, presented a small coding example, or something.

So, it was a worthwhile experiment. In late August I'll contact the school's tech coordinator and make another offer to talk to the new CS class. Perhaps the career talk will be more effective at the start of the year, to help give the students some motivation for what they're learning. And if I get definitive confirmation that I have an entire session, I can use more time to prepare a coding example to walk them through.

akuchling: Sherlock Hemlock (Default)
Barb and I played "All Creatures Great and Small" tonight, a farming game that's a stripped-down 2-player version of Agricola. She inflicted some hurting, beating me both games 44-39 and then 63-49. It's quick to play, with only eight fast-moving turns per game.
akuchling: Sherlock Hemlock (Default)
At the math meetup last Tuesday, I was chatting with someone and found we both wanted to learn Haskell. With the addition of a former co-worker of mine, the group has 3 people. Our goal was to read chapters 1 and 2 of the irritatingly-named Learn You a Haskell for Great Good for today, which wasn't a difficult goal. Assuming we keep going and do one chapter a week, we should finish the book in roughly late February.

The past week was a busy one -- two meetups, plus Halloween -- so I spent no time at all on the GnuPG tutorial. Perhaps this coming week it can find time alongside reading the Haskell book.


akuchling: Sherlock Hemlock (Default)

September 2016

2526272829 30 


RSS Atom

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated Oct. 17th, 2017 04:37 pm
Powered by Dreamwidth Studios