Skip to content

Instantly share code, notes, and snippets.

@thomseddon
thomseddon / mkcrt.sh
Created December 18, 2013 20:21
SSL walkthrough for nginx
#!/bin/bash
# Copyright 2013-present Thom Seddon
if [ "$1" == "" ]; then
echo "Usage: sudo ./mkcrt <hostname>"
exit 1
fi
if [ "$(id -u)" != "0" ]; then
echo "Must run with sudo"
@thomseddon
thomseddon / git_deploy.sh
Last active December 29, 2015 10:09
Create a git deployment folder on a remote machine
#!/bin/bash
# Read vars
if [ "$1" == "" ]; then
echo "Usage: ./git_deploy <folder> <user?> <post-receive?>"
exit 1
fi
folder=$1
if [ -d "$folder" ]; then
@thomseddon
thomseddon / install
Last active December 27, 2015 18:19
Install node.js on linux
#!/bin/bash
# Get the latest version no.
version=$(wget --quiet --output-document - \
http://nodejs.org/dist/latest/SHASUMS.txt |
head --lines 1 |
cut --fields 3 --delimiter " " |
cut --fields 2 --delimiter "-")
name=node-$version-linux-x64
@thomseddon
thomseddon / SoftDeleteBehavior.php
Last active December 26, 2015 12:39
CakePHP Soft Delete Behaviour
<?php
App::uses('ModelBehavior', 'Model');
class SoftDeleteBehavior extends ModelBehavior {
public function setup(Model $Model, $settings = array()) {
$field = isset($settings['field']) ? $settings['field'] : 'is_deleted';
$this->settings[$Model->alias]['field'] = $field;
}
@thomseddon
thomseddon / format.sh
Last active December 23, 2015 04:29
Reformat cakephp templates (generated with bake) to bootstrap style using sed
# Remove "actions" divs
find View/ -name "*.ctp" -exec sed -i ':a;N;$!ba;s/<div class="actions">\(.*\)<\/div>//g' '{}' \;
# Add "table" class to tables
find View/ -name "*.ctp" -exec sed -i "s/<table\(.*\)/<table class=\"table table-striped\">/g" '{}' \;
# Add btn classes to buttons
find View/ -name "*.ctp" -exec sed -i "s/view\(.*\))/view\1, array('class' => 'btn btn-default'))/g" '{}' \;
find View/ -name "*.ctp" -exec sed -i "s/edit\(.*\))/edit\1, array('class' => 'btn btn-info'))/g" '{}' \;
find View/ -name "*.ctp" -exec sed -i "s/delete\(.*\), null/delete\1, array('class' => 'btn btn-danger')/g" '{}' \;
@thomseddon
thomseddon / gist:5511325
Last active December 16, 2015 22:59
Connect sessions only on certain routes
var session = express.session();
// Slightly Invasive
app.get('/home', session, routes.home);
app.get('/about', routes.about);
app.get('/faq', routes.faq);
// or
// Crude
#!/usr/bin/env bash
set -e
set -x
### How To Use
#
# sudo bash -c 'bash \
# <(curl -sLB https://raw.github.com/gist/5080906/bootstrap_chef_server_rpm.sh) \
# --hostname foo.example.com'
#
@thomseddon
thomseddon / gist:4703968
Last active October 21, 2020 08:50
Auto Expanding/Grow textarea directive for AngularJS
/**
* The MIT License (MIT)
*
* Copyright (c) 2013 Thom Seddon
* Copyright (c) 2010 Google
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@thomseddon
thomseddon / gist:4703810
Last active December 27, 2016 02:58 — forked from nobuf/gist:3419910
Supporting placeholder on IE9 with AngularJS (without jQuery) > Removed jQuery dependency > Slight optimisation in retrieving placeholder text
angular.module('test', [])
.directive('placeholder', function($timeout){
var i = document.createElement('input');
if ('placeholder' in i) {
return {}
}
return {
link: function(scope, elm, attrs){
if (attrs.type === 'password') {
return;
@thomseddon
thomseddon / gitclean.sh
Last active December 11, 2015 23:28
Simple bash script to clean MULTIPLE unwanted files out of a git repo
#!/bin/bash
#
# Usage: ./gitclean.sh <branch> <path-to-match>
# Requires clean working tree (i.e. delete files in <path> and commit)
#
# Thom Seddon <thom@seddonmedia.co.uk>
git ls-tree --name-only -r $1 $2 | while read FILE; do
git filter-branch --index-filter "git rm --cached ${FILE}" HEAD
done