-
Intercepting class method invocations using metaclass programming in Python
In Ruby, objects have a handy method called method_missing which allows one to handle method calls for methods that have not been defined. Most examples out there explain how to implement this in Python using __getattr__, however, none of them (honestly, none) explain how to intercept class method (@classmethod) invocations using __metaclass__. And this is…
-
How to pass variables to a Docker container when building a Node app
Environment variables are declared with the ENV statement and are notated in the Dockerfile either with $VARIABLE_NAME or ${VARIABLE_NAME}. Passing variables at build-time The ENV instruction sets the environment variable to the value. The environment variables set using ENV will persist when a container is run from the resulting image. For example: The Dockerfile allows you to specify arguments…
-
Node.js: How to mock the imports of an ES6 module
The package mock-require is useful if you want to mock require statements in Node.js. It has a simple API that allows you to mock anything, from a single exported function to a standard library. Here’s an example: app/config.js app/services/content.js test/services/content_spec.js
-
Geo Proximity Search: The Haversine Equation
I’m working on a project that requires Geo proximity search. Basically, what I’m doing is plotting a radius around a point on a map, which is defined by the distance between two points on the map given their latitudes and longitudes. To achieve this I’m using the Haversine formula (spherical trigonometry). This equation is important…
-
Installing multiple versions of Ruby using RVM
Ruby Version Manager (RVM) is a tool that allows you to install multiple versions of Ruby and have multiple versions of the same interpreter. Very handy for those who have to maintain different applications using different versions of Ruby. To start, download RVM and install the latest stable version of Ruby: $ echo insecure >>…
-
Software Architecture Document Guidelines
Regardless of the development process that you use, a description of the software architecture can be essential for any project, big or small. If software architecture is about the structure of a system and is the vehicle for satisfying the requirements, then the software architecture document is a written description of this. The Software Architecture…
-
Implementing Dynamic Finders and Parsing Method Expressions
Most ORMs support the concept of dynamic finders. A dynamic finder looks like a normal method invocation, but the method itself doesn’t exist, instead, it’s generated dynamically and processed via another method at runtime. A good example of this is Ruby. When you invoke a method that doesn’t exist, it raises a NoMethodError exception, unless…
-
Database Replication Adapter for Zend Framework Applications
Last updated: 21 Feb, 2010 Database replication is an option that allows the content of one database to be replicated to another database or databases, providing a mechanism to scale out the database. Scaling out the database allows more activities to be processed and more users to access the database by running multiple copies of…
-
Zend Framework DAL: DAOs and DataMappers
A Data Access Layer (DAL) is the layer of your application that provides simplified access to data stored in persistent storage of some kind. For example, the DAL might return a reference to an object complete with its attributes instead of a row of fields from a database table. A Data Access Objects (DAO) is…
-
Java, C, Python and nested loops
Java has no goto statement, to break or continue multiple-nested loop or switch constructs, Java programmers place labels on loop and switch constructs, and then break out of or continue to the block named by the label. The following example shows how to use java break statement to terminate the labeled loop: public class BreakLabel…
-
Google Page Speed: Web Performance Best Practices
When you profile a web page with Page Speed, it evaluates the page’s conformance to a number of different rules. These rules are general front-end best practices you can apply at any stage of web development. Google provides documentation of each of the rules, so whether or not you run the Page Speed tool, you can refer…
-
The Little Manual of API Design
This manual gathers together the key insights into API design that were discovered through many years of software development on the Qt application development framework at Trolltech (now part of Nokia). When designing and implementing a library, you should also keep other factors in mind, such as efficiency and ease of implementation, in addition to…
-
Domain-Driven Design: Sample Application
Last updated: 15 Feb, 2010 Part 1: Domain-Driven Design and MVC Architectures Part 2: Domain-Driven Design: Data Access Strategies Part 3: Domain-Driven Design: The Repository Some of the Domain-driven design concepts explained above are applied in this sample application. Directory Structure app/ config/ controllers/ UserController.php domain/ entities/ User.php UserProfile.php repositories/ UserRepository.php views/ lib/ public/ The…
-
Domain-Driven Design: The Repository
Part 2: Domain-Driven Design: Data Access Strategies The Ubiquitous Language The ubiquitous language is the foundation of Domain-driven design. The concept is simple, developers and domain experts share a common language that both understand. This language is set in business terminology, not technical terminology. This ubiquitous language allows the technical team become part of the…
-
Domain-Driven Design: Data Access Strategies
Part 1: Domain-Driven Design and MVC Architectures The Domain Model Here are some of the features a Domain-driven design framework should support: A domain model that is independent and decoupled from the application. A reusable library that can be used in many different domain-specific applications. Dependency Injection in order to inject Repositories and Services into…
-
Domain-Driven Design and MVC Architectures
According to Eric Evans, Domain-driven design (DDD) is not a technology or a methodology. It’s a different way of thinking about how to organize your applications and structure your code. This way of thinking complements very well the popular MVC architecture. The domain model provides a structural view of the system. Most of the time,…
-
Zend Framework: The Cost of Flexibility is Complexity
The Zend Framework is a very flexible system, in fact, it can be used to build practically anything. But, the problem with using a flexible system is that flexibility costs. And the cost of flexibility is complexity. Martin Fowler wrote: Every time you put extra stuff into your code to make it more flexible, you…
-
Apache Log Analyzer 2 Feed
I found this project thanks to Raphael’s post Turning a Zend_Log log file into an RSS feed. Developed by Simone Carletti, ApacheLogAnalyzer2Feed is a really powerful open source PHP 5 class to parse and analyse Apache Web Server log files. Results are converted into a feed to let users subscribe them with a feed reader.…
-
ActiveRecord: JavaScript ORM Library
Aptana has just released a beta version of its ActiveRecord.js which is an ORM JavaScript library that implements the ActiveRecord pattern. It works with AIR and other environments: ActiveRecord.js is a single file, MIT licensed, relies on no external JavaScript libraries, supports automatic table creation, data validation, data synchronization, relationships between models, life cycle callbacks…
-
Four Great InfoQ Presentations
Hope you like these recommendations and if you know of any other good tech-related video, then please let me know. 1. Developing Expertise: Herding Racehorses, Racing Sheep One of my favourites. In this presentation Dave Thomas (The Pragmatic Programmer) talks about expanding people’s expertise in their domains of interest by not treating them uniformly as…
