How to Handle Uploading Really Large Files in PHP
PHP has some default limits that do not work out of the box when you want to work with uploading very large files. So there are a few configuration changes you have to make to the defaults that come with PHP. These are defined in you php.ini file. The...
Written by Sean Behan on 09/20/2018
How to Chunk Large Files in Swift
How to Chunk Large Files in Swift (4.1) It takes a bit of work but this is the solution I found that finally worked, thanks to this Stack Overflow thread https://stackoverflow.com/questions/46464177/split-data-in-chunks-and-upload-to-server The example ...
Written by Sean Behan on 09/15/2018
Select Basename in Postgres SQL
Postgres doesn't have a basename function per se. But it's easy to accomplish. select regexp_replace('http://www.seanbehan.com/images/logo.png', '.+/', '') ; -- Will return logo.png
Written by Sean Behan on 08/16/2018
How to Extract all Images from a Webpage with Ruby
Here is a little ruby snippet that will download all pictures from a webpage. Rather than using XPath, we are going to first reduce the source code to capture everything inside of quotes. Some websites use JSON w/in a script tag to lazy load images an...
Written by Sean Behan on 08/01/2018
How to Get GPS Location Information from Address String with Swift and iOS CLGeocoder
You can use CLGeocoder geocodeAddressString method. It will return an array of CLPlacemark objects that contain gps coords and city, location info. let address = "Burlington, Vermont" CLGeocoder().geocodeAddressString(address, completionHandler...
Written by Sean Behan on 06/11/2018
How to Get GPS Location Information from a Photo or Movie with Swift and UIImagePickerController
This code assumes you're using the UIImagePickerController. If not you will need to get an image url another way. But, If you are using UIImagePickerControllerDelegate then it will supply the asset's url in the `info` dictionary . From the asset's url...
Written by Sean Behan on 06/11/2018
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"))
Written by Sean Behan on 06/09/2018
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. With this class it's as simple as running `Reachabili...
Written by Sean Behan on 06/08/2018
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 delete your.apps.bundle.id Where "your.apps.bundl...
Written by Sean Behan on 06/08/2018
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 location of asset my-added-file.txt that you've ad...
Written by Sean Behan on 06/06/2018
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 directory, in my case.. /Users/sea...
Written by Sean Behan on 05/25/2018
How to Use Python Shutil Make_Archive to Zip Up a Directory Recursively including The Root Folder
The documentation for Python's shutil.make_archive is very confusing. Considering that the arguments to this function only need to be source and destination, makes it even more frustrating to try and reason about. Here are the relevant docs from the p...
Written by Sean Behan on 05/16/2018
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 contains just the SQL syntax error... and not any data...
Written by Sean Behan on 05/10/2018
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 String(data: data, encoding: ....
Written by Sean Behan on 05/02/2018
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, events. The reason for both tap and click events is due ...
Written by Sean Behan on 04/08/2018
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 log_output = 'TABLE' mysql> SET GLOBAL general_log = 'ON'; mysql> select event_ti...
Written by Sean Behan on 03/17/2018
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 AM from a string in PHP"; $rgx = "/\d{1,2}(:?\d...
Written by Sean Behan on 02/26/2018
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 `match` method allows us to detect whether or not the sea...
Written by Sean Behan on 01/30/2018
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)
Written by Sean Behan on 12/11/2017
How to Parse Query Strings in PHP
Here is a quick snippet for parsing query strings in PHP. You can use the `parse_url` and `parse_str` methods. `parse_str` will create a variable for you populated with results. $url = "http://www.seanbehan.com/path/?param=key"; parse_str(parse_url...
Written by Sean Behan on 12/04/2017
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 name_of_table And done.
Written by Sean Behan on 12/03/2017
How to Cast an Array to an Object with PHP
It's short and sweet. $obj_from_array = (object)['key'=>'val']; echo $obj_from_array->key;
Written by Sean Behan on 12/02/2017
How to Tag and Push a Release with Git
Set the `-a` and the `-m` flags like so git tag -a v1.0.0 -m "Note about the release goes here" Then to push the tag to a repository git push origin --tags And that's it! Here are the docs [https://git-scm.com/book/en/v2/Git-Basics-Tag...
Written by Sean Behan on 11/29/2017
How to Make an iOS App Icon from a File on the Command Line or Web Browser
If you need to make iOS app icon assets from a photo, take a look at the [Make App Icon](https://makeappicon.com/) website and API. They will let you upload an image from a web browser (in exchange for an email) and then email you the assets you can just...
Written by Sean Behan on 11/28/2017
Simple Way to Calculate the Odds of Something Happening
Here is a quick way to express a chance of something happening. This is an example in JavaScript that gives you a 1 in 3 chance of being true. [true, false, false].sort(function(){ return Math.random() >= 0.5 ? 1 : -1 })[0] Basically, we popu...
Written by Sean Behan on 11/27/2017