Skip to content

Instantly share code, notes, and snippets.

View missinglink's full-sized avatar

Peter Johnson missinglink

View GitHub Profile
packages:
yum:
git: []
files:
/opt/elasticbeanstalk/hooks/appdeploy/pre/51install_meteor.sh:
mode: "000755"
user: root
group: root
encoding: plain
@missinglink
missinglink / safeapply.js
Created November 19, 2013 18:10
AngularJS SafeApply. This fixes the annoying angular error: "Error: $digest already in progress"
app.factory( 'SafeApply', function() {
return function($scope, fn) {
var phase = $scope.$root.$$phase;
if(phase == '$apply' || phase == '$digest') {
if(fn && (typeof(fn) === 'function')) {
fn();
}
} else {
$scope.$apply(fn);
}
@missinglink
missinglink / leaflet-foursquare.js
Last active November 29, 2016 14:59
Leaflet configuration which allows you to set map co-ordinates with a pixel offset (as per foursquare homepage). In this example I am using jQuery to find the width of `$('main.content')` and use that to offset the map.
var map = L.map( 'map' );
L.Map.prototype.panToOffset = function (latlng, offset, options) {
var x = this.latLngToContainerPoint(latlng).x - offset[0]
var y = this.latLngToContainerPoint(latlng).y - offset[1]
var point = this.containerPointToLatLng([x, y])
return this.setView(point, this._zoom, { pan: options })
}
function centerMap(){
@missinglink
missinglink / app.js
Created November 28, 2013 21:47
minimal express + passport + facebook app
var express = require('express')
, passport = require('passport')
, FacebookStrategy = require('passport-facebook').Strategy;
var usercache = {};
var User = function(){}
User.findOrCreate = function( profile, cb ){
usercache[ profile.id ] = profile;
console.log( usercache );
return cb( null, profile );
@missinglink
missinglink / app.js
Last active December 30, 2015 01:39
Absolute minimal node.js static file server using connect.
/**
* Absolute minimal node.js static
* file server using connect.
*
* Directory structure.
* .
* ├── app.js ( this file )
* └── public/ ( static assets )
*
* Install & run server.
@missinglink
missinglink / server.sh
Created December 4, 2013 17:32
One-line bash webserver
while true; do { echo -e 'HTTP/1.1 200 OK\r\n'; cat index.html; } | nc -l 8080; done
@missinglink
missinglink / stream.sh
Last active December 30, 2015 08:08
Functional programming with bash experiment.
#!/bin/bash
function stdout {
echo -e "\e[32m$@\e[0m";
}
function stderr {
echo -e "\e[31m$@\e[0m" 1>&2;
}
#!/bin/bash
function stdout {
echo -e "\e[32m$@\e[0m";
}
function stderr {
echo -e "\e[31m$@\e[0m" 1>&2;
}
@missinglink
missinglink / foo.sh
Last active December 30, 2015 08:59
#!/bin/bash
echo '--- 1 ---'
ls -1 | cowsay
function pause {
read -p "$*"
}
function multi {
@missinglink
missinglink / google-analytics-node.js
Created December 5, 2013 18:24
An example of how to generate Google Analytics reports from node.js (with custom dimensions).
var GA = require('googleanalytics'),
Table = require('cli-table'),
util = require('util');
// API client.
// You may need to enable API access to analytics for your account
// here: https://code.google.com/apis/console
var ga = new GA.GA({
"user": "myaccount@gmail.com",