Skip to content

Instantly share code, notes, and snippets.

View simonmorley's full-sized avatar

Simon Morley simonmorley

  • London
View GitHub Profile
@simonmorley
simonmorley / gist:663c7307fdd1105101c2
Last active August 29, 2015 14:00
Vim Cheat Sheet
Navigation
Ctrl-D "Move half-page down
Ctrl-U "Move half-page up
Ctrl-B "Page up
Ctrl-F "Page down
**Nerd Tree**
Ctrl-f "Page down
@simonmorley
simonmorley / gist:24f1492e8515d1038d29
Created May 4, 2014 15:20
Public API Cors Before Filter Rails API
before_filter: cors_filters
def cors_filters
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'POST, PUT, DELETE, GET, OPTIONS'
headers['Access-Control-Request-Method'] = '*'
headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept, Authorization'
end
@simonmorley
simonmorley / gist:64f6b784f7c26ee1d1a6
Created May 9, 2014 08:53
Small Rabbit Consumer Test
#!/usr/bin/env ruby
# encoding: utf-8
require "bunny"
conn = Bunny.new vhost: '/boxes', user: 'boxes', pass: 'xxx', host: '127.0.0.1'
conn.start
ch = conn.create_channel
x = ch.topic("boxes", durable: true)
@simonmorley
simonmorley / gist:5901be947407ea427f0a
Last active January 19, 2017 21:36
Import and Alias Mulitple Indexes To Elasticsearch Rails
# A collection of Rake tasks to facilitate importing data from yout models into Elasticsearch.
# This will import the index as an alias, update the alias and delete the old ones
# It will also allow the importation of indexes via arguments
# Add this e.g. into the `lib/tasks/elasticsearch.rake` file in your Rails application:
#
# require 'elasticsearch/rails/tasks/import'
#
# To import the records from your `Article` model, run:
@simonmorley
simonmorley / gist:0c625876f2c2328a57a0
Created June 2, 2014 13:57
default chilli file for Cucumber Tony
######### Production PolkaSpots ########
HS_WANIF=`uci -P/var/state get network.wan.ifname`
HS_LANIF=`uci -P/var/state get network.lan.ifname`
HS_NETWORK=192.168.4.0
HS_NETMASK=255.255.255.0
HS_UAMLISTEN=192.168.4.1
HS_UAMPORT=3990
HS_UAMUIPORT=4990
# HS_DYNIP=
# HS_DYNIP_MASK=255.255.255.0
#!/bin/sh
#
if [ "X$SSH_AUTH_SOCK" = "X" ]; then
eval `ssh-agent -s`
ssh-add $HOME/.ssh/id_rsa
fi
HOST=
REDIS_SLAVE_PORT=6000
@simonmorley
simonmorley / gist:d16261a1b45e28af6455
Last active January 4, 2016 10:44
Google Cloud Compute Create Snapshot with Rotate
#!/bin/ruby
require 'json'
require 'time'
require 'syslog'
class Snapshot
def initialize()
@format = 'json'
@simonmorley
simonmorley / gist:57dd35abda1889bf3868
Created September 24, 2014 10:40
Testing the gubbins
Here is a dummy gubbins.rb
#!/usr/bin/ruby
class Gubbins
def initialize
@api_url = "https://api.polkaspots.com"
end
it("should call CT's api and enable alerts for a box", function() {
expect($scope.box.is_monitored).toBe(false)
spyOn(boxFactory, 'alerts').andCallThrough()
var cont = element.find('input').controller('ngModel');
cont.$setViewValue(true);
deferred.resolve({slug: 123, is_monitored: true});
$scope.$apply()
expect($scope.status.processing).toBe(true)
expect(boxFactory.alerts).toHaveBeenCalled();
expect($scope.box.is_monitored).toBe(true)
{
"ap_mac": "00-18-0A-13-XX-XX",
"unique_id": "xxx",
"created_at": "20141010",
"meraki_secret": "xxx",
"location_id": 1294,
"latitude": 52.924263174858446,
"longitude": -1.4837226407115054,
"day": 5,
"version": 2,