Skip to content

Instantly share code, notes, and snippets.

View Willshaw's full-sized avatar

Peter Williamson Willshaw

View GitHub Profile
@Willshaw
Willshaw / shellTrim.sh
Last active August 29, 2015 14:07
Shell script to create trimmed versions of a CSV. Trims the file to the number of lines supplied in the second input.
#!/bin/bash
#
#AUTHOR: Pete Williamson
#DATE: 2014-10-21
#
#USAGE:
# Creates smaller versions of supplied CSV file,
# based on the line number values as the second parameter
#
# The resulting CSVs are zipped up (for windows compatibility)
<cfscript>
lst = '';
cnt = 10000;
for( i = 1; i <= cnt; i++ ) {
val = randRange( 1, 5 );
lst = listAppend( lst, val );
}
@Willshaw
Willshaw / bash-grep-repos
Last active August 29, 2015 14:19
Bash Script to Git Grep a directory of repos
#!/bin/bash
#
# Supply 2 params from cmd, path to search and the term.
# The script will cd to $path, then check any directories
# it finds for the presence of a .git directory.
#
# If it finds a .git directory, a repo is assumed and
# a case insensitive grep is performed on term
#
# example:
@Willshaw
Willshaw / copyHooks.sh
Last active November 11, 2015 18:17
Copy hook into multiple repos
ls -la | awk '{print $9}' | grep -v comcar | egrep '^[a-z]' | while read -r line; do sed -e "s/myrepo/$line/" myrepo/hooks/post-receive > $line/hooks/post-receive; done
#
# Break down of the above command is below - don't try to run the bits
# on their own, you need to pipe the outputs between, like the example above
#
# List contentsfiles in current directory - full list view, row per file/folder
ls -la
# Only print the 9th column (folder name)
@Willshaw
Willshaw / fibonacci.php
Last active December 17, 2015 16:59
PHP Fibonacci number
<?
// array to store sequence - initialised with first 2 numbers
$nums = array(0,1);
// loop 20 times creating more numbers in the sequence
for($i = 1; $i <=20; $i++) {
$next = $nums[$i]+$nums[$i-1];
array_push($nums,$next);
}
@Willshaw
Willshaw / image-transparency-check.html
Last active January 14, 2016 10:02
Check the look of a transparent image on a coloured background - tested only in Chrome
<DOCTYPE !html>
<html>
<head>
<title>Quick image check</title>
<style>
* {
font-family: sans-serif;
}
#dropzone,
@Willshaw
Willshaw / download-files-push-to-s3
Last active April 12, 2016 11:31
Download a load of files from the web and push to an s3 bucket
#!/bin/bash
#
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# Version 2, December 2004
# Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
# Everyone is permitted to copy and distribute verbatim or modified
# copies of this license document, and changing it is allowed as long
# as the name is changed.
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
@Willshaw
Willshaw / coldfusion-datasource-setup
Created March 31, 2017 23:21
Simple Script for Local Development to setup coldfusion datasources
<cfscript>
writeOutput('starting db source installation...<br/ >');
function createDSN( name ) {
// Login is always required. This example uses two lines of code.
adminObj = createObject("component","cfide.adminapi.administrator");
adminObj.login("pete", "admin");
// Instantiate the data source object.
myObj = createObject("component","cfide.adminapi.datasource");
// Create a DSN.
@Willshaw
Willshaw / query-to-excel.cfm
Last active November 21, 2017 15:04
coldfusion query to excel
<cfscript>
obj_query = new core.utility.queryWrapper();
lst_columns = 'id,email';
lst_columns_for_sql = listQualify(lst_columns, "`" );
str_select = '
SELECT #lst_columns_for_sql#
FROM `allcars`.`users`
@Willshaw
Willshaw / example.sh
Created January 4, 2018 17:32
simple start to a bash script
#!/bin/bash
################################
# to use the tracker:
# call the track script, using the full path to the script
# and also give it an action string, and a script string
#
# $REPO_PATH"bin/track.sh" "completed thing" $REPO_PATH"task_one"
#
# /path/to/script/bin/track.sh "action that happened" "script/that/is/doing/things"