Skip to content

Instantly share code, notes, and snippets.

View KarlDoyle's full-sized avatar

Karl Doyle KarlDoyle

  • Dublin
View GitHub Profile
@KarlDoyle
KarlDoyle / constructor.pattern.js
Created March 18, 2017 23:01
Javascript Design Patterns ( In progress )
function Car( model, year, miles ) {
this.model = model;
this.year = year;
this.miles = miles;
}
Car.prototype.toString = function() {
return `${this.model} has done ${this.miles} miles`
}
@KarlDoyle
KarlDoyle / Vagrantfile_env.rb
Created February 21, 2017 00:07
Add environment variables to Vagrant
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
$SECRET = ENV['SECRET']
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu/trusty32"
config.vm.synced_folder "app", "/home/vagrant/app"
config.vm.provision "shell", :run => "always", env: {
@KarlDoyle
KarlDoyle / README.md
Created February 18, 2017 20:47 — forked from zenorocha/README.md
A template for Github READMEs (Markdown) + Sublime Snippet

Project Name

TODO: Write a project description

Installation

TODO: Describe the installation process

Usage

@KarlDoyle
KarlDoyle / delete-merged-branches.sh
Created February 2, 2017 18:12
delete local branches merged into master
git branch --merged | egrep -v "(^\*|master)" | xargs git branch -d
@KarlDoyle
KarlDoyle / example.css
Created January 9, 2017 11:34
CSS3 Perspective example
.parent {
perspective: 1000px;
perspective-origin: 50% 0px;
position: relative;
}
.child {
transform: scale(0.9) rotateY(20deg) skewY(10deg);
}
@KarlDoyle
KarlDoyle / deduplicated_sorted_array.js
Created December 5, 2016 15:11
de-duplicated and sorted array
// Method for returning an array with unique values.
// [1,2,3,3,3,3].unique() => returns [1,2,3]
Array.prototype.unique = function() {
// Set() objects are collections of values. You can iterate through the elements of a set in insertion order.
// A value in the Set may only occur once; it is unique in the Set's collection.
// https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Set
// Use the spread operator to transform a set into an Array.
// https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Spread_operator
@KarlDoyle
KarlDoyle / array.unique.js
Last active December 5, 2016 15:02
Dedupe an array of integers in Javascript
// Method for returning an array with unique values.
// [1,2,3,3,3,3].unique() => returns [1,2,3]
Array.prototype.unique = function() {
// Set() objects are collections of values. You can iterate through the elements of a set in insertion order.
// A value in the Set may only occur once; it is unique in the Set's collection.
// https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Set
// Use the spread operator to transform a set into an Array.
// https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Spread_operator
@KarlDoyle
KarlDoyle / box-modal-test.css
Created September 24, 2016 08:33
Different depth of nodes will use different colour allowing you to see the size of each element on the page, their margin and their padding. Now you can easily identify inconsistencies.
* { background-color: rgba(255,0,0,.2); }
* * { background-color: rgba(0,255,0,.2); }
* * * { background-color: rgba(0,0,255,.2); }
* * * * { background-color: rgba(255,0,255,.2); }
* * * * * { background-color: rgba(0,255,255,.2); }
* * * * * * { background-color: rgba(255,255,0,.2); }
@KarlDoyle
KarlDoyle / gist:46cf86bebf94e8dc9f40a48c1dbb7e15
Created May 12, 2016 21:16 — forked from jacobvosmaer/gist:3187346
Open all files with git merge conflicts in Vim

Open all files with git merge conflicts in MacVim

git diff --name-only | uniq | xargs mvim

When git encounters a merge conflict, e.g. during a rebase, it drops you back into the shell with a dirty working directory. I like this one-liner for opening all files with a merge conflict in MacVim.

Once you're in Vim, you can then switch between the files with :n and :prev, or another favourite: :w | n (save current file and open the next command line-supplied file).

UPDATE: see below for a version that works with real terminal commands.

@KarlDoyle
KarlDoyle / event-logging.js
Created August 18, 2015 15:00
console log date when event happens
function logEvent(console_message) {
var now = new Date();
var nowUTC = now.toUTCString()
console.log(console_message + ' : ' + nowUTC);
}