Skip to content

Instantly share code, notes, and snippets.

View cunneen's full-sized avatar

Mike Cunneen cunneen

  • Perth, Australia
View GitHub Profile
@cunneen
cunneen / check_constraints_mysql.sql
Created August 20, 2014 03:25
Mimicking Check Constraints in MySQL
-- Modified from: http://stackoverflow.com/a/14248038/956779
-- Add a BEFORE INSERT constraint that only allows values between 1 and 5
DELIMITER $$
CREATE TRIGGER `test_before_insert` BEFORE INSERT ON cheese_shop.items
FOR EACH ROW
BEGIN
IF (NEW.ratings > 5 OR NEW.ratings < 1) THEN
SIGNAL SQLSTATE '12345'
SET MESSAGE_TEXT = 'check constraint on items.ratings failed';
END IF;
@cunneen
cunneen / clean_windows_build.md
Last active August 29, 2015 14:06
How to create a clean Windows Build

How to create a clean windows build

  1. Install the operating system
  2. Install the service packs
  3. Apply updates from wsus offline
  4. Apply apps from ninite
  5. Apply third-party apps
  6. License keys should all be found/kept in lastpass
  7. Make a system image so you can do this quickly next time. Use Acronis TrueImage or Paragon Backup and Restore
@cunneen
cunneen / safeScale.js
Last active August 29, 2015 14:07
DO NOT USE THIS, IT HAS A BUG. Keeping it for illustration purposes. A little thing I knocked up to safely scale a javascript number using strings to avoid floating point issues. The bug is where the multipleOfTenAsNumber has more digits than the original number. It doesn't work in that case. E.g. console.log(safeScale("109.87654",10000000000));…
// if you try this in javascript:
// 10.2 * 100
// you get this:
// 1019.9999999999999
/** Safely scale a number. Just a hacky little demo.
* @param {string} numberAsString the number you want to scale e.g. 10.987654
* @param {number} multipleOfTenAsNumber the number you want to scale by e.g. 1000
* @returns {safeScale.result} the safely scaled number e.g. 10987.654
*/
function safeScale(numberAsString, multipleOfTenAsNumber) {
@cunneen
cunneen / fill_pdf_in_meteor.js
Created October 19, 2014 16:42
This is the rough outline of a regular (weekly) job that fills in a PDF form and will email it. There are 3 aspects: 1. [percolate studio's meteor cron](https://github.com/percolatestudio/meteor-synced-cron) 2. PDFtk installed 3. [meteor pdftk wrapper](https://github.com/pascoual/meteor-pdftk) The sample PDF with acrofields for this demo can be …
var meteor_root = Npm.require('fs').realpathSync(process.cwd() + '/../');
var application_root = Npm.require('fs').realpathSync(meteor_root + '/../');
// if running on dev mode
var fs = Npm.require('fs');
if (Npm.require('path').basename(fs.realpathSync(meteor_root + '/../../../')) == '.meteor') {
application_root = fs.realpathSync(meteor_root + '/../../../../');
}
var assets_folder = meteor_root + '/server/assets/';
@cunneen
cunneen / setup_moodle_on_ubuntu.sh
Last active March 29, 2021 09:58
Set up moodle on ubuntu server 14.04 (on amazon EC2 instance, should work with little or no modification on others). The database username/password will be moodle/mymoodlepassword123 .
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install apache2 mysql-client mysql-server php5
sudo apt-get install graphviz aspell php5-pspell php5-curl php5-gd php5-intl php5-mysql php5-xmlrpc php5-ldap clamav
sudo service apache2 restart
sudo apt-get install git-core
cd /opt
sudo git clone git://git.moodle.org/moodle.git
cd moodle/
sudo git branch --track MOODLE_28_STABLE
@cunneen
cunneen / replace_cordova_tarballs_with_npm.sh
Last active March 29, 2016 04:49
A very rough bash script to replace meteor cordova tarball URLs with a private NPM reference. Use together with sinopia.
#!/bin/bash
# Run this from the meteor application folder. It's assumed that the git root is somewhere
# ABOVE the meteor application folder. If your meteor application root *is* the git root,
# review this code very carefully as I've not tested it in such cases.
#
# It downloads all meteor cordova tarball and https plugins, and registers them
# with the npm registry. I use this with a private registry (sinopia).
# It then updates the meteor cordova plugin registry with a reference to the npm registry.
meteordir="`pwd`"
destfoldername="cordova-plugins"
@cunneen
cunneen / Readme.md
Last active January 23, 2024 11:17
Install Open GApps In Android Emulator

Introduction

This works to install Open GApps into the Android Emulator, working around the issue where the system partition is too small.

With it, I can get Google Play installing into the emulator. Tested on KitKat (API 19), Lollipop (API 21) and Oreo (API 27).

It's tested on MacOS.

Instructions

@cunneen
cunneen / makeicons.sh
Created August 13, 2018 03:03
Make a mac OS icns file from a single input file using imageMagick and iconutil
#!/usr/bin/env bash
infile=$1
if [ ! -f $infile ]; then
echo specify a filename as the first parameter.
exit 1;
fi
tempdir=$(mktemp --directory --suffix=.iconset --tmpdir=`pwd`)
@cunneen
cunneen / Frame android screenshots with ImageMagick.md
Last active December 27, 2021 16:36
Frame android screenshots with ImageMagick

Prerequisites

  1. A screenshot with the correct aspect ratio
  2. A device frame PNG with a transparent area where the screenshot will be placed See Facebook's Device Art
  3. GraphicsMagick / ImageMagick
  4. That's it.

Instructions

@cunneen
cunneen / create-new-react-native-project.sh
Last active October 19, 2021 13:49
Create a new react native app, specifying app name and package name
#!/usr/bin/env bash
# get the full path for the current dir
DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
###### prompt for values
# get the new app name
read -p "Enter your new app name [Foo App]: " NEW_APP_NAME
NEW_APP_NAME=${NEW_APP_NAME:-"Foo App"}