PHPNews

Convert CSV to Excel in PHP

During a recent data conversion project I needed to convert around 250 CSV files to Excel (xls) format. As this was a PHP project I decided to write a small PHP script using the PhpSpreadsheet library. Installation Use composer to install PhpSpreadsheet into your project: composer require phpoffice/phpsp…

Continue reading »

Written by code-diesel - - Aggregated on Thursday July 12, 2018


Writing WordPress posts in Markdown

WordPress allows you to write your posts using Markdown. This feature is available using Jetpack. If you write some of your eBooks or other documents using Markdown, and need to transfer some of the same content to a WordPress blog than this feature is extremely useful. No need to again create a different HTML version …

Continue reading »

Written by code-diesel - - Aggregated on Wednesday July 4, 2018


Free datasets for testing database engines

Below is a small list of free datasets with which you can test your database queries or use it for learning and practicing sql query optimization or other things. I’ve recently started reading some database books, specially by Joe Celko , and needed some medium size datasets on which I could run the sql queries …

Continue reading »

Written by code-diesel - - Aggregated on Monday July 2, 2018


PHP Simple HTML DOM Parser Script

In this post I have explained some elements to scrap data from external websites. Simple HTML DOM parser is a PHP 5+ class which is useful to manipulate HTML elements. This class can work with both valid HTML and HTML pages that do not pass W3C validation. You can find elements by ids, classes, tags and many more. …

Continue reading »

Written by code-diesel - - Aggregated on Thursday June 21, 2018


Face detection using jQuery

Face detection is a common feature in most digital cameras today; the white or red square that pops around someones face when we are focusing the camera on that person. Face detection algorithms enables the software to pinpoint the locations and sizes of human faces in digital images, whatever the surrounding objects …

Continue reading »

Written by code-diesel - - Aggregated on Wednesday June 20, 2018


Rendering text tables with NodeJS

A recent data project required the program to emit data tables from node which could be piped to other processes. easy-table is one such package which provided a nice way to output text tables in the console. Installation is using npm. $ npm install easy-table A small example code is given below. …

Continue reading »

Written by code-diesel - - Aggregated on Monday June 18, 2018


How to access Gmail using Python

In a previous post we saw how you could access Gmail in NodeJS. In this post we will see how we can access Gmail using Python. Turning on the Gmail api You first need to enable Gmail api and get the required OAuth credentials from your Google account. The steps which are shown below. 1 . Use this wizard …

Continue reading »

Written by code-diesel - - Aggregated on Monday June 18, 2018


Combinatorial row pairing in databases

While working on a database design I came across the problem of finding combinations or ‘cartesian product’ between all the rows between one table to another table, but not repeating the same permutations. Take the ‘Teams’ table below which lists four cricket teams. We want to create a combination list of matches …

Continue reading »

Written by code-diesel - - Aggregated on Monday June 11, 2018


How to read and create zip files in nodejs

As I’ve been working on a small project for the past few months, mostly related to backend processing – files, databases etc. The small part of the project needed the ability to read and write zip files. I found the jsZip npm package adequate for my requirement. This allows me to quickly read and write zip files. …

Continue reading »

Written by code-diesel - - Aggregated on Monday June 4, 2018


Listing files using glob patterns in nodejs

In a previous post we saw how to monitor files changes in nodejs. This was required in a cron job to check which files were changed by the cron process. I also needed to search for files in a particular directory to check which files were newly created by the process. Although this is possible using the file-state-…

Continue reading »

Written by code-diesel - - Aggregated on Monday May 7, 2018


Monitoring file changes using NodeJS

During script runs – that change files – I frequently need to check which files have been modified by the scripts, especially in CRON automated tasks. This allows me to take appropriate actions depending on the file state change. The following post shows how we can monitor file state changes in nodejs. For this …

Continue reading »

Written by code-diesel - - Aggregated on Tuesday May 1, 2018


Fuzzy string matching in NodeJS

String matching is an integral part of any programming language. Many times, however, one requires to get a fuzzy instead of an exact match between strings. Usually in search applications the same word may be spelled differently – which if we do an exact math will return empty results. Fuzzy matching allows you to …

Continue reading »

Written by code-diesel - - Aggregated on Monday April 23, 2018


Creating custom stream filters in PHP

In this post we will see how to create a custom stream filter. Streams , first introduced in PHP 4.3, provide an abstration layer for file access. A number of different resources besides files – like network connections, compression protocols etc. can be regarded as “streams” of data which can be serially read and …

Continue reading »

Written by code-diesel - - Aggregated on Wednesday April 11, 2018


Five APIs All Developers Need to Know

Every day, dozens of developer tools get released online. Some new developers opt for doing all their work manually, while others choose to explore new tools. If you fall into the second category, then you need to start using APIs. The acronym stands for Application Programming Interface. In essence, it’s a programin…

Continue reading »

Written by code-diesel - - Aggregated on Friday April 6, 2018


Unpacking binary data in PHP

Working with binary files in PHP is rarely a requirement. However when needed the PHP ‘pack’ and ‘unpack’ functions can help you tremendously. To set the stage we will start with a programming problem, this will keep the discussion anchored to a relevant context. The problem is this : We want to write a function that …

Continue reading »

Written by code-diesel - - Aggregated on Wednesday April 4, 2018


How to calculate the size of a MySQL database

Many times we need to calculate the size of a MySQL database through code for purpose like database backup or to check how fast the database is growing for a certain application. The database size can be easily ascertained using phpmyadmin or other desktop tools, but that requires you to manually launch the tool and …

Continue reading »

Written by code-diesel - - Aggregated on Monday April 2, 2018


How to profile and debug MySQL queries for speed

Most MySQL applications need profiling for speed enhancements at one time or other. I’ve developed several web applications in the past wherein MySQL queries were a major bottleneck in the application performance. In the past however there were no easy tools to analyse SQL queries in a running application and we …

Continue reading »

Written by code-diesel - - Aggregated on Monday April 2, 2018