Skip to content

Instantly share code, notes, and snippets.

@markglenfletcher
markglenfletcher / api_design_guidelines.txt
Created November 13, 2015 18:56
API Design Guidelines
Separate Concerns
Path indicates the identity of the resources
E.g. /stories/1
The body transfers the contents
E.g. { 'story': { 'name':'My Story' } }
Headers to communicate metadata
Always SSL
respond to non-secure connections with 403 Forbidden
Do not redirect!
Always scope to API version
@markglenfletcher
markglenfletcher / DSL.rb
Created October 9, 2015 11:26
DSL example
require 'active_support'
require 'active_support/core_ext'
class Program
class << self
def define(&block)
Program.new.tap { |p| p.instance_eval(&block) }
end
end
@markglenfletcher
markglenfletcher / cheat.txt
Created September 30, 2015 20:02
SQL cheat sheet
SQL
Statements always end with a semi-colon ;
Statement breakdown:
CREATE TABLE table_name (
column_1 data_type,
column_1 data_type
);
@markglenfletcher
markglenfletcher / onsz.rb
Created September 27, 2015 17:53
ONS API hit
api_key = 'omit'
root_url = "http://data.ons.gov.uk/ons/api/data/"
api_url_gen = -> (path,key,params) { "#{root_url}#{path}?apikey=#{key}&#{params}" }
datasets_url = api_url_gen.call('contexts.json',api_key,'')
HTTParty.get datasets_url
@markglenfletcher
markglenfletcher / fizzborkbuzz.rb
Last active August 29, 2015 14:27
FizzBorkBuzz
class FizzBuzz
def answer(num)
tests.map do |test_class|
test_class.new(num).run
end.compact.join
end
private
def tests
ress = (1..100).map do |i|
uri = URI("http://freefringe.org.uk/programme/?action=tribe_photo&tribe_paged=#{i}&ical=1")
res = Net::HTTP.get_response(uri)
if res.is_a?(Net::HTTPSuccess)
res.body
else
nil
end
end; nil
@markglenfletcher
markglenfletcher / setup.sh
Created June 25, 2015 13:20
Ubuntu Rbenv/Ruby2.1.6/Nginx/MySQL stack setup script
#!/usr/bin/env bash
set -e
#
# Justin Cases
#
cd $HOME
#
@markglenfletcher
markglenfletcher / keybase.md
Created January 9, 2015 16:36
Keybase Proof

Keybase proof

I hereby claim:

  • I am markglenfletcher on github.
  • I am markglenfletcher (https://keybase.io/markglenfletcher) on keybase.
  • I have a public key whose fingerprint is A574 94CF E204 0400 F3DF 1D8F CBDC AF2C 02BB 0F2E

To claim this, I am signing this object:

@markglenfletcher
markglenfletcher / user.rb
Created September 7, 2014 18:26
simple mongoid auth
require 'digest/sha1'
class User
include Mongoid::Document
attr_accessor :password, :password_confirmation
field :email, type: String
field :hashed_password, type: String
field :salt, type: String
class String
def to_pig_latin
PigLatin.new(self).to_s
end
def self.to_pig_latin(phrase)
phrase.to_pig_latin
end
end