Skip to content

Instantly share code, notes, and snippets.

@HotFusionMan
HotFusionMan / gist:9c18e3089506baddef58
Last active August 29, 2015 14:10
Add SQL "LIKE" clauses as ActiveRecord methods in a config/initializers/ file
# Thanks to https://stackoverflow.com/questions/7051062/whats-the-best-way-to-include-a-like-clause-in-a-rails-query for the original code.
module ActiveRecord
module Querying
def match_scope_condition(column, query)
arel_table[column].matches("%#{query}%")
end
def matching(*args)
column_name, opts = args.shift, args.extract_options!
operator = opts[:operator] || :or
@HotFusionMan
HotFusionMan / XOR.SQL
Created November 30, 2014 03:22
PostgreSQL PL/pgSQL implementation of XOR
CREATE OR REPLACE FUNCTION XOR(boolean, boolean) RETURNS boolean as $$ BEGIN RETURN ($1 and not $2) OR (not $1 and $2); END; $$ LANGUAGE 'plpgsql';
namespace :deploy do
def config(key)
(@config ||= YAML.load_file("config/deploy.yml").symbolize_keys)[key.to_sym]
end
# Hooks as needed
task :local_before do
end
=begin
http://groups.google.com/group/capistrano/msg/9f17c9c7787ac390
Message from discussion deploy:check and config.gem
From: Tom Copeland <t...@infoether.com>
Date: Thu, 4 Feb 2010 06:57:50 -0500
Local: Thurs, Feb 4 2010 3:57 am
Subject: Re: [capistrano] deploy:check and config.gem
On Feb 4, 2010, at 6:39 AM, Tom Copeland wrote:
@HotFusionMan
HotFusionMan / initialize_is_not_a_class_method.rb
Created August 12, 2010 00:25
initialize_is_not_a_class_method.rb
# In Ruby, initialize is not a class method; it can't access
# class instance variables.
class C
@a = 1
def self.a
@a
end
def initialize
# Instance methods can only access class-level instance variables via accessor methods (which are themselves class-level methods).
# Here's a demonstration of a more complex situation (in which the instance method in question comes from a mix-in module)
# that illustrates the same principle.
module M
def f
puts self.class.a
end
end
@HotFusionMan
HotFusionMan / passing_unknown_number_of_arguments_through_to_another_method.rb
Created August 12, 2010 00:12
passing_unknown_number_of_arguments_through_to_another_method.rb
class Parent
def initialize( a, b )
@a = a
@b = b
end
attr_reader :a, :b
end
class Child < Parent
def initialize( *args )
@HotFusionMan
HotFusionMan / toggle_network-interface_up-down.bash
Created September 27, 2010 17:18
toggle_network-interface_up-down.bash
#!/bin/bash
if (( $# < 1 ))
then
script_name=`basename $0`
echo "Usage: $script_name <interface_name>"
echo " e.g.: $script_name `ifconfig -l -d | cut -f 1 -d ' '`"
exit
fi
@HotFusionMan
HotFusionMan / toggle_Require_password_on_wake.scpt
Created October 26, 2010 02:29
When lending your Mac to someone who doesn't have an account on it, turn off being bothered to type in your password for them every time they have to wake it from sleep.
tell application "System Preferences"
activate
set current pane to pane id "com.apple.preference.security"
tell application "System Events"
tell process "System Preferences"
-- UNLOCK CHECKS
if (exists checkbox "Click the lock to make changes." of window 1) is true then
click checkbox "Click the lock to make changes." of window 1
@HotFusionMan
HotFusionMan / toggle_Require_password_on_wake.sh
Created October 27, 2010 15:34
shell script for calling gist 646214 from the command line
#!/bin/bash
~/bin/toggle_Require_password_on_wake.app/Contents/MacOS/applet