Playing with Roman numerals
Code-diesel Blog
by sameer
2y ago
The following code returns the longest Roman numeral string generated for the year between 1 and 2099. Note that the largest number that can be represented in Roman notation is 3,999 (MMMCMXCIX). function integerToRoman($year) { /* Ref: https://www.rapidtables.com/convert/number/how-number-to-roman-numerals.html * https://en.wikipedia.org/wiki/Roman_numerals */ $result = ''; // Create a lookup array that contains all of the Roman numerals. $lookup = array( 'M' => 1000, 'CM' => 900, 'D' => 500, 'CD' => 400 ..read more
Visit website
Reading SSL certificates in PHP
Code-diesel Blog
by sameer
2y ago
A recent project required me to write a automated SSL certificate checker that would ping me every-time a SSL renewal is due. The project required to parse a handful of client sites and get the SSL information. Reading a SSL certificate directly from a domain is relatively simple in PHP. A working example function is given below. /** * Takes a domain name and returns SSL certificate information * * @param string $domain_name * @return array $certinfo */ function getSSL($domain_name) { $errno = 0; $errstr = ''; // Set socket connection timeout $timeout = 30 ..read more
Visit website
Questions as an initiator of data projects
Code-diesel Blog
by sameer
2y ago
Unlike many other fields data-science projects should start with focused questions. A table of data is not of much use in itself unless we analyse and understand it with a specific goal in mind. Without a predefined goal we would not know where to start – what to look for in the data, how to analyze it, what extraneous elements should be removed etc. Take an example. The following data link gives the monthly, seasonal and annual maximum temperatures from 1901 to 2017 for India. The default format is in CSV. https://data.gov.in/resources/monthly-seasonal-and-annual-max-temp-series-1901-2017-0 W ..read more
Visit website
Yearly medicine dosage visualization
Code-diesel Blog
by sameer
2y ago
For the past several years I’ve regularly consumed Pantoprazole – a proton pump inhibitor (PPI) – to control my acid reflux. However, as it is well know, regular PPI use causes various health problems. I’ll not enumerate those here, but trust me when I say that they are numerous. Last year I decided to wean myself off PPIs slowly, by only limiting to a 20mg dose on any single day, and alternating or dropping some days completely. I recorded my dosage information in Google calendar on my mobile, so that I could process it later. Now that I’ve a more than a year’s data with me I thought of visua ..read more
Visit website
Quickly extract urls from a xml sitemap file
Code-diesel Blog
by sameer
2y ago
The following short PHP code will enable you to extract urls from a standard WordPress xml sitemap or any other website sitemap adhering to the sitemap schema. # extract-urls.php # # Extract only URLS from a XML sitemap. # Sitemap schema : https://www.sitemaps.org/protocol.html if(count($argv) getName() == 'urlset') { $children = $xml->children(); foreach($children as $child) { if($child->getName() == 'url') { echo $child->loc . PHP_EOL; } } } } else { exit('Failed to open XML file ..read more
Visit website
Visualizing missing data in databases
Code-diesel Blog
by sameer
2y ago
Missing data in databases can cause bugs in applications or incorrect calculations. Recently, while working on a RETS application, I needed to ensure that not many missing values were encountered in one of the MySQL tables. Although one could easily write a SQL query to find the percentage of missing values, I many times find it easier to first get a visual representation of the amount of missing data there is in the table, and then drill-down further if required. One library that I found that lets you easily get a visual representation of missing data in your database tables is missingno – a ..read more
Visit website
Pitfalls of assigning a wrong data type to a database column
Code-diesel Blog
by sameer
2y ago
A recent debugging session on a web application surfaced a recurrent issue in database design – that of assigning a wrong data type to a database field. Storing numeric data in a numeric field, when is it not recommended? Many programmers, when designing a database schema, default to using a numeric data type for a numeric field – like zip codes, telephone numbers, age, price etc. However, not every numeric value needs to be stored as a numeric type. Many times it is prudent to store numeric values as a ‘text’ type – ‘varchar’ to be specific. Take the case of a zip code – it usually gets assig ..read more
Visit website
Check PHP syntax from the command line
Code-diesel Blog
by sameer
2y ago
PHP command-line interface (CLI) includes a nifty option to quickly check for any syntax errors in a source code file. A simple check for a single file is given below. The option flag to check is -l (lowercase ‘L’). $ php -l example.php If the file contains no syntax errors, the CLI returns the following message. No syntax errors detected in example.php If there is an error in the code the CLI will return the error depending on the context of the error. Parse error: syntax error, unexpected '$dom' (T_VARIABLE) in example.php on line 6 Errors parsing example.php We can also test for multi ..read more
Visit website
Middleware in Express applications
Code-diesel Blog
by sameer
2y ago
If you have recently moved or are thinking of moving to the nodejs Express framework than you should primarily get acquainted with its routing and middleware concepts, as an Express application is essentially a series of middleware function calls. Middlewares in Express are functions executed after the incoming request from the client, the middleware then processes the request depending on its purpose and then hands over the request to the next middleware in the chain or generates a output if is the last one in the chain, terminating the request-response cycle. Middleware in a nutshell Middlew ..read more
Visit website
Styling terminal string in NodeJS
Code-diesel Blog
by sameer
2y ago
Most terminal applications or tools in NodeJS are single colored in nature. ‘Chalk’ is a nodejs package that allows you to style your application terminal output strings in various colors and styles, making it more readable and colorful. Installation is via npm. npm install chalk Usage is short and simple. const chalk = require('chalk'); console.log(chalk.blue('Hello world!')); // Displays string in Red A more detailed example. const chalk = require('chalk'); const log = console.log; // Combine styled and normal strings log(chalk.blue('Hello') + ' World' + chalk.red('!')); // Compos ..read more
Visit website

Follow Code-diesel Blog on FeedSpot

Continue with Google
Continue with Apple
OR