Skip to content

Instantly share code, notes, and snippets.

View mbenford's full-sized avatar

Michael Benford mbenford

View GitHub Profile
@mbenford
mbenford / dbus-monitor.py
Created June 13, 2021 22:37
Monitoring DBus with dbus-next
from dbus_next.aio import MessageBus
from dbus_next.message import Message
from dbus_next.constants import BusType
import asyncio
async def main():
match = (
"type='method_call',"
"interface='org.freedesktop.PowerManagement.Inhibit',"
"path='/org/freedesktop/PowerManagement/Inhibit'"
@mbenford
mbenford / git-update.sh
Last active August 17, 2022 09:53
Bash script to update a local copy of a Git repository with latest changes from a remote branch
#!/bin/bash
set -e
local_branch=$(git rev-parse --symbolic-full-name --abbrev-ref HEAD)
remote_branch=$(git rev-parse --abbrev-ref --symbolic-full-name @{u})
remote=$(git config branch.$local_branch.remote)
echo "Fetching from $remote..."
git fetch $remote
@mbenford
mbenford / git-checkout-release.sh
Created October 20, 2014 19:07
Bash script to checkout either the latest release branch or the one specified
#!/bin/bash
set -e
if [ "$1" != "" ]; then
release_name="release/$1"
else
release_name=$(git branch -r | tail -n1 | sed 's/.*origin\///')
fi
echo "Checking out branch '$release_name'..."
@mbenford
mbenford / get-permutations.cs
Last active October 21, 2021 15:01
Generates all permutations of a set by using LINQ and a recursive approach
public static class Permutations
{
public static IEnumerable<IEnumerable<T>> Get<T>(IEnumerable<T> set, IEnumerable<T> subset = null)
{
if (subset == null) subset = new T[] { };
if (!set.Any()) yield return subset;
for (var i = 0; i < set.Count(); i++)
{
var newSubset = set.Take(i).Concat(set.Skip(i + 1));
@mbenford
mbenford / demo.html
Last active September 30, 2020 16:17
Angular directive that binds attributes without relying on interpolation
<input type="text" ng-bind-attrs="{placeholder: somePropertyOfTheScope, tabindex: anotherPropertyOfTheScope}" >
@mbenford
mbenford / vpn.sh
Created April 8, 2020 03:10
Starts or stops a VPN connection
#!/bin/bash
set -e
conn_id=$(nmcli conn show | grep vpn | awk '{print $2}' | head -n1)
if [ "$conn_id" == "" ]; then
echo "no VPN connection was found"
exit 1
fi
@mbenford
mbenford / git-cut-branch.sh
Created July 15, 2019 17:51
Git custom command that moves all commits between @{u} and HEAD into a new branch and deletes them from the current branch
#!/bin/bash
# Moves all commits between @{u} and HEAD into a new branch
# and deletes them from the current branch.
#
# Copyright (c) 2019 Michael Benford <michael@michaelbenford.net>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
@mbenford
mbenford / autosize.js
Created December 18, 2013 03:47
Autosize directive for AngularJS. Resizes an input field automatically so its content is always visible. http://plnkr.co/edit/iodg4SqKBXL0V6ZJmRue
app.directive('autosize', function($document) {
return {
require: 'ngModel',
link: function(scope, element, attrs, ctrl) {
var placeholder, span, resize;
placeholder = element.attr('placeholder') || '';
span = angular.element('<span></span>');
span[0].style.cssText = getComputedStyle(element[0]).cssText;

Keybase proof

I hereby claim:

  • I am mbenford on github.
  • I am mbenford (https://keybase.io/mbenford) on keybase.
  • I have a public key ASBo0WcLt6b2Gjuq4tG-go7Ez0_bPJq3kNUA28QoKK1bPQo

To claim this, I am signing this object:

@mbenford
mbenford / DeployToOctopus.ps1
Created August 10, 2014 19:28
Powershell script for TeamCity that creates and deploys a release on Octopus Deploy based on the current branch
function Is-Default-Branch {
return "%teamcity.build.branch.is_default%" -eq "true"
}
function Build-Arguments {
if (Is-Default-Branch) {
$releaseNumber = "%octopus.master.releaseNumber%"
$deployTo = "%octopus.master.deployTo%"
$packageVersion = "%octopus.master.packageVersion%"
}