QuickCheck - property based testing in Haskell and JavaScript
In my last article, I presented a functional programming pattern. The goal was to reach out to the developers who weren’t familiar with advanced type systems like the one found in Haskell and make them a bit curious. This time I’d like to take a step further and present a testing approach coming from the same world, that can be used with mainstream languages with a great success.
Many ways to test the code
The importance of testing is almost a cliché nowadays. Out of this relevance, a large number of testing frameworks and paradigms have been created. On the paradigm level we have notions like TDD and BDD. On the level of implementations we have hundreds of projects for each language like RSpec in Ruby and Jasmine or Mocha in JavaScript.
The ideas behind the libraries don’t differ that much. All of them are based on the idea of providing code examples with assertions on how the code should behave in these particular cases.
A bit more revolutionary in its approach was the Cucumber project. In its essence, it allows business people to express the system logic by stating it in specially formed, plain English. An example taken from the Cucumber’s website reads:
Feature: Refund item …functional-programming haskell javascript testing
Hue’s on First: How we used responsive bulbs to join software and hardware for a busy medical practice

In 2014 we began working with a busy bariatric surgery office in Long Island to create a system that would allow the practice to better manage doctor paging and patient wait time. By placing a responsive, color-coded light bulb and tablet outside each examination room, the staff could see which rooms were empty, which were occupied by a patient waiting on a specific doctor, and in which a doctor-patient consultation was in process. Outside each room is a tablet with information including the patient number, the attending doctor’s name, and the wait time.

In addition to providing a comprehensive, granular paging service for doctors, Fast Track also provides feedback to the practice. This feedback includes average patient wait times per doctor, per time of day, and per procedure. This allows the practice to make necessary changes and increase patient satisfaction and peace of mind.

