Skip to content

Instantly share code, notes, and snippets.

View arjenblokzijl's full-sized avatar

Arjen Blokzijl arjenblokzijl

View GitHub Profile
@arjenblokzijl
arjenblokzijl / gist:b0bd9d2db524b42c6a4b
Created July 27, 2015 08:01
War tested PHP regular expressions
Dutch Chamber of Commerce > /(?<!\d)\d{8}(?!\d)/
Dutch postal code > /^[1-9][0-9]{3}[\s]?[A-Za-z]{2}$/i
General URL > @(https?|ftp)://(-\.)?([^\s/?\.#-]+\.?)+(/[^\s]*)?$@i
LinkedIn URL > /(ftp|http|https):\/\/?((www|\w\w)\.)?linkedin.com(\w+:{0,1}\w*@)?(\S+)(:([0-9])+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
@arjenblokzijl
arjenblokzijl / font-awesome.txt
Last active August 29, 2015 14:25
ProcessWire Hanna Code export for Font Awesome usage
!HannaCode:font-awesome:eyJuYW1lIjoiZm9udC1hd2Vzb21lIiwidHlwZSI6IjIiLCJjb2RlIjoiXC8qaGNfYXR0clxuaWNvbj1cIlwiXG5jb2xvcj1cIlwiXG5oY19hdHRyKlwvXG48P3BocFxuXG5pZiAoJGljb24pIHtcblxuICAgIGlmICgkY29sb3IpIHtcbiAgICAgICAgJGNvbG9yID0gXCJzdHlsZT0nY29sb3I6JGNvbG9yJ1wiOyBcbiAgICB9XG4gICAgXG4gICAgZWNobyBcIjxpIGNsYXNzPSdmYSAkaWNvbicgJGNvbG9yPjxcL2k+XCI7XG5cbn0ifQ==/!HannaCode
@arjenblokzijl
arjenblokzijl / splitcsv.sh
Created August 13, 2015 11:18
Split CSV file and preserve header
tail -n +2 file.txt | split -l 4 - split_
for file in split_*
do
head -n 1 file.txt > tmp_file
cat $file >> tmp_file
mv -f tmp_file $file
done
@arjenblokzijl
arjenblokzijl / add-extension.sh
Last active August 29, 2015 14:27
Recursively add file extension to all files
# http://stackoverflow.com/questions/1108527/recursively-add-file-extension-to-all-files
find . -type f -exec mv '{}' '{}'.jpg \;
@arjenblokzijl
arjenblokzijl / split-processwire-array.php
Last active May 16, 2018 07:33
Split WireArray/PageArray into chunks
<?php
// Thanks to netcarver > https://processwire.com/talk/topic/7803-implement-array-chunk/?p=75573
$items = $pages->find('#whatever'); // Find your stuff
$parts = 3; // How many items should there be in 1 chunk?
$chunked = array_chunk($items->getArray(), $parts);
foreach ($chunked as $chunk) {
foreach ($chunk as $item) {
@arjenblokzijl
arjenblokzijl / ssh-keys.md
Last active August 16, 2017 06:03
Setup SSH keys

SSH keys

1. Create

ssh-keygen -t rsa

2. Store the keys (and passphrase)

Once you have entered the Gen Key command, you will get a few more questions:

@arjenblokzijl
arjenblokzijl / workflow.md
Last active November 9, 2015 11:03
Single mainline Git workflow

Workflow

Single mainline Git workflow

proces

The single mainline workflow constists of:

  • a single mainline branch ("master")
  • one short-lived feature branch per feature with a speaking branch name
@arjenblokzijl
arjenblokzijl / convert-csv-file-to-php-associative-array.php
Last active July 30, 2020 19:55
Convert CSV file to PHP associative array
<?php
/* Thanks to http://steindom.com/articles/shortest-php-code-convert-csv-associative-array */
ini_set('auto_detect_line_endings', TRUE);
$rows = array_map('str_getcsv', file('myfile.csv'));
$header = array_shift($rows);
$csv = array();
foreach ($rows as $row) {
@arjenblokzijl
arjenblokzijl / ssl-serverpilot.md
Last active July 25, 2018 20:36
How To Add SSL to ServerPilot nginx

How To Add SSL to ServerPilot nginx

Requirements

  1. Domain (i.e. example.com)
  2. Subdomain(s): (i.e. www.example.com)
  3. Username
  4. App name

Create the Certificate

@arjenblokzijl
arjenblokzijl / save-fields-from-csv.php
Created May 18, 2016 13:33
Save fields in ProcessWire from .csv file
<?php
// Bootstrap ProcessWire
include 'index.php';
// Process CSV
$rows = array_map('str_getcsv', file('fields.csv'));
$header = array_shift($rows);
$fields = array();
foreach ($rows as $row) {