Skip to content

Instantly share code, notes, and snippets.

View lukemorton's full-sized avatar

Luke Morton lukemorton

View GitHub Profile
@lukemorton
lukemorton / README.markdown
Created June 4, 2011 13:32
Set caret position via jQuery

jQuery Caret

This is a very simple lightweight plugin to allow you to move the caret (or cursor) position in an <input /> or <textarea> element.

By exposing three jQuery.fn methods you can easily move a a caret to any position you like:

$.fn.caretTo( index , [ offset ] )

@lukemorton
lukemorton / example.js
Created November 22, 2012 13:51
jQuery plugin for watching a form for changes then detecting if it has changed
// In this example we detect if a user clicks a link to travel elsewhere
// but has made changes to a form. If they have changed the form it prompts
// them to confirm before continuing.
jQuery(function ($) {
var $form = $('form').watchChanges();
$('a').click(function (e) {
if ($form.hasChanged() and ! confirm('Continue without saving changes?')) {
e.preventDefault();
}
@lukemorton
lukemorton / README.md
Last active August 24, 2022 15:17
Providing an interface in PHP for RFC 6570 and a little more based on addressable (a ruby gem).

URI

uri-template interface for PHP.

Classes

  • URI\Template::expand()
  • URI\Regex::from_template()
  • URI\Parser::parse() (only if needed)
<?php
/**
* Static singleton class for handling Assets
*
* @usage
* Asset::css('myscript.css');
*
* Asset::css(array(
* 'my-script.css',
* 'another.css',
@lukemorton
lukemorton / event-source.html
Created June 1, 2011 16:46 — forked from rwaldron/event-source.html
EventSource: The Glorified Long Polling Machine
Open your console.
<script src="event-source.js"></script>
@lukemorton
lukemorton / gist:1364437
Created November 14, 2011 16:58
CodeMirror mustache support
CodeMirror.defineMode("mustache", function (config, parserConfig) {
var mustacheOverlay = {
token: function (stream, state) {
if (stream.match("{{")) {
while ((ch = stream.next()) != null)
if (ch == "}" && stream.next() == "}") break;
return "mustache";
}
while (stream.next() != null && !stream.match("{{", false)) {}
return null;
@lukemorton
lukemorton / brew.sh
Last active March 19, 2020 11:13
My brew
#!/bin/sh
echo "Installing brew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
echo "Installing desktop apps..."
brew cask install google-chrome
brew cask install slack
brew cask install atom
brew cask install rowanj-gitx
function g; git $argv; end
function ll; ls -laH $argv; end
function _git_branch_name
set -l branch (command git symbolic-ref HEAD ^/dev/null | sed -e 's|^refs/heads/||')
if test -n "$branch"
echo $branch
else
set -l commit (command git rev-parse --short HEAD ^/dev/null)
@lukemorton
lukemorton / .gitconfig
Last active March 19, 2020 09:51
Latest git aliases
[alias]
st = status -sb
co = checkout
cp = cherry-pick
ci = commit
br = branch
sub = submodule
ls = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate
ll = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --numstat
undo = reset HEAD^
# Example One: spec/unit/lib/space/flight/ship_gateway_spec.rb
RSpec.describe Space::Flight::ShipGateway do
let(:ship) { FactoryBot.create(:ship) }
let(:gateway) { described_class.new(ship_repository: Ship) }
context 'when finding a ship by id' do
subject { gateway.find_by_id(ship.id) }
it 'returns ship with correct id' do