Skip to content

Instantly share code, notes, and snippets.

View patrickleet's full-sized avatar

Patrick Lee Scott patrickleet

View GitHub Profile
@patrickleet
patrickleet / gist:6312627
Created August 22, 2013 20:51
meteor.js cheatsheet
// Assuming the following directory structure
/*
app/
.meteor/
client/
server/
collections/
*/
// 1. Create a collection
@patrickleet
patrickleet / getParameterByName.js
Last active December 25, 2015 17:09
get query string param values by key name, optional url - uses location if none
function getParameterByName(name, url) {
var a = document.createElement('a');
a.href = url || location.href;
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(a.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
@patrickleet
patrickleet / router.js
Created November 14, 2013 18:13
route to same template
Router.map(function () {
this.route('home', {
path: '/',
template: 'myTemplate'
});
this.route('someroute', {
path: '/foo',
template: 'myTemplate'
// A Promise is an object that represents a task with two possible outcomes (success or failure) and holds callbacks that fire
// when one outcome or the other has occurred.
// But the biggest advantage of using Promises is that you can easily derive new Promises from existing ones.
// You might ask two Promises representing parallel tasks to give you a Promise that will inform you of their mutual completion.
// Or you might ask a Promise representing the first task in a series to give you a Promise representing the final task in
// the series.
// Without Promises
$.get('/mydata', {
@patrickleet
patrickleet / configureYelp.html
Last active August 11, 2017 16:05
Meteor OAuth1Binding REST calls using oauth1 package (Yelp example)
<template name='configureYelp'>
<div class="container">
<div class="section">
<h1>Yelp API Access Configuration</h1>
<p class="lead">Do not change if you don't know what you are doing.</p>
<p>{{currentConfig}}</p>
{{> quickForm schema=configureYelp doc=this id='configureYelp' type='method' meteormethod='configureYelp' buttonClasses="btn btn-primary" buttonContent="Configure Yelp"}}
</div>
</div>
</template>
<!-- Context should be the object you are tagging -->
<template name="tagInput">
<select class='tag-input' name='tags[]' multiple="multiple">
{{#each tags}}
<option value="{{this}}" selected="true">{{this}}</option>
{{/each}}
</select>
</template>
@patrickleet
patrickleet / Modal.js
Created February 26, 2015 19:27
modals
Modal = function() {
if (! (this instanceof Modal)) {
return new Modal(options);
}
this.modalTemp = null;
this.clearTimeout = null;
this.inserted = false;
this.fixScrollPosition = true;
this._lastScrollTop = 0;
@patrickleet
patrickleet / gitflow.sh
Created October 18, 2015 00:43
Average git workflow
# create a branch (ex. 'bug/checkout-error '
# or 'feature/segment-analytics')
git checkout -b feature/example
# Do work, then commit your changes.
# To create a commit you first need to add the files
# you are going to commit. This is known
# as "staging the files".
# Check that the files changes are what you think.
@patrickleet
patrickleet / Docker Cheatsheet.md
Last active October 15, 2016 14:08
docker | docker-machine | docker-compose | docker swarm cheatsheet

docker | docker-machine | docker-compose | docker swarm cheatsheet

docker-machine

Used to create VMs that run docker

create

docker-machine create -d virtualbox machinename
import pRequest from 'util/promiseRequest'
Object.resolve = function(path, obj) {
return path.split('.').reduce(function(prev, curr) {
return prev ? prev[curr] : undefined
}, obj)
}
export class RESTConnector {
constructor({ rootUrl, keyPath }) {