Skip to content

Instantly share code, notes, and snippets.

View jamesbrooks's full-sized avatar

James Brooks jamesbrooks

View GitHub Profile
@jamesbrooks
jamesbrooks / Brewfile
Last active July 4, 2023 04:06
My personal Brewfile for homebrew-bundle
tap 'moncho/dry'
tap 'homebrew/cask-drivers'
tap 'homebrew/cask-versions'
brew 'asdf'
brew 'awscli'
brew 'bash-completion@2'
brew 'bash'
brew 'bat'
brew 'colima'
@jamesbrooks
jamesbrooks / gist:5812100
Created June 19, 2013 06:38
Rails - Internal Requests
def internal_request(path, params={})
request_env = Rack::MockRequest.env_for(path, params: params.to_query).merge({
'rack.session' => session
})
Rails.application.routes.call(request_env).last.body
end
@jamesbrooks
jamesbrooks / gist:5306657
Created April 4, 2013 00:20
Generate self-signed SSL certificate
openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout domain.key -out domain.crt
@jamesbrooks
jamesbrooks / team_builder.rb
Last active December 14, 2015 19:58
Block-based object constructor
class TeamBuilder
attr_accessor :name
attr_accessor :members
def initialize(name)
self.name = name
self.members = []
end
@jamesbrooks
jamesbrooks / DBAnalyzer.rb
Created December 1, 2011 01:50
Analyses a MySQL general query log, filters queries by structure and presents the most frequently ran query kinds
#!/usr/bin/env ruby
# Example usage
# DBAnalyzer.rb general-query.log
class DBAnalyzer
OPERATIONS = %w(SELECT)
SHOW_TOP = 10
@jamesbrooks
jamesbrooks / EXAMPLE.js
Created November 18, 2010 12:50
jQuery Skeleton Plugin
$('#element').plugin(); // calls init
$('#element').plugin({ foo: 'bar' }); // calls init and extends the hash into settings
$('#element').plugin('doSomething'); // calls init (if it hasn't already been done) and calls doSomething
$('#element').plugin('doSomething', { cake: 'delicious' }); // calls init and calls doSomething with the provided argument
#!/usr/bin/ruby
require 'rubygems'
require 'nokogiri'
require 'open-uri'
doc = Nokogiri::HTML(open('http://www.sportingpulse.com/comp_info.cgi?a=FIXTURE&compID=107624&c=1-4401-0-0-0'))
against = doc.xpath('//*[text()="Owned"]').first.xpath('../../..//b[text()!="Owned"]').first.text
time = doc.xpath('//*[text()="Owned"]').first.xpath('../../../td').first.inner_html.gsub(/\302\240/, ' ').gsub('<br>', ', ')
puts "Owned play #{against} at #{time}\n\n"
#!/bin/bash
# configuration
PROJECT_NAME='Foo'
PATH_TO_BACKUPS='/backups/foo_database_backups'
RECIPIENT_EMAIL='james@whatever.com'
DATABASE_USERNAME='root'
DATABASE_PASSWORD='password'
DATABASE_DATABASE='database_name'
# end of configuration. should not need to edit from this point
module TMail
class Mail
def plain_text_body
gather_plain_text_parts(self).flatten
end
private
def gather_plain_text_parts(part)
returning [] do |message|
message << part.body.strip if part.content_type == 'text/plain'
module ActionController
module Routing
class RouteSet
class Mapper
def hush_cms_pages(path)
named_route 'hush_cms_page',
"#{path}/*path",
:controller => HushCMS.configuration['controllers']['pages'],
:action => 'show'
end