Writing
Notes on building software — the decisions that age well, the ones that don't, and what I learn in between.
-
How to Dynamically Call a Method from a String in Swift
You have to subclass NSObject class Car : NSObject { func drive(){ print("Driving..") } } let car : Car = Car() car.perform(NSSelectorFromString("drive"))
-
How to Check if Your iOS or MacOS App is Connected to the Internet
Is your app connected to the internet? You can use this standalone class to check! There are no dependencies so you can copy/paste it into your project without needing to install another framework....
-
How to Flush or Erase Cache of Your XCode iOS or MacOS Cocoa App
If you're working with an XCode application, either iOS or MacOS, and want to do a completely clean build and delete the cache, it's simple. Execute this command from the command line.. defaults...
-
How to Find the Directory Locations Your XCode App Uses
You can add this snippet to your application, say for instance in your viewDidLoad function, that will print to the XCode console, the location of your app while it's being developed. // prints the...
-
How to Find Postgres Log File and Postgres Data Directory from PSQL
If you want to find the location of your log file in Postgres, you'll need to hop into a Psql session.. psql dbname Then it's as simple as running.. show data\directory ; Which will output the data...
-
How to Use Python Shutil Make_Archive to Zip Up a Directory Recursively including The Root Folder
The documentation for Python's shutil.makearchive is very confusing. Considering that the arguments to this function only need to be source and destination, makes it even more frustrating to try...
-
How to Just Get SQL Statement Error with SQLAlchemy Python Database Wrapper
If you're working with SQLAlchemy, the best database driver for Python, and want to see only SQL syntax errors, you need to use the StatementError exception class. On it, is an attribute orig, that...
-
Extension for Encoding and Decoding Strings in Base64 in Swift
Here is an extension to base 64 encode and decode strings in Swift (3) extension String { func fromBase64() - String? { guard let data = Data(base64Encoded: self) else { return nil } return...
-
How to Emulate Double Tap for Progressive Web Apps (PWA) iOS and Android
The double tap event isn't supported in libraries like jQuery Mobile (out of date anyway). But coding up your own function is very easy. We will compare time in milliseconds between tap or click,...
-
How to Log and Query SQL Queries Hitting Your Database with MySQL
Here is some code just in case you want to look at and query the queries hitting your MySQL database. Enter this from the mysql client console. mysql SET GLOBAL logoutput = 'TABLE' mysql SET GLOBAL...
-
How to Extract Time Information from a Natural Language String with a Regular Expression and PHP
You can easily extract time information from a string with a regular expression and PHP (or any language with regular expressions). $str = "Here is how to extract time info.. like 4:30 PM and 2:10...
-
How to Filter or Search HTML with Vanilla Javascript - No JQuery Required
The basic approach is to use the document.querySelectorAll to match certain elements, then manually set the display property to 'none' or 'block' (or 'inline-block') to hide or show it. Using the...
-
How to Time Piped *nix Commands
If you want to time how long a piped bash command take, use the time command followed by your commands in parens like so.. time (ls -lha | wc -l)
-
How to Parse Query Strings in PHP
Here is a quick snippet for parsing query strings in PHP. You can use the parseurl and parsestr methods. parsestr will create a variable for you populated with results. $url =...
-
How to import CSV into SQLite3
To import a CSV file into SQLite is easy. sqlite3 my.db .mode csv .import path/to/file.csv nameoftable And done.