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
View configure-apache-environment-variable-on-macosx.md

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
[CmdletBinding()]
param (
[Parameter(Mandatory=$True)]
[string]$grep_pattern,
[Parameter(Mandatory=$True)]
[string]$glob_pattern,
[Parameter(Mandatory=$False)]
[string]$path
@vegarbg
vegarbg / set_selinux_ez_policies.sh
Last active Aug 29, 2015
Set correct SELinux labels and booleans for eZ Publish. Works with eZ Community 2014.07.
View set_selinux_ez_policies.sh
#!/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
@vegarbg
vegarbg / safeResult.py
Last active Aug 29, 2015
Returns the result of fn(kwargs), or if there are exceptions, returns alternative instead.
View safeResult.py
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
@vegarbg
vegarbg / modernizr-rem.coffee
Last active Aug 29, 2015
Modernizr test for availability of root ems (rem) sizing.
View modernizr-rem.coffee
Modernizr.addTest "rem", ->
elem = document.createElement "div"
elem.setAttribute "style", "font-size: 1rem"
return elem.style.fontSize == "1rem"
@vegarbg
vegarbg / inline-block-whitespace-fix.css
Last active Aug 29, 2015
Example of inline-block with whitespace fix. Demo at http://jsfiddle.net/vegarg/G2W5M/
View inline-block-whitespace-fix.css
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;
@vegarbg
vegarbg / logging.conf
Created May 13, 2014
Example of using the Python logging library.
View logging.conf
[loggers]
keys=root
[handlers]
keys=consoleHandler,fileHandler
[formatters]
keys=simpleFormatter
[logger_root]
@vegarbg
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
vegarbg / filegrep.py
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.
View filegrep.py
#!/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
vegarbg / generate_storage_report.sh
Last active Dec 23, 2015
A shell script that generates a simple report of hard drive usage.
View generate_storage_report.sh
#!/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}
You can’t perform that action at this time.