Skip to content

Instantly share code, notes, and snippets.

View jonathanconway's full-sized avatar
⌨️
Typing

Jonathan Conway jonathanconway

⌨️
Typing
View GitHub Profile
@jonathanconway
jonathanconway / .prettierrc
Created March 18, 2024 10:12
Handy sensible defaults for prettier including import ordering and grouping
{
"tabWidth": 2,
"useTabs": false,
"singleQuote": false,
"importOrder": ["^[@]?[a-zA-Z]", "^[@/a-zA-Z]", "^../", "^./"],
"importOrderSeparation": true,
"importOrderSortSpecifiers": true,
"plugins": ["@trivago/prettier-plugin-sort-imports"]
}
@jonathanconway
jonathanconway / TypeExtensions.IsSimpleType.cs
Created August 12, 2012 08:09
Determine whether a type is simple.
public static class TypeExtensions
{
/// <summary>
/// Determine whether a type is simple (String, Decimal, DateTime, etc)
/// or complex (i.e. custom class with public properties and methods).
/// </summary>
/// <see cref="http://stackoverflow.com/questions/2442534/how-to-test-if-type-is-primitive"/>
public static bool IsSimpleType(
this Type type)
{
@jonathanconway
jonathanconway / .gitconfig
Last active September 2, 2023 07:20
Useful Git aliases. Append this code to the .gitconfig file in your %USERPROFILE% folder.
[user]
name = Jonathan Conway
email = jonathan.conway@gmail.com
[alias]
bn = !git for-each-ref --format='%(refname:short)' `git symbolic-ref HEAD`
br = branch
c = commit
co = checkout
com = checkout master
cp = cherry-pick $0
@jonathanconway
jonathanconway / mov2gif
Last active August 11, 2023 08:20
Convert QuickTime screencasts to animated GIFs using ffmpeg
#!/bin/bash
# Inspired by solution by StackOverflow user #18664.
# [See: https://apple.stackexchange.com/a/211219/97498]
#
# Usage:
# gif [filename]
#
# filename - name of a .mov file to convert, excluding .mov extension
alias subl='open -a "Sublime Text"'
alias l="ls -la"
@jonathanconway
jonathanconway / addthis_reload.js
Created April 1, 2014 23:45
Reload (or initialize) addThis social share buttons. Useful when implementing addThis in a SPA (Single Page Application).
// Reload (or initialize) addThis social share buttons.
// IMPORTANT: make sure you put in a correct pubid on line 7.
window.addthis_reload = function () {
if (!window.addthis) {
// Load addThis, if it hasn't already been loaded.
window['addthis_config'] = { 'data_track_addressbar' : false };
$('body').append('<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid={YOUR PUBID HERE}"></script>');
} else {
// Already loaded? Then re-attach it to the newly rendered set of social icons.
// And reset share url/title, so they don't carry-over from the previous page.
@jonathanconway
jonathanconway / docker-nuke
Last active June 16, 2022 19:59
Nuke all docker images and containers ☢️
#!/bin/bash
docker rm --force $(docker ps --all -q)
docker rmi --force $(docker images --all -q)
/**
* Enum which supports attached methods.
* Each method's `this` is the enum object.
*/
class Enum {
/**
* @param items {Object} Enum keys and values as a plain object
* @param methods {Object} Enum methods as a plain object
* (names are keys, values are methods)
*/
@jonathanconway
jonathanconway / jquery.prebind.js
Created June 25, 2011 05:53
preBind() - Add an event binding *before* any pre-existing bindings. (An early version, may not work in all scenarios)
$.fn.preBind = function(type, data, fn) {
var currentBindings = this.data('events')[type];
var currentBindingsLastIndex = currentBindings.length - 1;
var newBindings = [];
// bind the event
this.bind(type, data, fn);
// move the new event to the top of the array
newBindings.push(currentBindings[currentBindingsLastIndex]);
@jonathanconway
jonathanconway / radioTabbable.ng.js
Last active April 5, 2019 14:03
Angular Directive that makes individual radio-buttons focusable using the keyboard only. (Useful for accessibility, on a case-by-case basis.)
/**
* @ngdoc directive
* @name radioTabbable
* @requires none
* @description
* Makes individual radio buttons focuseable using the TAB key.
* (By default, pressing TAB while on a radio button would have shifted focus to the next control outside of the radio group.)
* @usage
* <input type="radio" name="radioGroup" value="0" radio-tabbable="" />
* <input type="radio" name="radioGroup" value="1" radio-tabbable="" />