Posts

How To Enable Auto-Completion in Python Shell

Learn how to use TAB to auto-complete expressions in plain vannila Python shell. If you need to have auto completion in Python shell (almost the same way as iPython), it's very easy. Create a file named .pyreadline with the following content and put it in your home directory. #!python import rlcompleter, readline readline.parse_and_bind('tab: complete') Export the file as PYTHONSTARTUP variable; for example append it to .bashrc . echo "export PYTHONSTARTUP=~/.pyreadline" >> ~/.bashrc

How To Batch-set Environment Variables

Learn how to automatically (dump) set environment variables defined in a file. Sometimes you have a file (usually called .env or .environment ) with dozen of environment variables defined and you have to set those variables before running a command --for example this happens in Django projects with a .env file for settings. The solution is easy: export $(cat ENVIRONMENT_FILE | xargs) && YOUR_COMMAND

How To Add Logging To A Clojure Project

When deploying a Clojure application in a production environment, it is necessary to have logging enabled to be able to, in case of any failure, track down the problem using the logs later. Clojure inhertis serveral logging frameworks from Java like Log4j and it has its own Clojure'esque wrapper around Java logging API called clojure.tools.logging . This HowTo will help you get started with a working “loggable” Clojure project. Though the instructions assume that you're using Leiningen for build automation, it can be applied to any Maven based build too. Setting Up A New Project This creates a new empty project: $ lein new app logger1 Generating a project called logger1 based on the 'app' template. Now edit project.clj to add required dependencies: (defproject logger1 "0.1.0-SNAPSHOT" :description "FIXME: write description" :url "http://example.com/FIXME" :license {:name "Eclipse Public License" :url ...

Thoughts On JVM-based Forth Implementation

Image
Is it possible and worth to implement Forth on top of JVM? Forth : A language which looks as weird as it is simple and powerful --and it looks extremely weird! I, first, came to know Forth with help of my good friend Michael a.k.a. ttmrichter and immediately Forth placed itself on top of the favourite language pyramid in my mind, alongside only Lisp family. Since then, I've been eager to do serious coding in Forth. However, there's a problem: most of Forth'ers work in the system/chip programming field which means that there are hardly any higher level libraries (e.g. UI toolkits or database connectors) for someone like me to try Forth in business applications. It's definitely possible to write all those libraries starting from the scratch but even the thought of it turns my stomach! Recently I've been thinking about implementing Forth on JVM. JVM Forth has several advantages: It will be platform independent. It will have access to tons of existing libraries...

Tornado Web Framework - Flash Messages

Implement flash messages in Tornado web framework. Problem Suppose you have a URL for editing an object under /OBJECT-ID/edit . Normally when user fills in the information on that page and presses the submit button, the request is sent to /OBJECT-ID/update which persists the data. But if the the data provided by user is not valid, you need to redirect user the to /OBJECT-ID/edit along with the provided data and validation errors, so s/he can correct it. The clean and preferred way to do this is by using flash cookies. Code All the source code provided in this post, is licensed under Apache License 2.0. import re import pickle from tornado.escape import to_unicode from tornado import web, escape class Flash(object): """ A flash message along with optional (form) data. """ def __init__(self, message, data=None): """ 'message': A string. 'data': Can be anything. ""...

Spec - Part II: The Layout

Image
GUI Development in Pharo Smalltalk using Spec. It covers the layouts and tidies up the Greeter application built in part I.  Last updated: March 2019 Introduction First of all: have you read the first part of this series yet? If not, please do so as we are going to iterate over what was done there. As you recall, the greeter application which was built earlier was fully functional. However, it was not easy on the eye --in other words, it was very ugly. As promised, we will tidy it up in this episode. The Question Of The Ages "What do you want!?" Before setting off on the road of endlessly pushing and pulling widgets around, let's first settle for a target design. For the rest of this episode, we will try to achieve the following design (this design is done in LibreOffice Draw and is not a snapshot from the system): Figure 1 - The target design for this episode Layout Smithing Tools There are about half a dozen of layouts and widgets (which can be used ...

Spec - Part I: The Basics

Image
GUI Development in Pharo Smalltalk using Spec. It covers the basics concepts and walks you through the building up of a Spec version of the legendary "Hello, world". Last updated: March 2019  Introduction Spec is a UI library for Pharo Smalltalk. Well, to be more precise, Spec is a library for describing UI elements, their properties and their behaviour. Under the hood the output of Spec is fed into a UI framework like Polymorph to draw the widgets on the screen. In this series of tutorial episodes, you will understand its concepts and learn how to use it for your everyday UI programming requirements. Prerequisites For this series we will use Pharo 7.0 (the latest stable version at the time of writing this) and since Spec is already included in Pharo 7.0, you don't need to do anything. Just create a package to put in all the classes that we create -- let's assume My-Spec-Tutorial as the name. The First Window Windows are the primary containers for ot...

ADempiere: How To Use Scala For Customisations

Image
Scala is a viable alternative to Java. This guide shows how easy it is to develop ADempiere ERP customisations in Scala. Introduction Scala is becoming an increasingly popular language and for many companies/developers it's a superior alternative to Java. ADempiere open source ERP/CRM , is written in Java but since Scala runs on JVM and has very good Java interoperability, it's very easy to customise ADempiere with Scala. We'll see how it can be done. Prerequisites The only things you're going to need is ADempiere binaries.  You can either download them from SourceForge or build it directly from source with RUN_build (at the time of this writing 3.7.0LTS was the latest). JDK 1.6 Scala 2.10.x  (at the time of this writing 2.10.2 is the latest) SBT 0.12.x (at the time of this writing 0.12.4 is the latest) Project Template I have created a template project which is hosted on github to speed up things for people. First clone it: git clone https://github.com/bahm...

Grails: How To Secure Your Application Using Spring Security Core

Image
A step by step tutorial on how to use Spring Security Core to secure your Grails application. Introduction Any web-based application must have a mechanism for authenticating users and authorising them to do their defined activities in the system. One can go for the traditional approach of doing it with a login form; it works for the start. But on today's Internet, a classic pair of username and password is not always available as many people prefer to use a single OpenID, Twitter or Facebook account to access their data across different web sites. Also in corporate environments usually authentication and authorisation is done against an LDAP database. This is where Spring Security collection comes to play by allowing you to connect to a wide range of data sources and acquire access information from them instead of strong them yourself. At the heart of Spring Security lies Spring Security Core and as usual there's a Grails plugin for that! Let's see how we can use it. ...

A New Platform For Business Application Development

Image
Anybody who has been involved in developing a business application, has already exhausted the long list of frameworks/libraries in JVM, .NET and Python platforms searching for something that reduces the costs while increases the development speed. However it's almost proved to me that one should seek the answer in less explored/popular platforms. Let's meet Pharo! Introduction Well, the title of this blog entry may be a bit confusing as the platform I'm going to talk about is not "new" at all! In fact, it's been around evolving far more than most of us know and could imagine. As a polyglot programmer, for the past 5 years, I've been trying many different languages and platforms to find one which would help me reach my goal: to write a business application (ERP) which can be run in hosted mode (SaaS) and is easily maintainable; and I had a short list of features/characteristics I was looking for in any of them. Note: I will elaborate on software as a ...