Skip to content

Instantly share code, notes, and snippets.

View leftclickben's full-sized avatar

Ben New leftclickben

View GitHub Profile
@leftclickben
leftclickben / sloc-by-extension
Created October 12, 2020 06:31
Source analytics
#!/bin/bash
set -u
# usage example to find all Java source files: ./sloc-by-extension java
EXTENSION="${1}"
for dir in $(ls -d */); do
pushd ${dir} >/dev/null
LIST=$(find . -name "*.${EXTENSION}" | grep -iv test)
@leftclickben
leftclickben / experiment-gist-as-a-blogging-platform.md
Last active November 13, 2019 11:02
Experiment: gist as a blogging platform

Experiment: gist as a blogging platform

Am I crazy? Perhaps. But why shouldn't we use gist as a blogging platform?

What it has going for it

  • support for comments
  • renders markdown
  • support for multiple files, so code examples can be attached as well as inline
  • automatic indexing by search engines
@leftclickben
leftclickben / ubuntu-node-setup-5.x
Created January 22, 2016 16:42
Complete instructions for installing node 5.x on Ubuntu via apt (should work for other versions, just change `5.x`)
#!/bin/bash
curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -
sudo apt-get install nodejs
sudo chown -R $USER /usr/lib/node_modules/
sudo chgrp $USER /usr/bin
sudo chmod g+w /usr/bin
@leftclickben
leftclickben / git-update
Last active July 29, 2016 05:55
Pull down latest from git remote and remove dead branches
#!/bin/bash
#
# git-update
# Pull down latest from git remote and remove dead branches
#
# To create an alias to `git update`, put this on your path, then:
# git config --global alias.update '!git-update'
#
# Copyright (c) 2016 Leftclick.com.au
# License: MIT
@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;
@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 / 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 / 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 / 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 / test-ldap-2.php
Last active October 11, 2021 13:01
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]