Suranyami

Polyglot developer, geometric tessellation fan, ambient DJ.

Whenever, as is the usual course of events during the day, I push to a remote git repo with git push origin master, I have this annoying habit of singing the words to this song that I heard in my collection ages ago:

“Original master: him dead!”

It’s from a collection of West African funk, a quite groovy song, of which they were virtually the only lyrics.

Eventually, my coworkers, er, noticed this habit of mine, responding with:

“What the hell is that? That thing you keep saying.”

To which I then immediately responded:

“it’s a song, let me play it for you, it’s called… ummm… hang on, I’ll look for it… ummm… I don’t know what it’s called. Or who it’s by. Or what album it’s from. I know it's from a compilation of West African funk…”

Cue rolling eyes, and mutterings of “of course it is…”.

And things stayed in that nebulous state of affairs, with the added surreallity of everyone else that works with git in my office singing the same thing each push, despite none of us having the slightest clue what it was.

Until yesterday, when pure luck and random-play caused it to pop up! Yay.

It’s called:

“Natural Points”, by Smahila & the SBs, on the album “The Danque!!!”

2011-10-22 18:47  by David Parry

Discuss...

I was chatting with Tony from work the other day about the Buddhist idea of Right Speech, which is one of the items in the Noble Eightfold Path. It turned out I could only remember 2 of the 4 requirements, so I had to look them up:

Right speech is the first principle of ethical conduct in the eightfold path. Ethical conduct is viewed as a guideline to moral discipline, which supports the other principles of the path. This aspect is not self-sufficient, however, essential, because mental purification can only be achieved through the cultivation of ethical conduct. The importance of speech in the context of Buddhist ethics is obvious: words can break or save lives, make enemies or friends, start war or create peace.

Buddha explained right speech as follows:

  1. to abstain from false speech, especially not to tell deliberate lies and not to speak deceitfully
  2. to abstain from slanderous speech and not to use words maliciously against others
  3. to abstain from harsh words that offend or hurt others, and
  4. to abstain from idle chatter that lacks purpose or depth.

Positively phrased, this means to tell the truth, to speak friendly, warm, and gently and to talk only when necessary.

So, in summary:

  1. speak the truth
  2. speak kindly
  3. speak gently
  4. speak only when necessary

October 14 2011, 9:40 PM  by David Parry

Discuss...

Because I always forget this, I’m putting it here:

UPDATE persons
SET
  address='Nissestien 67', city='Sandnes'
WHERE
  last_name='Tjessem' AND first_name='Jakob'

October 4 2011, 11:10 PM  by David Parr

Discuss...

  1. Make important things big and unimportant things small or remove them.
  2. Keep removing unnecessary stuff until you’ve got a simpler message.
  3. Group things together that are related.
  4. If something needs to stand out from the rest, make it different somehow.
  5. Pick a typeface that’s appropriate for the task at hand. If you don’t know how to do that, then choose an undecorated sans-serif. If you don’t know what that is, use Helvetica.
  6. Group things in categories.
  7. Put space around things that need to be apart from the rest

I think I’ll keep adding to this. They seem like good principles.

November 1 2011, 10:27 PM  by David Parry

Discuss...

January 11 2012, 3:02 PM  by David Parry

EventMachine + WebSockets

This is the notes from a talk I gave at #rorosyd on the 10th of January 2012.

