JavaScript Performance: Node CLI flags
These are some notes on performance engineering related to generating insights into Node.js (v8) performance. All material here is specific to the v8 engine found in Node.js, Chrome, and Opera. Generally useful things to learn to tune JavaScript (for the v8 engine) is natives syntax. You can run JS with natives syntax directives sprinkled throughout using …
Socket Statistics on Linux with ss
An excellent tool when you need to troubleshoot distributed systems is ss, which provides visibility into TCP states of your live connections. Even if you know netstat this is a command you should get acquainted with because of its more powerful interface which requires fewer pipes to find the connection information you need and it is probably already …
Profunctor exploration in less than 100 lines of Haskell
A snippet showing the design space around profunctors using Haskell as the teaching language Includes sighting of Strong, Choice, Cartesian and more profunctors.
Decoding lens operators
Notation conventions The following table provides a quick overview of conventions used in symbolic operators in the lens library. Symbol Concept Denotes ^ getter gets value from structure ~ setter sets values in structure % over apply transformation over selected substructure = state threads state through << before change returns value before …
Ruby 2.4 changes overview
Unified Fixnum and Bignum into Integer It’s backward compatible too. $ irb irb(main):001:0> RUBY_VERSION => "2.3.1" irb(main):002:0> (2**100).class => Bignum irb(main):003:0> 2.class => Fixnum irb(main):004:0> Fixnum => Fixnum irb(main):005:0> Bignum => Bignum irb(main):006:0> Bogonum NameError: uninitialized …
Nix in your home directory
Prerequisites wget is installed tar is installed Purpose If you really don't want to install Nix under /nix (or you can't) then you can install Nix in your home directory like in the homedir_install.sh script included in this Gist. Now whenever you want to run a command under Nix's control, you should prefix with nixrun. Good luck. …
Scala WTFs - moments of confusion in the Scala REPL
Small sample of Scala WTFs circa 2014 from the REPL (many taken from Paul Phillips talks on the Scala Collections library): scala> List("a", "b", "c").toSet // the only reasonable line of code in here res1: scala.collection.immutable.Set[String] = Set(a, b, c) scala> List("a", "b", "c").toSet() // seen …
OSX Lion (10.7.4) work laptop setup
Homebrew Install after the command-line tools for Xcode. tmux erlang haskell-platform zsh git figlet scala sbt rbenv ruby-build s3cmd pit brew install tmux erlang haskell-platform zsh \ git figlet scala sbt rbenv ruby-build s3cmd pit RubyGems veewee App Store Opera Skitch XCode (Command-line tools) Miro (if only there was a way to uninstall iTunes) Manual …
Erlang OTP Glossary of Terms
I am hoping this will serve as a reference for coworkers and others new to Erlang and OTP to be able to figure out the terminology easier than I had to. I learned the hard way, so you don't have to!:) Erlang/OTP - The set of libraries and conventions that are used as part of the core Erlang distribution by Ericsson to build fault-tolerant, distributed …
Erlang Meck API notes
Here is a snippet showing how to use the Meck API which is a mocking library in Erlang. We will show how to create a fully mocked version of an existing module, unloading mocks, removing functions from a mocked module, and getting a list of all function calls to a module.
Custom Security Handler Nitrogen
An example of a custom security handler implementation for Nitrogen 2.x. customer_security_handler.erl %%% HEADER %%% @author Susan Potter <me@susanpotter.net> %%% @date 2011-02-16T17:08 %%% @license BSD %%% @doc Example of a security_handler behavior implementation module. %%% It assumes a callback module is passed in that exports: %%% login_path/0 …
Predicate Algebra in Python
Updated for Python3 recently: class Predicate: """ Define predicate algebra. >>> isEven=Predicate(lambda x: x % 2 == 0) >>> isOdd=Predicate(lambda x: x % 2 == 1) >>> isEven(6) True >>> isOdd(6) False >>> isEmpty=Predicate(lambda s: s == "") >>> isNotEmpty=~isEmpty >>> …
My .gitconfig & .tigrc files
This started as my first ~/.gitconfig file and is probably out of date when you read it. [user] name = Susan Potter # make sure you change this email = me@susanpotter.net # make sure you change this [color] diff = auto status = auto branch = auto [diff] rename = copy color = auto [apply] whitespace = strip [pager] color = true [status] color = auto [branch] …
Ruby Idioms, Part 7: Last argument options Hash
This idiom I have seen a little more in Rails than I have seen in Ruby, but I am putting it in this Ruby Idioms series anyway. First off, most of you will know by know that you can "transparently" provide a method in Ruby a Hash. What do I mean by "transparently"? Well have a look at the code example below: user = User.find(:first, :include …
Ruby Idioms, Part 6: Postfix conditional flow
Tonight I remembered couple more idioms in Ruby and felt compelled to share. In Javafied Ruby code (below) we often see something like the following: if something for role in user.roles return true if @@roles.include? role end end Now when I first started writing Ruby code almost 3 years ago, I thought looping through a collection like above was the nicest …
Ruby Idioms, Part 5: Ranges
Some of you may say this isn't strictly an idiom, but it is dependent on Ruby's core API and classes, so I have included it. Ranges are a very nice low-level abstraction and can save Ruby developers a lot of time for certain coding needs. In a previous idiom example on this blog I had a list of positive odd numbers under 7. Well typing this out by …
Ruby Idioms, Part 4: The splat
To splat or not to splat, that is the question. In Java to unpack an array's values into separate variables you would need to do something like the following: burgers = [:hamburger, :bocaburger, :gardenburger, :turkeyburger] t = burgers[0] u = burgers[1] v = burgers[2] w = burgers[3] In the Ruby mindset this would look more like the following: burgers = …
Ruby Idioms, Part 3: Nested attribute retrieval
Now, probably the biggest difference after the syntax, and the non-static nature of Ruby for Java heads to get used to is that Ruby is an "expressionist" language. Meaning almost all statements in Ruby evaluates to a value, i.e. everything that reasonably can be is an expression in Ruby is. This is definitely not the way Java thinks or works. So this …
Ruby Idioms, Part 2: Unless
Now the "idiom" we will use is not specific to Ruby, since I am pretty sure Perl has one of the constructs we will use to solve the stated problem, but it is still idiomatic, since the majority of popular OO languages (static, dynamic or otherwise) do not have it (as far as I know). Also some consider this to be a sub-optimal idiom, because there is …
Ruby Idioms, Part 1: Array#include?
With more people moving to Ruby everyday from languages like Java, I wanted to create blog entries on the most common Ruby idioms (especially ones frequently found in Rails core or Rails application code) and briefly explain how to convert your Java mindset to Ruby (over time). This is the first installment. First let us inspect what we might do in Java …
Rubyisms: reopening classes
Ever wished you could write code in a very expressive way like the following examples? expiration_date = 3.years.from_now birth_date = 32.years.ago Now you can, in Ruby at least. Two years ago I was a very happy Python developer that thought no other language could compete with Python for developer productivity. My Python indoctrination occurred after 7 …
Rubyisms: naming conventions
Unveil the world of Ruby naming conventions with a captivating symphony of clarity and productivity. Discover implicit and explicit rules as we explore class and module names, variable names, question-marked methods, slightly dangerous methods, instance variables, global variables, and constants. Each convention is infused with examples from the Ruby …
Rubyisms: forwardables
Recently some Java friends of mine have decided to taste the juicier fruits in Ruby-land with my assistance. So below are some excerpts from an email conversation I had with one about Ruby's standard library forwardable features. Nested object path decoupling Suppose we have the following model classes defined for a simple CRM system: Customer, Address, …