Skip to content

Instantly share code, notes, and snippets.

View hultberg's full-sized avatar

Edvin Hultberg hultberg

View GitHub Profile
@hultberg
hultberg / uri.js
Created August 25, 2014 09:09 — forked from jlong/uri.js
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
@hultberg
hultberg / gist:618af91e2645973b190e
Last active August 29, 2015 14:19
Git: Total stats of an author using gawk
git log --author="[NAME]" --pretty=tformat: --numstat \
| gawk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s removed lines: %s total lines: %s\n", add, subs, loc }' -
@hultberg
hultberg / gist:f6761dca45b4dbefd32e
Created April 23, 2015 07:49
Git: Total stats of an author using awk
git log --author="_Your_Name_Here_" --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf "added lines: %s, removed lines: %s, total lines: %s\n", add, subs, loc }' -
@hultberg
hultberg / bash_prompt.sh
Last active September 22, 2015 08:39 — forked from insin/bash_prompt.sh
Set color bash prompt according to active virtualenv, git branch and return status of last command.
#!/bin/bash
#
# DESCRIPTION:
#
# Set the bash prompt according to:
# * the active virtualenv
# * the branch/status of the current git repository
# * the return value of the previous command
# * the fact you just came from Windows and are used to having newlines in
# your prompts.
@hultberg
hultberg / gist:7dc43332a0d3a1d681de4ab86000ea4b
Created April 12, 2016 07:54 — forked from ryanuber/gist:9014174
Vagrant re-import box from files on local system

If you find that vagrant box list somehow does not contain a box you previously had, you can sometimes add the box back if you still have the sources for it in ~/.vagrant.d/boxes.

$ cd ~/.vagrant.d/boxes/precise64/0/virtualbox/
$ tar czf ~/precise64.box .
$ vagrant box add precise64 ~/precise64.box 
Downloading box from URL: file:/Users/ryanuber/precise64.box
Extracting box...te: 417M/s, Estimated time remaining: --:--:--)
Successfully added box 'precise64' with provider 'virtualbox'!
@hultberg
hultberg / helpers.php
Created April 18, 2016 18:00 — forked from mabasic/helpers.php
config_path function for Lumen framework
<?php
if ( ! function_exists('config_path'))
{
/**
* Get the configuration path.
*
* @param string $path
* @return string
*/
@hultberg
hultberg / purge.sh
Created May 9, 2016 08:58 — forked from adrienbrault/purge.sh
Script to reduce VM size before packaging for vagrant
#!/usr/bin/env bash
# Credits to:
# - http://vstone.eu/reducing-vagrant-box-size/
# - https://github.com/mitchellh/vagrant/issues/343
aptitude -y purge ri
aptitude -y purge installation-report landscape-common wireless-tools wpasupplicant ubuntu-serverguide
aptitude -y purge python-dbus libnl1 python-smartpm python-twisted-core libiw30
aptitude -y purge python-twisted-bin libdbus-glib-1-2 python-pexpect python-pycurl python-serial python-gobject python-pam python-openssl libffi5
@hultberg
hultberg / post-merge
Last active April 21, 2017 05:37 — forked from sindresorhus/post-merge
git hook to run a command after `git pull` if a specified file was changed.In this example it's used to run `npm install` if package.json changed and `bower install` if `bower.json` changed.Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.
#/usr/bin/env bash
# MIT © Sindre Sorhus - sindresorhus.com
# git hook to run a command after `git pull` if a specified file was changed
# Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`.
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
check_run() {
echo "$changed_files" | grep --quiet "$1" && eval "$2"
<?php
function compile($data) {
// Compile variables:
// var = $value
//
// into:
// $var = $value
@hultberg
hultberg / convert.sh
Created May 14, 2017 13:44
Convert .ogg to .mp3
#!/usr/bin/env bash
# Convert all .ogg files in current folder to mp3, and move the original .ogg file into own folder named "ogg".
# Stop on error (-e).
# Debug each command (-x).
set -ex
# Make sure there is a ogg folder available.
if [[ ! -d "ogg" ]]; then
mkdir ogg