Skip to content

Instantly share code, notes, and snippets.

Luke Pearce kule

View GitHub Profile
@kule
kule / evdev.xml
Last active Jun 14, 2020
uk-mac-xkb-symbols-config
View evdev.xml
<!-- Amend the uk mac variants in /usr/share/X11/xkb/rules/evdev.xml -->
...
<variant>
<configItem>
<name>mac</name>
<description>English (UK, Macintosh)</description>
</configItem>
</variant>
<!-- START OF ADDITION -->
<variant>
@kule
kule / mini_rspec.rb
Created Sep 11, 2018
Simplified example of how rspec works
View mini_rspec.rb
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'colorize'
end
class MatcherInterface
def initialize(some_object)
@some_object = some_object
@kule
kule / user_tracking.rb
Last active May 19, 2020
Simple User Tracking For Rails
View user_tracking.rb
# (concern) e.g. for Post model
module UserTrackable
extend ActiveSupport::Concern
included do
before_create :set_created_by
before_save :set_updated_by
belongs_to :created_by, class_name: 'User', foreign_key: 'created_by_id'
@kule
kule / stock_manager.rb
Last active Dec 23, 2015
service object example
View stock_manager.rb
class StockManager
def initialize(cart_item)
@cart_item = cart_item
end
def save_and_update_stock
if @cart_item.quantity_changed?
ActiveRecord::Base.transaction do
new_quantity = @cart_item.product.quantity
if @cart_item.quantity_was.to_i > @cart_item.quantity
@kule
kule / rvm_install_1.9.3_trace
Created Nov 7, 2012
Gist for RVM Issue #1299
View rvm_install_1.9.3_trace
→ rvm install 1.9.3 --trace
1.9.3 --trace
rvm 1.16.18 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]
+ [[ -n '' ]]
+ set -o errtrace
+ export 'PS4=+ ${BASH_SOURCE##${rvm_path:-}} : ${FUNCNAME[0]:+${FUNCNAME[0]}()} ${LINENO} > '
+ PS4='+ ${BASH_SOURCE##${rvm_path:-}} : ${FUNCNAME[0]:+${FUNCNAME[0]}()} ${LINENO} > '
+ /scripts/cli : __rvm_parse_args() 716 > [[ -z install ]]
@kule
kule / defender.rb
Created Oct 25, 2012
Example handle_defensio_callback
View defender.rb
# Public: This will take the request object and update the relevant model
def self.handle_defensio_callback(request)
query_params = CGI::parse(request.query_string)
defender_model = query_params['model'].first.strip
if defender_model.empty?
raise DefenderError, 'Incorrect url structure; missing callback url param'
else
begin
document = document_from_defensio_callback(request)
unless document.nil?
@kule
kule / linode_disk_space.sh
Created Nov 17, 2010
Linode Ubuntu; check the amount of disk space you have left.
View linode_disk_space.sh
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | grep 'xvda' | awk '{ print $5 " (" $4 ") Left " }'
@kule
kule / scope.rb#select_date
Created Jun 11, 2009
webrat: scope.rb#select_date
View scope.rb#select_date
# Verifies that date elements (year, month, day) exist on the current page
# with the specified values. You can optionally restrict the search to a specific
# date's elements by assigning <tt>options[:from]</tt> the value of the date's
# label. Selects all the date elements with date provided. The date provided may
# be a string or a Date/Time object.
#
# Rail's convention is used for detecting the date elements. All elements
# are assumed to have a shared prefix. You may also specify the prefix
# by assigning <tt>options[:id_prefix]</tt>.
#
You can’t perform that action at this time.