Writing
Notes on building software — the decisions that age well, the ones that don't, and what I learn in between.
-
How to Fix Raw query must include the primary key with Django ORM
When running raw SQL queries in Django you must include a primary key otherwise an invalid query exception is raised. Normally this is fine but when running more complex queries a primary key may...
-
Simple SQL for Counting New Signups
Here is a little snippet that will return new signups (or new records) for today select id, email, createdat::date date from signups where email not in (select distinct email from signups where...
-
How to Find An SQLite Database with React Native and the iPhone Simulator.
I spent a few hours digging around my file system using find and grep hunting for my SQLite database that the iPhone Simulator was using for my React Native project. And no luck. But I found a...
-
Active Admin Rails 5 undefined method per_page_kaminari
If you run into this error in development, using Rails 5 and Active Admin NoMethodError - undefined method perpagekaminari' Try the following. First, make sure you have an initializer in your...
-
Regex for Extracting URLs in Plain Text
Here is a Regex for extracting URLs from text. However, these links will not already be hyperlinked or source attribtues from images or iframes. This example is in PHP. I was trying to format a...
-
I Just Published My First PHP Package HTMLXPATH
I just wrote and published my first PHP package on Packagist.com. It's available on packagist.org and the source code is on github. To install the package use composer composer require...
-
Matching email addresses in Javascript
Matching email addresses in Javascript regex = /\b[a-zA-Z0-9.%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}\b/img "hello sean@example.com how are you? do you know bob@example.com?".match(regex) // =...
-
How to Make Cross Database Queries with Postgres and DBLink Extension
Here are a few snippets for cross database queries. It's important to note that you must be explicit in enumerating the columns and types you are querying. Otherwise, things will probably not work...
-
How to send email with Python, smtplib and Postmark
Here is a quick code snippet showing how to send email via SMTP with Postmark without any dependencies. It assumes you are using Heroku and have added the addon. But if not just make sure your api...
-
Using Selenium to Drive Firefox Browser for Web Automation
There are a lot of practical uses for automating user behavior in a browser. Everything from testing your web application to logging into Twitter and auto following people. But first you have to...
-
How to Import/Export a Database from One Heroku App to Another Heroku App
Heroku is awesome! Let's say we want to copy a production database to a staging database. We can use the pg:backups:restore command to accomplish this. Here is an example. For the source database...
-
Linux Disk Usage Command Recursive
It's short and sweet! du -hs If you run this command it will tell you the sizes of all the files and folder in the current directory. The -h flag is for human readable format and the -s will give...
-
Reshape an Array of Form Inputs for Flask with getlist()
This is how to reshape an array using Python without Numpy. This is a fairly simple task but it can be a little confusing to wrap your head around. I ran into this problem while working with Flask,...
-
Trigrams, Bigrams and Ngrams in Python for Text Analysis
Creating trigrams in Python is very simple trigrams = lambda a: zip(a, a[1:], a[2:]) trigrams(('a', 'b', 'c', 'd', 'e', 'f')) = [('a', 'b', 'c'), ('b', 'c', 'd'), ('c', 'd', 'e'), ('d', 'e', 'f')]...
-
How To Create a Dump File in Postgres Compatible with Heroku
When Heroku creates a dump file of your Postgres database it uses the -Fc option It is equivalent to running pgdump -Fc -d nameofdb nameofdb.dump This command will let you import your database with...