Skip to content

Instantly share code, notes, and snippets.

View kule's full-sized avatar

Luke Pearce kule

View GitHub Profile
@kule
kule / scope.rb#select_date
Created June 11, 2009 08:14
webrat: 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>.
#
@kule
kule / linode_disk_space.sh
Created November 17, 2010 15:35
Linode Ubuntu; check the amount of disk space you have left.
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | grep 'xvda' | awk '{ print $5 " (" $4 ") Left " }'
@kule
kule / defender.rb
Created October 25, 2012 15:48
Example handle_defensio_callback
# 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 / rvm_install_1.9.3_trace
Created November 7, 2012 13:24
Gist for RVM Issue #1299
→ rvm install 1.9.3 --trace
1.9.3 --trace
rvm 1.16.18 (stable) by Wayne E. Seguin <[email protected]>, Michal Papis <[email protected]> [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 / stock_manager.rb
Last active June 9, 2022 11:46
service object example
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 / user_tracking.rb
Last active October 8, 2023 15:35
Simple User Tracking For Rails
# (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 / mini_rspec.rb
Created September 11, 2018 09:37
Simplified example of how rspec works
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'colorize'
end
class MatcherInterface
def initialize(some_object)
@some_object = some_object
@kule
kule / evdev.xml
Last active August 1, 2023 11:12
uk-mac-xkb-symbols-config
<!-- 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 / starship.toml
Created September 13, 2022 08:18
Starship.rs Pastel Powerline Inspired Setup (ruby/k8s/docker/git)
format = """
[](bg:#33658A fg:#282727)\
[](bg:#349a73 fg:#33658A)\
$hostname\
[](bg:#9A348E fg:#349a73)\
$directory\
[](bg:#DA627D fg:#9A348E)\
$ruby\
[](fg:#DA627D bg:#869ED8)\
$kubernetes\