Skip to content

Instantly share code, notes, and snippets.

View missinglink's full-sized avatar

Peter Johnson missinglink

View GitHub Profile
@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;
}
@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 / 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 / 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 / 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 / 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);
}
packages:
yum:
git: []
files:
/opt/elasticbeanstalk/hooks/appdeploy/pre/51install_meteor.sh:
mode: "000755"
user: root
group: root
encoding: plain
@missinglink
missinglink / 0_reuse_code.js
Created October 20, 2013 11:18
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@missinglink
missinglink / prices.regexp.js
Last active April 15, 2021 14:05
Extract price information from any page using regex stolen from this annoying superfish script.
var regexp = /(([\$\£\€\u20AC]|eur|ils|rs)\.?\s*(<[^>]+>|&nbsp;|\s)?([0-9]+[\,\.])?[0-9]+([\,\.][0-9]+)?)|(([0-9]+[\,\.])?[0-9]+([\,\.][0-9]+)?)(<[^>]+>|&nbsp;|\s|\s\,\-\s)?(€|\u20AC|eur|ils|rs)\.?/ig;
document.body.innerHTML.match(regexp);
@missinglink
missinglink / installation.md
Last active December 20, 2015 03:19
Working example of how to set up elasticsearch so that the _percolate index is being populated via a mongodb river. Tested with mongodb 2.4.4+, elasticsearch 0.9.0+, elasticsearch-river-mongodb 1.6.11

Configure mongo for replication

  • Make sure you have sufficient disk space to hold the oplog ( can be several GB )
  • Edit /etc/mongodb.conf to add replSet = rs0
  • Restart mongodb
  • In the mongo REPL execute rs.initiate() ( this can take some time; log shows activity )
  • Try executing a query, your REPL prompt should now be rs0:PRIMARY>

MongoDB documentation: http://docs.mongodb.org/manual/tutorial/convert-standalone-to-replica-set/