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
PHP Headers for Sending CSV File Downloads
If you would like to force a file download prompt to the user, instead of just outputting the text to the browser, use the following headers.
...
Written by Sean Behan on 11/25/2017
XPath with HTML in PHP One Liner
Here is a one liner for using XPATH with HTML in PHP
$doc = new DOMXPath(@DOMDocument::loadHTML(file_get_contents("https://www.reddit.com/r/PHP/")));
Now you can use XPATH to query the html..
foreach($doc->query("//a") as $el){
echo $el->no...
Written by Sean Behan on 11/14/2017
How to Calculate Age with PHP
Calculate age in PHP
$your_birthday = '1982-08-29';
$difference = date_diff(date_create(), date_create($your_birthday));
$age = $difference->format('%Y');
// 35
Short and sweet
Written by Sean Behan on 11/11/2017
How to Use Named Variables with Postgres and PHP PDO Driver
You can write reusable scripts with Postgres by taking advantage of named variables.
A named variable starts with a `:` in your sql script. Here is an example
select :a_number
You can then use this statement with `psql` and the `--variable` fl...
Written by Sean Behan on 11/11/2017
How to Get a Random Item from an Array in PHP
Use this snippet for grabbing a random item from an array in php
$fruits = ['apple', 'banana', 'carrot', 'date', 'elderberry'];
echo array_rand(array_flip($fruits));
// => 'banana'
PHP's `array_flip` makes the keys the values and the valu...
Written by Sean Behan on 11/10/2017
Connect to Postgres on Heroku using DATABASE_URL Config Var with PHP and PDO
Unfortunately PHP's PDO constructor doesn't take a database connection url (in a format that Heroku makes available as a config var) as an argument. It has its own, rather odd syntax.
However, it's easy enough to extract url parts with the `parse_url`...
Written by Sean Behan on 11/10/2017
How to Slugify a String in PHP
Here is a snippet for generating a URL friendly slug in PHP
function slugify($string){
return strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $string), '-'));
}
And you can use it in your code like so
...
Written by Sean Behan on 10/26/2017