Skip to content

Instantly share code, notes, and snippets.

View chales's full-sized avatar

Chris Hales chales

View GitHub Profile
#!/bin/sh
#
# This script will hold your hand during the process of converting an existing Drupal 7 file field from public to private.
#
# http://twitter.com/thsutton
# http://www.linkedin.com/pub/thomas-sutton/55/391/350
# http://thomas-sutton.id.au/
set -eu
@chales
chales / cors-apache.cfg
Created April 22, 2015 05:42
Apache directive for a CORS to be used in a vhost or htaccess
<IfModule mod_headers.c>
# Enter possible domains and a cathcall regex for the subdomain.
SetEnvIf Origin "^http(s)?://(.+\.)?(domain1\.com|domain2\.com|domain3\.com)$" AllowOrigin=$0
Header always set Access-Control-Allow-Origin "%{AllowOrigin}e" env=AllowOrigin
Header merge Vary "Origin"
Header always append Access-Control-Max-Age "1000"
Header always append Access-Control-Allow-Headers "X-Requested-With, Content-Type, Origin, Authorization, Accept, Accept-Encoding, \
if-modified-since, pragma, cache-control"
Header always set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT"

I just had to set up Jenkins to use GitHub. My notes (to myself, mostly):

Detailed Instructions

For setting up Jenkins to build GitHub projects. This assumes some ability to manage Jenkins, use the command line, set up a utility LDAP account, etc. Please share or improve this Gist as needed.

Install Jenkins Plugins

grep {
type => "syslog"
match => [ "syslog_program", "drupal" ]
add_tag => "Drupal"
drop => false
}
grok {
type => "syslog"
tags => [ "Drupal" ]
match => [ "@message", "^https?://%{HOSTNAME:drupal_vhost}\|%{NUMBER:drupal_timestamp}\|(?<drupal_action>[^\|]*)\|%{IP:drupal_ip}\|(?<drupal_request_uri>[^\|]*)\|(?<drupal_referer>[^\|]*)\|(?<drupal_uid>[^\|]*)\|(?<drupal_link>[^\|]*)\|(?<drupal_message>.*)" ]
@chales
chales / pre-push
Created June 23, 2015 22:23
Git pre-push hook used to prevent force pushes
#!/bin/bash
# Prevents force-pushing to proceted branches
CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD`
PROTECTED_BRANCHES="^(develop|master|release*)"
PUSH_COMMAND=`ps -ocommand= -p $PPID`
FORCE_OPTION="delete|force|-f"
if [[ "$CURRENT_BRANCH" =~ $PROTECTED_BRANCHES && "$PUSH_COMMAND" =~ $FORCE_OPTION ]]; then
echo "Prevented force-push to protected branch '$CURRENT_BRANCH'!"
@chales
chales / sed cheatsheet
Last active January 3, 2023 13:57 — forked from un33k/sed cheatsheet
magic of sed -- find and replace "text" in a string or a file
FILE SPACING:
# double space a file
sed G
# double space a file which already has blank lines in it. Output file
# should contain no more than one blank line between lines of text.
sed '/^$/d;G'
@chales
chales / README.md
Last active July 25, 2021 05:38
Helper bash functions to retrieve info and login to AWS EC2 instances.

You must install the AWS CLI to use these functions. You also have to have access keys to AWS and permission to access instance information.

The AWS CLI install is usually painless, see http://docs.aws.amazon.com/cli/latest/userguide/installing.html

sudo easy_install pip

sudo pip install awscli

After install run the setup to set your configuration options which includes the default region and your access keys.

@chales
chales / bbedit-pretty-json-readme.txt
Last active March 7, 2025 11:24
Make JSON legible with BBEdit
2016/03/15
Tested with BBEdit 11.5 / OS X 10.11.3 / Python 2.7.10
http://grokin.gs/blog/elegant-json-pretty-print-for-bbedit/
Place the script (or a link to this script) in the ~/Library/Application Support/BBEdit/Text Filters directory
Restart BBEdit.
The new filter should be under: "Test > Apply Text Filter > bbedit-pretty-json"
@chales
chales / docker-machine-rename
Created April 5, 2016 12:26 — forked from alexproca/docker-machine-rename
Rename docker-machine
#!/usr/bin/env bash
#copy this in a folder from path ex: /usr/local/bin
#usage: docker-machine-rename default my-default
OLD_MACHINE_NAME=${1:-default};
NEW_MACHINE_NAME=${2:-my-default-2};
STORE_PATH=`docker-machine inspect $OLD_MACHINE_NAME | grep -m 1 StorePath | cut -d ':' -f 2 | cut -c 3- | rev | cut -c 3- | rev`;
mv "$STORE_PATH/machines/$OLD_MACHINE_NAME" "$STORE_PATH/machines/$NEW_MACHINE_NAME";
cp "$STORE_PATH/machines/$NEW_MACHINE_NAME/config.json" "$STORE_PATH/machines/$NEW_MACHINE_NAME/config.json.bak"
@chales
chales / pedantically_commented_playbook.yml
Created May 27, 2016 13:54 — forked from marktheunissen/pedantically_commented_playbook.yml
Insanely complete Ansible playbook, showing off all the options
---
# ^^^ YAML documents must begin with the document separator "---"
#
#### Example docblock, I like to put a descriptive comment at the top of my
#### playbooks.
#
# Overview: Playbook to bootstrap a new host for configuration management.
# Applies to: production
# Description:
# Ensures that a host is configured for management with Ansible.