The demo code is available at: [https://github.com/suranyami/socket_demo][]

So, what’s EventMachine?

  • Reactor pattern
  • Extremely high performance
  • Doesn’t need threads, concurrency
  • Addresses the C10K problem
  • Callbacks
  • Fast, low memory overhead

EventMachine supports lots of protocols!

There is a great list of currently implemented protocols at https://github.com/eventmachine/eventmachine/wiki/Protocol-Implementations which includes:

  • HeaderAndContent
  • SMTPServer
  • Stomp
  • Socks4
  • ObjectProtocol
  • SASLauth
  • LineAndText
  • LineText2
  • HTTPClient
  • HTTPClient2
  • AMQP
  • MySQL
  • SMTP
  • Postgres
  • MemCache
  • XMPP
  • DNS
  • PowerDNS
  • ICMP
  • XML Push Parser
  • Redis
  • MongoDB
  • CouchDB
  • Beanstalk
  • SNMP
  • HTTPRequest
  • HTTPServer
  • PubSubHubbub
  • Proxy
  • WebSocket
  • SMPP
  • RPC
  • IRC
  • Spec
  • Cassandra
  • Thrift
  • Solr
  • Syslog
  • Amazon S3
  • OSCAR (AIM, ICQ)
  • RServe
  • SSH

How to learn about EventMachine?

PeepCode

EventMachine Introduction

Example of a Trivial Telnet Server

require 'eventmachine'
class Echo < EM::Connection
  def receive_data(data)
    send_data(data)
  end
end

EM.run do
  EM.start_server(“0.0.0.0”, 10000, Echo)
end

So, what’s a WebSocket?

  • Used for “push”, real-time bidirectional updates
  • HTML 5, proposed RFC, too.
  • In all modern browsers Chrome Safari, Safari Mobile Firefoxx but NOT Android browser (FFS! Why?) ** IE 10, but not IE 6-9 (who cares!)
  • iOS native library + elsewhere
  • Combining EventMachine + WebSocket = em-websocket

Where would I use it?

  • Chat
  • Multiplayer Games
  • Real-time dataviz
  • Real-time news feeds
  • Real-time anything

Trivial WebSocket server

require 'eventmachine'
require 'em-websocket'

conf = {:host => “0.0.0.0”, :port => 8080}

EM.run {
  EventMachine::WebSocket.start(conf) do |ws|
    ws.onopen {ws.send "Hello Client"}
    ws.onclose { puts "Connection closed" }
    ws.onmessage {|msg| ws.send "Echo: #{msg}"}
end }

A Less Trivial example

So, I wanted something to demo that wasn’t trying to do to much but demonstrated the real-time nature of WebSockets, so I built this little socket_demo site:

  • Sinatra serves HTML, JS (CoffeeScript), CSS
  • Running an EM-WebSocket server
  • Each guest decides whether a block is green or red (default’s white)
  • Joining/leaving adds/removes blocks
  • New guest gets snapshot of world

Useless, but non-trivial!

CoffeeScript

Assign an id to socket/guest

EM-Websocket Server:

class Demo constructor: –>
    if WebSocket?
      window.socket = new WebSocket("ws://192.168.1.3:7070")
    else
      window.socket = new MozWebSocket("ws://192.168.1.3:7070")

Register ourselves

CoffeeScript:

window.socket.onopen = –>
  window.socket.send JSON.stringify({kind: “register”})

EM-Websocket Server:

socket.onmessage do |msg|
  puts "Server Received #{msg}"
  id = @sockets[socket][“id”]
  incoming = ActiveSupport::JSON.decode(msg)
  case incoming[“kind”]
    when "register"
      socket.send(register_message(id).to_json)
      broadcast(id)
    else
      ## Send “add” event to everyone

EM-Websocket Server:

def send_to_all(message) @sockets.each do |destination|`
    destination.send(message.to_json)
end

CoffeeScript:

```coffeescript
window.socket.onmessage = (mess) –>
  data = jQuery.parseJSON(mess.data)
  switch data[“kind”]
  when "add"
      window.add_player data["id"], data["color"]

Send click events

$(“#red”).click (e) => window.socket.send JSON.stringify {kind: “update”, color: “red”}

$(“#green”).click (e) => window.socket.send JSON.stringify {kind: “update”, color: “green”}

Server gets a message

socket.onmessage do |msg|
  id = @sockets[socket][“id”] incoming = ActiveSupport::JSON.decode(msg)
  case incoming[“kind”]
    when “register”
      socket.send(register_message(id).to_json)
      broadcast(id)
    else
      if incoming["color"]
        color = incoming["color"]
        message = {"kind" => "update", "id" => id, "color" => color}
        @sockets[socket]["color"] = color
        send_to_all(message)
    end
  end
end

Live Demo

Then I gave a live demo where I used my laptop as an unsecured base station, and people connected to it with their iPhones and started clicking on the red/green buttons:

wifi: suranyami (no password) url: test.local:4567

How to do testing with EventMachine?

em-spec https://github.com/joshbuddy/em-spec

This demo code viewable here: [https://github.com/suranyami/socket_demo][]

September 11th, 2013 2:19pm

Discuss...

I was into disassembling old TVs for electronic parts in high school. One day I bought a huge old 1950s unit (broken) at a flea market for $1. It had a 1 Farad capacitor in it about the size of a tin of peaches. Our school library had recently been re-carpeted with nylon carpet that generated epic levels of static charge on cold, dry days. So I used to scuff my feet around the library holding onto one of the terminals of this giant capacitor, then approach a victim and give them my “Star Wars Emporer” electric shock treatment.

A few years ago a colleague did some quick arithmetic and suggested that I may well have been approaching an amount of current that could have caused heart failure. Woops.

Discuss...

So, today is day 2 of me making music with my groovy little setup consisting of:

  • Korg SQ-1
  • Moog WerkStatt Ø1
  • Logic Pro X
  • PreSonus AudioBox iTwo

My soundcloud account here: https://soundcloud.com/suranyami

Using mono mini-jack cables, connect the following:

  • Korg CV-out to Moog VCO-Exp-In
  • Korg Gate-out to Moog Gate-out (Go figure!)

Even though the gate-out to gate-out thing is the only known (and not officially recommended) way to trigger the Werkstatt, it only really works when you also hold a key down on the Moog.

The first problem I encountered was synchronization. I recorded a bassline, but then tried to add a drum track to it. Since the analog synth had nothing to do with Logic, everything was out of sync.

Because I’m using the Korg SQ-1, though, the solution is remarkably simple:

  • plug the Korg into the laptop via USB
  • set Logic Pro to Transmit MIDI Clock, MMC & MIDI Time Code to all MIDI devices

Now the sequencer is in-sync with Logic. Yay!

Next challenge: the SQ-1 has an in-built MIDI-to-CV/Gate capability. Use that for fun & profit!

Extra note: Gadget love

I have not felt so much fun, expansive possibilities with a piece of hardware in decades. I distinctly remember the times I was blown away by what we can achieve with electronics:

  • When Stephen Smith and I convinced the University of Queensland Psychology Department to let us use their Fairlight CMI in 1982 to make some pretty cheesey pop songs, whenever they weren’t using it.

  • When I played with an Apple Lisa for the first time. I went to print something and it said “Is the cable connected?” This was completely new & revolutionary.

  • Using MacPaint/MacDraw/Adobe Illustrator/Adobe Photoshop/Pagemaker for the first time.

When Stephen Smith & I used to play with electronic instruments in the 80’s, it was a labour of love. We made drums out of bits of old rubber stretched over wooden frames, with crappy dismantled earphones as input devices, processed by Schmidt triggers that we got as free samples by pretending we were an electronics OEM called “DaveTronics Pty Ltd” despite being 14 years old. The great thing about this was working out how much can go wrong just making some noise.

I loved that time. But I love being able to twiddle with sound in the ways I always imagined I could.

I remember having a very heated argument with Stephen because my favourite setting on the Roland SH-101 was “Attack: 0, Decay: 0.001”. It was a great little CLICK sound. What could that click sound have become with a cheap hi-res audio interface, crazy-ass effects, and plugging it into a wicked, patchable analog synth? We may now know.

PS: Stephen Smith, please talk to me! I know it’s hard, but I think I’m your oldest friend and I miss you. PPS: Stephen & I are on speaking terms, nothing bad has happened, it’s just he’s a bit hard to get hold of

January 2nd, 2016 10:28pm

Discuss...

We were inside a Matrix-like simulation of reality.

Our goal was to explore a new planet and colonise it. The new world was arcane and beautiful in its oddities, lakes of flying fish, tall spires where huge elephantine pterodactyles nested.

Soon after arrival, we laid plans, and began construction of towns, cities, farms, houses.

As we began working, there appeared a group of aliens, different from the native fauna. Their actions seemed to be undoing some (but not all) of the actions we were taking.

Then a crop of obstructions and annoyances started swirling around us. Landscapes transformed, people would break out in hives and spots, swarms of bees would obstruct our paths.

Some sought to lash out at the newcomers and attack them. This caused their actions to become increasingly strange, and the obstructions become more and more horrific. Living explosions, blood & gore, violence. The more we resisted the newcomers, the more awful and incomprehensible the entire situation became.

But, noticed a few, the situation was not universal. There were some interactions with the newcomers where their actions ran harmoniously with ours, and the obstructions were curiously absent.

Through careful analysis and experimentation, some principles and practices were discovered that showed us how to live harmoniously with the newcomers. Some even discovered that not only could they survive, it was possible to flourish and even soar.

With peace returning, we were able to spend time closely studying the new creatures and their curiously symbiotic relationship to ourselves.

Time and attention revealed that the others where our own actions, manifested as a physical entity. Their actions were the new version of ourselves following our actions, and the obstructions were the consequences of our actions.

July 29th, 2014 8:44am

Discuss...

Never start a project involving legacy code that has already been estimated & scoped by someone other than myself.

October 21st, 2015 10:56am

Discuss...

Our team recently began using PhraseApp for translations/localizations. It's a great service. But, we hit a problem:

SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed

We tried the usual things:

brew uninstall openssl
brew install openssl
brew link openssl --force
rvm osx-ssl-certs update all

and imploding rvm and the like, all to no avail. Eventually, the solution was found using the following:

ssl-tool: Misc. tools to help with debugging WTF is going on with SSL connections and Ruby

This showed that there was an expired CA cert from GlobalSign on the dev machine.

It was then fixed with this:

OpenSSL and dealing with expired Root CA certs

I hope this helps anyone else who encounters this.

August 25th, 2015 10:27am #ruby #ssl #certificates #expired #homebrew

Discuss...

Enter your email to subscribe to updates.