I asked Danny Divita, one of the main developers on this project, to tell us more about the Hue/ FastTrack interface.
LF: Describe the project for which we used Hue bulbs. What were all the pieces that needed fitting together?
DD: The Hue bulbs are being used for a bariatric clinic to alert the staff …
case-study api design user-interface hardware architecture
MediaWiki extension EmailDiff: notification emails improved
One of the nice things about MediaWiki is the ability to use
extensions to extend the core functionality in many ways. I’ve just released a
new version of an extension I wrote called EmailDiff that helps provide a much needed
function. When one is using a MediaWiki site, and a page is on your
watchlist—or your username is inside
the ‘UsersNotifiedOnAllChanges’ array—you will receive an email whenever a page
is changed. However, this email simply gives you the editor’s summary and states
“the page has been changed, here’s some links if you want to see exactly what”.
With the EmailDiff extension enabled, a full diff of what exactly has changed is sent
in the email itself. This is extremely valuable because you can quickly see exactly what has
changed, without leaving your email client to open a browser (and potentially have to login),
and without breaking your flow.
Normally, a MediaWiki notification email for a page change will look something like this:
Subject: MediaWiki page Project:Sandbox requirements has been changed by Zimmerman
Dear Turnstep,
The MediaWiki page Project:Sandbox requirements has been changed on
16 November 2015 by …mediawiki
Strict typing fun example — Free Monads in Haskell
From time to time I’ve got a chance to discuss different programming paradigms with colleagues. Very often I like steering the discussion into the programming languages realm as it’s something that interests me a lot.
Looking at the most popular languages list on GitHub, published last August, we can see that in the most popular five, we only have one that is “statically typed”. https://github.com/blog/2047-language-trends-on-github
The most popular languages on GitHub as of August 2015:
- JavaScript
- Java
- Ruby
- PHP
- Python
The dynamic typing approach gives great flexibility. It very often empowers teams to be more productive. There are use cases for static type systems I feel that many people are not aware of though. I view this post as an experiment. I’d like to present you with a pattern that’s being used in Haskell and Scala worlds (among others). The pattern is especially helpful in these contexts as both Haskell and Scala have extremely advanced type systems (comparing to e. g. Java or C++ and not to mention Ruby or Python).
My goal is not to explain in detail all the subtleties of the code I’m going to present. The learning curve for both languages can be pretty dramatic. The …
functional-programming haskell programming
Story telling with Cesium
Let me tell you about my own town
I was born in Yekaterinburg. It’s a middle-sized town in Russia.
Most likely you don’t know where it is. So let me show you:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Hello World!</title>
<script src="/cesium/Build/Cesium/Cesium.js"></script>
<link rel="stylesheet" href="layout.css"></link>
</head>
<body>
<div id="cesiumContainer"></div>
<script>
var viewer = new Cesium.Viewer('cesiumContainer');
(function(){
var ekb = viewer.entities.add({
name : 'Yekaterinburg',
// Lon, Lat coordinates
position : Cesium.Cartesian3.fromDegrees(60.6054, 56.8389),
// Styled geometry
point : {
pixelSize : 5,
color : Cesium.Color.RED
},
// Labeling
label : {
text : 'Yekaterinburg',
font : '16pt monospace',
style: Cesium.LabelStyle.FILL_AND_OUTLINE,
outlineWidth : 2,
verticalOrigin : Cesium.VerticalOrigin.BOTTOM, …angular cesium javascript kamelopard maps kml
Loading JSON Files Into PostgreSQL 9.5
In the previous posts I have described a simple database table for storing JSON values, and a way to unpack nested JSON attributes into simple database views. This time I will show how to write a very simple query (thanks to PostgreSQL 9.5) to load the JSON files
Here’s a simple Python script to load the database.
This script is made for PostgreSQL 9.4 (in fact it should work for 9.5 too, but is not using a nice new 9.5 feature described below).
#!/usr/bin/env python
import os
import sys
import logging
try:
import psycopg2 as pg
import psycopg2.extras
except:
print "Install psycopg2"
exit(123)
try:
import progressbar
except:
print "Install progressbar2"
exit(123)
import json
import logging
logger = logging.getLogger()
PG_CONN_STRING = "dbname='blogpost' port='5433'"
data_dir = "data"
dbconn = pg.connect(PG_CONN_STRING)
logger.info("Loading data from '{}'".format(data_dir))
cursor = dbconn.cursor()
counter = 0
empty_files = []
class ProgressInfo:
def __init__(self, dir):
files_no = 0
for root, dirs, files in os.walk(dir):
for file in files: …postgres
Converting JSON to PostgreSQL values, simply
In the previous post I showed a simple PostgreSQL table for storing JSON data. Let’s talk about making the JSON data easier to use.
One of the requirements was to store the JSON from the files unchanged. However using the JSON operators for deep attributes is a little bit unpleasant. In the example JSON there is attribute country inside metadata. To access this field, we need to write:
SELECT data->'metadata'->>'country' FROM stats_data;The native SQL version would rather look like:
SELECT country FROM stats;So let’s do something to be able to write the queries like this. We need to repack the data to have the nice SQL types, and hide all the nested JSON operators.
I’ve made a simple view for this:
CREATE VIEW stats AS
SELECT
id AS id,
created_at AS created_at,
to_timestamp((data->>'start_ts')::double precision) AS start_ts,
to_timestamp((data->>'end_ts')::double precision) AS end_ts,
tstzrange(
to_timestamp((data->>'start_ts')::double precision),
to_timestamp((data->>'end_ts' …postgres
Storing Statistics JSON Data in PostgreSQL
We have plenty of Liquid Galaxy systems, where we write statistical information in json files. This is quite a nice solution. However we end with a bunch of files on a bunch of machines.
Inside we have a structure like:
{
"end_ts": 1438630833,
"resets": [],
"metadata": {
"country": "USA",
"installation": "FIRST"
},
"sessions": [
{
"application": "first",
"end_ts": 1438629089,
"start_ts": 1438629058
},
{
"application": "second",
"end_ts": 1438629143,
"start_ts": 1438629123
},
{
"application": "third",
"end_ts": 1438629476,
"start_ts": 1438629236
}
],
"start_ts": 1438629033,
"status": "on"
}And the files are named like “{start_ts}.json”. The number of files is different on each system. For January we had from 11k to 17k files.
The fields in the json mean:
- start_ts/end_ts - timestamps for start/end …
postgres
