Skip to content

Instantly share code, notes, and snippets.

Vegar Guldal vegarbg

Block or report user

Report or block vegarbg

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile

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):

View filegrep.ps1
param (
vegarbg /
Last active Aug 29, 2015
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."
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(/.*)?"
vegarbg /
Last active Aug 29, 2015
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
result = fn( kwargs )
except expectedError:
return result
vegarbg /
Last active Aug 29, 2015
Modernizr test for availability of root ems (rem) sizing.
Modernizr.addTest "rem", ->
elem = document.createElement "div"
elem.setAttribute "style", "font-size: 1rem"
return == "1rem"
vegarbg / inline-block-whitespace-fix.css
Last active Aug 29, 2015
Example of inline-block with whitespace fix. Demo at
View inline-block-whitespace-fix.css
ul {
/* Fix for inline-block whitespace issue. Source: */
letter-spacing: -4px;
word-spacing: -4px;
li {
background-color: lightgray;
display: inline-block;
height: 75px;
vegarbg / logging.conf
Created May 13, 2014
Example of using the Python logging library.
View logging.conf
vegarbg / load-utf8-html-into-dom.php
Last active Dec 30, 2015
How to load a UTF-8 HTML document into the PHP DOM.
View load-utf8-html-into-dom.php
$dom = new DOMDocument('1.0', 'utf-8');
@$dom->loadHTML( mb_convert_encoding($htmldoc, 'HTML-ENTITIES', 'UTF-8') );
$x = new DOMXPath($dom);
vegarbg /
Last active Dec 29, 2015
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)
vegarbg /
Last active Dec 23, 2015
A shell script that generates a simple report of hard drive usage.
CURRENT_DATETIME=`date "+%Y%m%d_%H%M%S_%z" | sed -e "s/+//"`
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}
You can’t perform that action at this time.