Posts

Creating a Custom Log Helper for the CodeIgniter Framework

Over the past few months, we've been working extensively with the PHP CodeIgniter framework. One thing that consistently slowed me down during debugging was the repetitive process of logging variables. Every time I needed to log a variable, I found myself typing out log_message('error', $your_variable) —a lengthy 18 characters every single time! And that’s just for basic variables. If I wanted to log a boolean, object, or array, the process became even more time-consuming, often requiring additional if statements or extra formatting. To simplify this process, I decided to write a small custom log helper. This helper makes logging easier by automatically handling different variable types, allowing for faster and more efficient debugging. If you’re working with CodeIgniter and find logging as tedious as I did, you might find this helper useful too. <? if ( !function_exists('l') && !function_exists('l2') && !function_exists('ge...

Unexpected Session Logout Issue in CodeIgniter: A Case Study

The Problem Recently, at work, we encountered a puzzling issue with our web application, which was built using the CodeIgniter PHP framework. Users were being logged out unexpectedly, and the logout behavior was irregular and hard to predict. Although we noticed this problem early on, it was difficult to reproduce consistently, making debugging a challenge. The issue seemed random, but we eventually observed that it occurred more frequently when the screen displaying a map of POI (Points of Interest) positions was refreshed at short intervals, such as every few seconds. What Was the Cause? Initially, we suspected the session was expiring prematurely. However, upon closer inspection, we discovered that the session cookie was being truncated—losing about 10 to 20 characters. This led us to investigate the CodeIgniter Security class, specifically the xss_clean function, which is designed to prevent cross-site scripting (XSS) attacks. The root cause was a regular expression within xss_cle...

Creating a Drill-Printing Robot with Android and leJOS

Image
Project Overview This project is an exciting fusion of Android development and robotics, combining an Android application with the LEGO NXT cube (v1.0) enhanced by the leJOS firmware. The result? A robot capable of drilling images, among other things! The project consists of two main components: Android Application : This app communicates with the NXT cube via Bluetooth, acting as a controller for various robotic functions. NXT Robot with leJOS Firmware : The NXT cube is upgraded with leJOS, allowing programming in Java, making it more versatile for complex tasks. Android Application The Android app isn't just for drilling images—it's a comprehensive controller for the NXT robot. Initially, it was designed as a multi-functional tool capable of: Controlling the robot’s movement using different programs, like line-following or accelerometer-based controls. Allowing the user to select the type of robot and the corresponding control programs. After pairing the app with the NXT cube...

Automatically Rotating Scanned Text Images with Tesseract OCR

Problem If you've ever had a batch of scanned images with text, you know how tedious it can be to manually rotate each one to the correct orientation. This process can be especially frustrating when dealing with a large number of images. Wouldn't it be great if there were a way to automatically rotate these images so that the text is always upright and readable? Solution To solve this problem, I developed a simple script that automatically detects the correct orientation of text in scanned images using Optical Character Recognition (OCR) and dictionary matching. Here's how it works: OCR Parsing with Tesseract : I used Tesseract, a popular open-source OCR engine, to extract text from the images. Tesseract is powerful and versatile, making it an excellent choice for this task. Dictionary Matching : I created a list of the most commonly occurring words in the text. This list acts as a reference to determine the correct orientation. While my example includes only 5-6 words,...