Skip to content

Instantly share code, notes, and snippets.

View arjenblokzijl's full-sized avatar

Arjen Blokzijl arjenblokzijl

View GitHub Profile
@arjenblokzijl
arjenblokzijl / create-random-dates.php
Created May 18, 2016 13:35
Create random dates between in PHP
<?php
// Forgot where this came from
function rand_date($min_date, $max_date) {
$min_epoch = strtotime($min_date);
$max_epoch = strtotime($max_date);
$rand_epoch = rand($min_epoch, $max_epoch);
@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) {
@arjenblokzijl
arjenblokzijl / gist:9272411
Last active April 25, 2018 15:18
Generate ProcessWire pages with random titles, body and image
<?php
for ($i = 1; $i <= 20; $i++)
{
$title = file_get_contents("http://loripsum.net/api/1/plaintext/long/prude/");
$body = file_get_contents("http://loripsum.net/api/3/decorate/link/ul/prude/long/");
$template = "INSERT_TEMPLATE_HERE"; // i.e. 'basic-page'
$parent = "INSERT_PARENT_HERE"; // i.e. /about-us/
$c = new Page();
@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 / 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 / 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 / instructions.md
Created February 26, 2021 19:49
Separate work and personal git accounts

Edit global gitconfig file

git config --global --edit

# This is Git's per-user configuration file.
[user]
	name = Your Work Name
	email = user@workemail.com