Skip to content

Instantly share code, notes, and snippets.

View stephenrichards's full-sized avatar

Stephen Richards stephenrichards

  • Ministry of Justice
  • London
View GitHub Profile
@stephenrichards
stephenrichards / gist:5851607f3a19b3bb1c07
Created December 17, 2014 12:36
ruby script to download http pages with all assets (including 404, 500, etc)
#!/usr/bin/env ruby
# faux-wget.rb : example of performing wget-style mirroring
require 'nokogiri'
require 'net/http'
require 'fileutils'
require 'uri'
require 'pp'
=begin rdoc
fee_type_ids = Fee::BaseFeeType.where('description like ?', '%uplift%').where.not(id: [8,9,26,90]).pluck(:id)
claim_ids = Fee::BaseFee.where(fee_type_id: fee_type_ids).where.not(amount: 0.0).pluck(:claim_id)
submitted_claim_ids = Claim::BaseClaim.where(id: claim_ids).where(state: ['authorised', 'part_authorised']).order(id: :desc)
require 'rest-client'
require 'ap'
response = RestClient.get 'https://ip-ranges.amazonaws.com/ip-ranges.json', accept: :json
hash = JSON.parse(response.body)
regions = hash['prefixes']
ranges = []
regions.each do |region|
ranges << region['ip_prefix'] if region['region'] == 'eu-west-1'
["46.51.128.0/18",
"46.51.192.0/20",
"46.137.0.0/17",
"46.137.128.0/18",
"52.16.0.0/15",
"52.18.0.0/15",
"52.30.0.0/15",
"52.48.0.0/14",
"52.92.40.0/21",
"52.93.0.0/24",
/*
Query CCR database
Get bills on cases for AGFS scheme 10 with a caclulation date > 2/1/2015
*/
select
c.id,
s.psty_highest_level,
b.bity_bill_type,
@stephenrichards
stephenrichards / pop.rake
Created January 25, 2017 11:12
Rakefile to create people with similar names for peoplefinder test
namespace :db do
task :pop => :environment do
include FactoryGirl::Syntax::Methods
Person.where('surname like ?', 'Me%').map(&:destroy)
names = [
%w{ Nicky Meadhurst },
%w{ Nicola Meadhurst },
%w{ Nicky Medhurst },
%w{ Nicola Medhurst },
%w{ Jane Meadhurst },
@stephenrichards
stephenrichards / db_counter.rb
Created February 1, 2017 10:40
Count record in each table in database
# use as DbCounter.new.run
class DbRrecordCounter
def initialize
@conn = ActiveRecord::Base.connection
end
def run
@stephenrichards
stephenrichards / list_routes.rb
Created March 21, 2018 13:59
Llist all controllers and actions
Rails.application.routes.routes.each do |route|
d = route.defaults
next unless d.key?(:controller)
next if d[:internal] == true
puts "#{d[:controller]}/#{d[:action]}"
end
class Person < ApplicationRecord
validates_with PersonValidator
end
class OysterCardsController < ApplicationController
def index
@cards = OysterCard.order(balance: :desc)
end
def show
end
def swipe_out