CodePlea icon
Random thoughts on programming
16 Aug 2019

SQL Query Executing Twice in PHP

I finally fixed a crazy bug on one of my sites where PHP + SQLite was causing some queries to run twice.

I run a lot of web sites, and I like PHP because it's easy to deploy and easy to maintain. More importantly it's easy to manage a large number of sites if they are all similarly setup. I run a lot of small side projects. These projects are the sort of things that I want to build in a weekend and then not really think about again.

Many of my PHP sites use the SQLite database. SQLite is great because it requires no setup or management. It's built into PHP, and you use it by just, well using it. There's no server or separate program to manage.

Read the rest of SQL Query Executing Twice in PHP

13 May 2019

I Wrote a Book

Hands-On Network Programming with C Book Cover

I wrote a book!

It's called Hands-On Network Programming with C, and it's all about network coding with sockets and the C programming language.

It's available now on Amazon. You may also be interested in the example code which can be found on Github.

It was a lot of fun to write, and I think it turned out pretty well.

A lot of topics are covered. Basic networking concepts, such as TCP, UDP, and IPv6 are all covered. I took careful attention to make sure that all the programs run on Windows, macOS, and Linux.

Read the rest of I Wrote a Book

30 Jul 2018

How F5Bot Works

F5Bot logo

F5Bot is a simple service that monitors social media (such as Reddit) for keywords. It emails you when your keywords show up. It's free to use.

I wrote an article about how F5Bot works and how I programmed it. You may find it interesting if you're interested in how web scraping works. In particular, I'm proud that I'm able to scrape and process all of Reddit (posts + comments) in real time, and I'm doing it on one tiny VPS.

The article is published as a guest post over on the intoli blog. You can read it here: How F5Bot Slurps All of Reddit.

20 Jul 2018

How to Embed an Arbitrary File in a C Program

A problem I've run into several times over the year, is that a small program I've written relies on another outside file. Maybe it needs to include an image, or maybe it relies on another small executable. It's a pain to deploy multiple files in these cases. I'd like everything nicely wrapped up into one executable.

So how do you embed a file into an executable?

Many years ago I wrote a small utility that takes a binary file for input. It then hex-encodes the file and outputs C code. The C code is an array which is initialized with the file's contents.

I just dug this program up to use it yet again, and I've decided that it'd be nice to share it.

Read the rest of How to Embed an Arbitrary File in a C Program

20 Feb 2017

Get an email whenever you're mentioned online

I've published a few open source projects, and I noticed that sometimes they would be posted on social media sites such as Hacker News, Reddit, Lobsters, etc. Sometimes I wouldn't notice these posts until days later (if ever), which meant that I did not have an opportunity to join in the discussion.

So I built a bot that scrapes these sites and scans for keywords. It sends me an email whenever one of my projects is mentioned. I decided that it would be pretty easy to turn it into a free service that others might enjoy, and so I did.

It's called F5Bot. F5Bot just takes a list of keywords and will send you an email whenever one of those keywords is mentioned on the social media sites it monitors. It's totally free, so signup and give it a try!

Read the rest of Get an email whenever you're mentioned online

06 Jan 2017

Incomplete Beta Function in C

The Incomplete Beta function, or regularized incomplete beta function, seems to be one of those functions that should be built into the standard libraries, but is conspicuously missing. It shows up all over the place in statistics. It's crucial to Student's t distribution, which is likely the second most important distribution in statistics after the Gaussian distribution.

a chart showing the incomplete beta function for different values of a and b

I couldn't find an open-source implementation to fit my exact needs, so I'm going to give simple C code to compute it.

If you're just looking for code, check out the Github repo. If you want to learn how it works, keep reading.

Read the rest of Incomplete Beta Function in C

22 Dec 2016

GoAccess, Analytics, and PHP

GoAccess is an excellent open source web log analyzer. It makes nice, fancy charts and such:

Screenshot of GoAccess output

GoAccess has several modes of running, including outputting HTML, or severing HTML live with its built-in webserver. I knew I wanted to use GoAccess to analyze my server logs, but I wasn't sure what the best way to use it was.

Read the rest of GoAccess, Analytics, and PHP

19 Dec 2016

Technical Analysis Library

I recently released a technical analysis library called Tulip Indicators under the LGPL license. If you need to do technical analysis, I think it's the best library out there now.

I also released a companion project called Tulip Cell which provides the functions to Excel spreadsheets via an add-in.

And finally, I'm working on a full featured charting program that I plan to release soon: Tulip Charts.

For older articles, please see the archive.