Skip to content

Instantly share code, notes, and snippets.

Avatar

Michael Benford mbenford

View GitHub Profile
@mbenford
mbenford / vpn.sh
Created Apr 8, 2020
Starts or stops a VPN connection
View vpn.sh
#!/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 Jul 15, 2019
Git custom command that moves all commits between @{u} and HEAD into a new branch and deletes them from the current branch
View git-cut-branch.sh
#!/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
View keybase.md

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 / spring-cleaning.js
Last active Apr 17, 2017
ngTagsInput spring cleaning script
View spring-cleaning.js
const path = require('path');
const GitHubApi = require('github');
const jsonfile = require('jsonfile');
const moment = require('moment');
const async = require('async');
const config = require('./config.json');
const github = new GitHubApi({ protocol: 'https' });
github.authenticate({ type: 'oauth', token: config.token });
View MappingExtensions.cs
public static class MappingExtensions
{
public static void Unflatten<T>(this IMemberConfigurationExpression<T> config)
{
config.ResolveUsing(resolutionResult =>
{
var context = resolutionResult.Context;
var prefix = context.MemberName;
var destProperties = context.DestinationType.GetProperties();
var dest = Activator.CreateInstance(context.DestinationType);
@mbenford
mbenford / .bash_aliases
Last active Aug 29, 2015
My .bashrc file
View .bash_aliases
alias la="ls -a"
alias psa="ps aux"
@mbenford
mbenford / get-permutations.js
Created Apr 30, 2015
Generate all permutations of the given set
View get-permutations.js
function getPermutations(set) {
var result = [];
permutate(set);
return result;
function permutate(set, subset) {
if (!subset) subset = [];
if (set && !set.length) {
result.push(subset);
return;
@mbenford
mbenford / get-permutations.cs
Last active Dec 9, 2020
Generates all permutations of a set by using LINQ and a recursive approach
View get-permutations.cs
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 / bit-manipulation.js
Created Apr 15, 2015
Bit manipulation in Javascript
View bit-manipulation.js
function setBitOn(number, bit) {
return number | 1 << bit;
}
function setBitOff(number, bit) {
return number & ~(1 << bit);
}
function toggleBit(number, bit) {
return number ^ 1 << bit;
@mbenford
mbenford / mergesort.js
Created Apr 14, 2015
Merge sort in Javascript
View mergesort.js
function mergesort(array) {
return sort(array, 0, array.length - 1);
function sort(array, start, end) {
if (start === end) return [array[start]];
var middle = Math.floor((start + end) / 2);
return merge(sort(array, start, middle), sort(array, middle + 1, end));
}