Skip to content

Instantly share code, notes, and snippets.

View bbody's full-sized avatar
⌨️
Smashing out mad code

Brendon Body bbody

⌨️
Smashing out mad code
View GitHub Profile
@bbody
bbody / github_shortcuts.sh
Last active July 6, 2023 07:45
A few Git shortcuts I use
[alias]
# Lists local branches ordered by last commit date, showing the latest branches at the bottom
brrr = for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(color:red)%(objectname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'
# Amends staged items to current commit
extend = commit --no-edit --amend
# Shorthand for checkout
co = checkout
# Shorthand for checkout trunk, it will determine the main branch e.g. master or main, and check it out
cot = !git co `git cwt`
# Checks out a new branch, expects a name to follow
(
() => {
const jiraReference = window.prompt("JIRA Reference","");
if (!jiraReference) {
window.open('INSERT_JIRA_HOMEPAGE_HERE', "_blank");
} else {
window.open(`INSERT_JIRA_ROOT_HERE/browse/${jiraReference}`).focus();}
}
)()
@bbody
bbody / gist:5ed0766d3705db34683694756b4aac16
Created May 11, 2021 15:58
Get filenames recursively in a root directory
const getListOfFiles = function (directory) {
let files = [];
fs.readdirSync(directory).forEach(function(filename) {
const filePath = path.join(directory, filename);
const fileStatus = fs.lstatSync(filePath);
if (fileStatus.isFile()) {
// Check if image
'use strict';
/**
* @ngdoc directive
* @name portfolioApp.directive:socialMediaItem
* @description
* # socialMediaItem
*/
angular.module('portfolioApp')
.directive('socialMediaItem', function () {
@bbody
bbody / rails_dokku.sh
Last active January 12, 2019 14:20
Setting up a Rails site on Dokku
APP_NAME=$1 # "app_name"
URL=$2 # "appname.example.com"
RAILS_BUILDPACK="https://github.com/heroku/heroku-buildpack-ruby.git#v142"
dokku apps:create $APP_NAME
dokku config:set $APP_NAME BUILDPACK_URL=$RAILS_BUILDPACK
# Assumes PostGres sudo dokku plugin:install https://github.com/dokku/dokku-postgres.git if not installed already
dokku postgres:create $APP_NAME
dokku postgres:link $APP_NAME $APP_NAME
@bbody
bbody / jest.config.js
Last active January 8, 2019 16:05
Schema Compare
// jest.config.js
module.exports = {
verbose: true,
};
@bbody
bbody / video_to_gif.sh
Created December 22, 2018 08:41
Video to GIF with colour optimization
#!/bin/sh
# Arguments:
# First argument: input file
# -ss: start time [optional]
# -t: end time [optional]
# Example usage:
# ./video_to_gif.sh input_file.mov
# ./video_to_gif.sh input_file.mov -ss 1.00
@bbody
bbody / compare_images.sh
Created May 15, 2018 03:58
Compares two folders of files and outputs diffs (if any) to a folder called diffs
# compare_images.sh
# Requires imagemagick `brew update && brew install imagemagick`
for entry in "$1"/*
do
if [ -f "$entry" ];then
NAME=`basename "$entry"`
DIFF=`compare -metric AE "$1/$NAME" "$2/$NAME" null: 2>&1`;
if [ "${DIFF}" -eq "0" ]; then
@bbody
bbody / db.rake
Last active April 1, 2018 02:14
Useful rake task to restart database from scrap for Rails applications, do not use in production
# lib/tasks/db.rake
namespace :db do
desc 'Drop, create, migrate then seed the development database'
task reseed: [ 'db:drop', 'db:create', 'db:migrate', 'db:seed' ] do
puts 'Reseeding completed.'
end
end
@bbody
bbody / addition_parser_test.py
Last active February 15, 2016 09:48
Test suite for a string addition parser for a TDD video
import unittest
def calculate_addition_string(expression):
numbers = expression.split('+')
total = 0
for number in numbers:
total += int(number)
return total
class TestAdditionMethods(unittest.TestCase):