Skip to content

Instantly share code, notes, and snippets.

View bezhermoso's full-sized avatar

Bez Hermoso bezhermoso

View GitHub Profile
function jump-to-git-root {
local _root_dir="$(git rev-parse --show-toplevel 2>/dev/null)"
if [[ $? -gt 0 ]]; then
>&2 echo 'Not a Git repo!'
exit 1
fi
local _pwd=$(pwd)
if [[ $_pwd = $_root_dir ]]; then
# Handle submodules:
# If parent dir is also managed under Git then we are in a submodule.
# Mnemonic: `gr` == `git root`
# IMPORTANT: Use single-quotes. Otherwise, the sub-command will expand *now* at definition!
alias gr='cd $(git rev-parse --show-toplevel)'
@bezhermoso
bezhermoso / brew-inventory.sh
Last active August 20, 2018 22:59
Create an inventory of installed Homebrew formulae, preserving flags
#!/usr/bin/env bash
brew list | while read formula; do
command="brew install $formula"
flags="$(brew info $formula | grep -i "built from source .* with:" | cut -f 11- -d' ')"
echo $command $flags
done
# Usage:
# ./brew-inventory.sh >! brew-formulae.txt
@bezhermoso
bezhermoso / csvjson-readline.js
Created August 2, 2016 23:40
Parse CSV rows as objects, line-by-line.
"use strict";
const readline = require('readline');
const EventEmitter = require('events');
const dataPattern = /^['"|](.*)['"|]$/;
const trimData = function (str) {
return String(str).trim().replace(dataPattern, '$1');
}

Keybase proof

I hereby claim:

  • I am bezhermoso on github.
  • I am bez (https://keybase.io/bez) on keybase.
  • I have a public key whose fingerprint is 029D BA21 BA36 3EF3 50C5 E6F6 55BD EC09 7B88 5413

To claim this, I am signing this object:

@bezhermoso
bezhermoso / calctime.sh
Last active July 13, 2016 18:52
Calculate time duration in bash (only for OS X's `date`. Probably won't work with out UNIX/Linux distros)
#!/usr/bin/env bash
# Usage: `calctime <start> <end>` i.e. `calctime 08:20 11:22`.
# Will prompt for start time and end time if not provided.
# DON'T specify AM or PM. Support is still @todo.
# However, this will try its best to guess the proper duration i.e. `calctime 08:00 1:00` will print out `Duration: 5 hours`.
from=$1
to=$2

Keybase proof

I hereby claim:

  • I am bezhermoso on github.
  • I am bez (https://keybase.io/bez) on keybase.
  • I have a public key ASASRjyDVyw16RGnhaRKrWI-U_UGrMgVJpbz2tnIc4S78go

To claim this, I am signing this object:

diff --git a/core/lib/Drupal/Core/Routing/UrlGenerator.php b/core/lib/Drupal/Core/Routing/UrlGenerator.php
index 9979b73..3dce650 100644
--- a/core/lib/Drupal/Core/Routing/UrlGenerator.php
+++ b/core/lib/Drupal/Core/Routing/UrlGenerator.php
@@ -340,7 +340,10 @@ public function generateFromRoute($name, $parameters = array(), $options = array
$base_url = $this->context->getBaseUrl();
$absolute = !empty($options['absolute']);
- if (!$absolute || !$host = $this->context->getHost()) {
+
@bezhermoso
bezhermoso / notification-actions.applescript
Last active February 11, 2023 09:54
Handly AppleScripts to manage OS X notifications. (Use in Automator, bind to keyboard shortcuts via BetterTouchTool, etc.) Inspired by http://apple.stackexchange.com/a/155736
# Close all notifications
my closeNotifications()
on closeNotifications()
tell application "System Events" to tell process "Notification Center"
set theWindows to every window
repeat with i from 1 to number of items in theWindows
set this_item to item i of theWindows
try
click button 1 of this_item
@bezhermoso
bezhermoso / notification-actions.applescript
Created January 15, 2016 16:29
Handly AppleScripts to manage OS X notifications. (Use in Automator, bind to keyboard shortcuts via BetterTouchTool, etc.) Inspired by http://apple.stackexchange.com/a/155736
my closeNotifications()
on closeNotifications()
tell application "System Events"
tell process "Notification Center"
set theWindows to every window
repeat with i from 1 to number of items in theWindows
set this_item to item i of theWindows
try
click button 1 of this_item