Skip to content

Instantly share code, notes, and snippets.

Configure Apache Environment Variable on Mac OS

  1. Restart the computer in Recovery mode (hold down Cmd-R). Open Terminal and run:

     $ csrutil disable
    
  2. Restart the computer normally.

  3. Edit the Apache2 plist file with whatever editor you like (example using vim):

[CmdletBinding()]
param (
[Parameter(Mandatory=$True)]
[string]$grep_pattern,
[Parameter(Mandatory=$True)]
[string]$glob_pattern,
[Parameter(Mandatory=$False)]
[string]$path
@starlightsys
starlightsys / set_selinux_ez_policies.sh
Last active August 29, 2015 14:16
Set correct SELinux labels and booleans for eZ Publish. Works with eZ Community 2014.07.
#!/bin/bash -x
if [ "$EUID" -ne 0 ]
then echo "Must be run as root."
exit
fi
setsebool -P httpd_anon_write 1
setsebool -P httpd_sys_script_anon_write 1
for d in $(echo "ezpublish/cache,ezpublish/logs,ezpublish/config,ezpublish_legacy/design,ezpublish_legacy/extension,ezpublish_legacy/settings,ezpublish_legacy/var,web" | tr "," "\n"); do
semanage fcontext -a -t public_content_rw_t "/var/www/html/ez/$d(/.*)?"
done
@starlightsys
starlightsys / safeResult.py
Last active August 29, 2015 14:06
Returns the result of fn(kwargs), or if there are exceptions, returns alternative instead.
def safeResult(fn, expectedError = Exception, alternative = None, **kwargs):
"""Returns the result of fn(kwargs), or if there are exceptions, returns alternative instead."""
result = alternative
try:
result = fn( kwargs )
except expectedError:
pass
return result
@starlightsys
starlightsys / modernizr-rem.coffee
Last active August 29, 2015 14:03
Modernizr test for availability of root ems (rem) sizing.
Modernizr.addTest "rem", ->
elem = document.createElement "div"
elem.setAttribute "style", "font-size: 1rem"
return elem.style.fontSize == "1rem"
@starlightsys
starlightsys / inline-block-whitespace-fix.css
Last active August 29, 2015 14:03
Example of inline-block with whitespace fix. Demo at http://jsfiddle.net/vegarg/G2W5M/
ul {
/* Fix for inline-block whitespace issue. Source: http://www.lifeathighroad.com/web-development/css-web-development/inline-block-whitespace-workaround/ */
letter-spacing: -4px;
word-spacing: -4px;
}
li {
background-color: lightgray;
display: inline-block;
height: 75px;
@starlightsys
starlightsys / logging.conf
Created May 13, 2014 11:18
Example of using the Python logging library.
[loggers]
keys=root
[handlers]
keys=consoleHandler,fileHandler
[formatters]
keys=simpleFormatter
[logger_root]
@starlightsys
starlightsys / load-utf8-html-into-dom.php
Last active December 30, 2015 06:29
How to load a UTF-8 HTML document into the PHP DOM.
<?
$dom = new DOMDocument('1.0', 'utf-8');
@$dom->loadHTML( mb_convert_encoding($htmldoc, 'HTML-ENTITIES', 'UTF-8') );
$x = new DOMXPath($dom);
@starlightsys
starlightsys / filegrep.py
Last active December 29, 2015 10:29
Quick script that ties together find and grep so you can search through file contents. Uses Python because I was already familiar with argparse.Much of the length and inelegance of the script is because I wanted to preserve colored output through the pipe.
#!/usr/bin/env python
import argparse, subprocess
parser = argparse.ArgumentParser()
parser.add_argument("file_glob", help="a quoted string to use when globbing for files; example: \"*.py\"")
parser.add_argument("search_string", help="the string to search for in the files")
args = parser.parse_args()
find = subprocess.Popen(["find", ".", "-type", "f", "-name", args.file_glob, "-print0"], stdout=subprocess.PIPE)
@starlightsys
starlightsys / generate_storage_report.sh
Last active December 23, 2015 10:59
A shell script that generates a simple report of hard drive usage.
#!/bin/sh
CURRENT_DATETIME=`date "+%Y%m%d_%H%M%S_%z" | sed -e "s/+//"`
REPORTFILE="${CURRENT_DATETIME}_storage_report.txt"
echo "Generating file ${REPORTFILE} ..."
echo "Storage report for `date "+%Y-%m-%d %H:%M:%S %z"`" > ${REPORTFILE}
echo "========================================================================" >> ${REPORTFILE}
# If you have sort version 8.17 or newer, use the following code:
find . -mindepth 1 -maxdepth 1 -print0 | xargs -0 du -hs | sort -hr >> ${REPORTFILE}
# If you have an older version of sort, use this code instead:
# (find . -mindepth 1 -maxdepth 1 -print0 | xargs -0 du -sk) | sort -n | perl -ne '($s,$f)=split(m{\t});for (qw(K M G)) {if($s<1024) {printf("%.1f",$s);print "$_\t$f"; last};$s=$s/1024}' | tac >> ${REPORTFILE}