Skip to content

Instantly share code, notes, and snippets.

View leftclickben's full-sized avatar

Ben New leftclickben

View GitHub Profile
@leftclickben
leftclickben / testUnsort
Created September 6, 2013 07:32
Take an array of items and "unsort" them so that the items sharing similar properties are separated as much as possible. This code is not highly optimised and is not recommended for large data sets.
#!/usr/bin/php
<?php
// This is the input array.
$values = array(
array(
'title' => 'First item (1,1)',
'categoryID' => 1,
'storeID' => 1
),
@leftclickben
leftclickben / knockoutDateSelector
Last active December 24, 2015 14:09
Knockout date selector - use three `<select>` elements and compute a date, also restrict date within certain range
<!doctype html>
<html>
<head>
<title>Knockout Date Selector</title>
</head>
<body style="background-color:#eee;font-family:sans-serif;">
<article style="width:600px;background-color:#fff;margin:1em auto;border:1px solid #000;padding:1em;">
<h1>Knockout Date Selector</h1>
<p>
@leftclickben
leftclickben / loadtest.js
Last active December 28, 2015 12:59
Simple website load tester written in Node.js
/*jslint node: true, white: true, nomen: true, plusplus: true*/
/*globals require: true, process: true*/
/*!
* Generic load tester
* Copyright (c) 2013 Leftclick.com.au
* MIT License, or whatever.
* Author assumes no liability for damage, loss, etc.
*
* Configuration is passed as a command-line argument when running node, e.g.
@leftclickben
leftclickben / cleanup-providence-database-after-relationship-generator-integration-test.sql
Created May 14, 2014 04:17
cleanup-providence-database-after-relationship-generator-integration-test.sql
-- Cleans up any data that might be remnant after a run of the RelationshipGeneratorPluginIntegrationTest,
-- particularly if the run fails for some reason, it might not execute its tearDown() and can leave remnant
-- data in the database.
-- NOTE YOU WILL NEED TO MODIFY SOME OF THE HARDCODED VALUES IN HERE TO SUIT YOUR CURRENT DATABASE
-- Alternatively this could probably be improved to use more of the "code like '%...%'" and less of the "id > X" style
delete from ca.ca_attribute_values where value_id > 14;
delete from ca.ca_attributes where table_num = 57 and element_id = 70 and row_id > 46;
@leftclickben
leftclickben / test-ldap-2.php
Last active June 11, 2024 14:06
Open a connection to an LDAP server, query it for a given user, and check group membership for that user (test script)
#!/usr/bin/php
<?php
# Parse options
$opts = getopt('h:n:u:p:b:s:', array( 'help' ));
if (isset($opts['help']) && $opts['help']) {
echo <<<ENDHELP
Usage:
$argv[0] [-h HOSTNAME] [-n PORTNUM] [-u USERNAME] [-p PASSWORD] [-b BASEDN] [-s SEARCH]
@leftclickben
leftclickben / gist:322b7a3042cbe97ed2af
Last active June 7, 2023 10:58
Steps to migrate from SVN to GitLab

Steps to migrate from SVN to GitLab

This process worked for me. I take no responsibility for any damage or loss incurred as a result of following or not following these steps or, for that matter, anything else you might do or not do.

Setup

  • SVN is hosted at svn.domain.com.au.
  • SVN is accessible via http (other protocols should work).
  • GitLab is hosted at git.domain.com.au and:
@leftclickben
leftclickben / nestedRenameSpacesToUnderscores
Last active August 29, 2015 14:09
Rename whitespace in files to underscores, with any level of nesting
maxdepth=`find . -printf '%d\\n' | sort -n | tail -1` && for depth in `seq 1 $maxdepth`; do find -mindepth 1 -maxdepth $depth -exec bash -c 'f=`echo "{}" | sed -r s:\\\s+:_:g` ; if [ "$f" != "{}" ]; then mv "{}" "$f"; fi' \; ; done
@leftclickben
leftclickben / describeScreen.php
Last active August 29, 2015 14:24
(CollectiveAccess) Retrieve CSV of placements for a given screen, with labels
#!/usr/bin/env php
<?php
$screen = 35; // modify as required
$locale = 'en_AU';
$pdo = new PDO('mysql:host=wamcmisdb01-staging;dbname=cmis', 'cmis', 'uhkdv5Uwhkk7pmv');
$placements = $pdo->query('select * from ca_editor_ui_bundle_placements where screen_id = ' . $screen . ' order by rank asc')->fetchAll();
foreach ($placements as $placement) {
$settings = unserialize(base64_decode($placement['settings']));
@leftclickben
leftclickben / strip-referer
Created December 7, 2015 07:05
strip-referer
#!/bin/bash
# http://nigel.mcnie.name/blog/removing-the-referer-part-of-php-error-messagse-from-apache-logs
perl -pe 's/\s+\[\:error\]\s+\[pid\s+\d+\]\s+\[client\s+.*?\]//; s/, referer:.*//'
@leftclickben
leftclickben / admin-access.js
Last active July 4, 2018 00:58 — forked from spencermefford/0-model-override.js
An alternative to extending Loopback's built-in models: use a boot script to enhance the built-in model
(function () {
'use strict';
// Relevant resource: https://gist.github.com/spencermefford/bc73812f216e0e254ad1
module.exports = function (server, callback) {
var ACL = server.models.ACL,
User = server.models.User,
Role = server.models.Role,
RoleMapping = server.models.RoleMapping;