Writing a Test Framework from Scratch
On March 21 and 22, I had the opportunity to attend the 10th and final MountainWest RubyConf at the Rose Wagner Performing Arts Center in Salt Lake City.
One talk that I really enjoyed was Writing a Test Framework from Scratch by Ryan Davis, author of MiniTest. His goal was to teach the audience how MiniTest was created, by explaining the what, why and how of decisions made throughout the process. I learned a lot from the talk and took plenty of notes, so I’d like to share some of that.
The first thing a test framework needs is an assert function, which will simply check if some value or comparison is true. If it is, great, the test passed! If not, the test failed and an exception should be raised. Here is our first assert definition:
def assert test
raise "Failed test" unless test
endThis function is the bare minimum you need to test an application, however, it won’t be easy or enjoyable to use. The first step to improve this is to make error messages more clear. This is what the current assert function will return for an error:
path/to/microtest.rb:2:in `assert': Failed test (RuntimeError)
from test.rb:5:in `<main>'To make this more readable, …
conference ruby
New Features in PostgreSQL 9.5
The new PostgreSQL 9.5 release has a bunch of great features. I describe below the ones I find most interesting.
Upsert
UPSERT is simply a combination of INSERT and UPDATE. This works like this: if a row exists, then update it, if it doesn’t exist, create it.
Before Postgres 9.5 when I wanted to insert or update a row, I had to write this:
INSERT INTO test(username, login)
SELECT 'hey', 'ho ho ho'
WHERE NOT EXISTS (SELECT 42 FROM test WHERE username='hey');
UPDATE test SET login='ho ho ho' WHERE username='hey' AND login <> 'ho ho ho';Which was a little bit problematic. You need to make two queries, and both can have quite complicated WHERE clauses.
In PostgreSQL 9.5 there is much simpler version:
INSERT INTO test(username, login) VALUES ('hey', 'ho ho ho')
ON CONFLICT (username)
DO UPDATE SET login='ho ho ho';The only requirement is that there should be a UNIQUE constraint on a column which should fail while inserting a row.
The version above makes the UPDATE when the INSERT fails. There is also another form of the UPSERT query, which I used in this blog post. You can just ignore the INSERT failure: …
postgres
A Beginner’s Guide to PCI DSS Compliance and TLS Versions
I recently did some research for one of End Point’s ecommerce clients on their PCI compliance and wanted to share some basic information for those of you who are new to this topic.
TLS
TLS (Transport Layer Security) is a standard for secure communications between applications. TLS is the current version of what used to be called SSL, the secure sockets layer. In the case of a financial transaction, this is the communication between the website selling a product and the end user. TLS works by encrypting data between two endpoints to ensure any sensitive data (such as financial details and private customer information) is exchanged securely. As security measures increase, new versions of TLS are released. To date, TLS 1.2 is the most up-to-date, with TLS 1.1 being considered safe, and TLS 1.0 being phased out. For details about OS versions supporting the latest TLS standards, please see Jon Jensen’s write-up here.
Compliance with PCI DSS
As all online retailers know, becoming and staying compliant with PCI DSS (Payment Card Industry Data Security Standard) is a big job. PCI is THE ecommerce security standard and in order to accept payment with Visa, MasterCard, American Express, and …
ecommerce hosting payments security
Learning from data basics: the Naive Bayes model
Have you ever wondered what is the machinery behind some of the algorithms for doing seemingly very intelligent tasks? How is it possible that the computer program can recognize faces in photos, turn an image into a text or even classify some emails as legitimate or as spam?
Today, I’d like to present one of the simplest models for performing classification tasks. The model enables extremely fast execution, making it very practical in many use cases. The example I’ll choose will enable us to extend the discussion about the most optimal approach to another blog post.
The problem
Imagine that you’re working on an e-commerce store for your client. One of the requirements is to present the currently logged in user with a “promotion box” somewhere on the page. The goal is to maximize our chances of having the user put the product from the box into the basket. There’s one promotional box and a couple of different categories of products to choose the actual product from.
Thinking about the solution—using probability theory
One of the obvious directions we may want to turn towards is to use probability theory. If we could collect the data about the user’s previous choices and his or her …
machine-learning optimization probability ruby
Creating a video player with time markers — step by step
Introduction
Today we will show you how to create a video player with time markers using JavaScript and HTML5 only. Libraries that we will use are proven to be stable enough for production projects. What we want to achieve? The final result is visible below:
To simplify (or to make it harder for some of you :)) this tutorial we won’t use any package management tools. The demo is available on Github here: https://github.com/peter-hank/video-with-markers
Requirements
We will need some libraries (all of these are free to use in commercial projects):
- Video.js — https://github.com/videojs/video.js,
- Videojs-markers plugin — https://github.com/spchuang/videojs-markers.
- jQuery — http://code.jquery.com/jquery-2.0.3.min.js
- Sample video file — http://download.blender.org/peach/bigbuckbunny_movies/BigBuckBunny_320x180.mp4
Step 1 — creating a project skeleton
Let’s create a new folder for our project and call it video-with-markers. Inside let’s create a new file called “index.html”, three folders: “css”, “js” and “var”.
We also need to copy libraries files and put it into a proper directory:
html javascript video
Spree Admin pages unreachable (500 errors)
I was notified a few minutes ago by one of our Spree clients that their admin interface was unreachable due to errors.
Digging into the logs, I discovered SocketErrors (DNS lookup failures) were behind the 500 errors. Digging deeper, I discovered the SocketErrors were coming from a Spree file attempting to access “alerts.spreecommerce.com”. I confirmed in my browser that alerts.spreecommerce.com fails to resolve.
This Git commit discusses the removal of the class, but if you haven’t stayed current and you’ve left the “Check for alerts” box checked, you may need to do some manual editing of your stored preferences to get the UI to load again.
Spree::Preference.where(key: "spree/app_configuration/check_for_spree_alerts").first.update_attributes(value: false)It does appear that your app will need to restart to pull in this change.
I’m not sure what the chances are your particular config key might vary, so please use the above with caution.
spree ecommerce
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

