Skip to content

Instantly share code, notes, and snippets.

View gfmurphy's full-sized avatar

George F Murphy gfmurphy

  • Salesforce
  • Little Rock
View GitHub Profile
function validate_forms() {
global $wpdb, $current_user, $user_ID;
$any_bad_inputs = false;
$bad_input_message = '';
if(is_numeric($_POST['card_number']) === false) {
$_SESSION['wpsc_gateway_error_messages']['card_number'] = __('Please enter a valid card number.', 'wpsc');
}
@gfmurphy
gfmurphy / soft_destroy.rb
Created October 7, 2011 20:33
Messy? Can you think of a more clear implementation of soft_destroy_method?
module SoftDestroy
# accepts a method or proc to execute as a soft deletion routine
# replaces existing destroy method with new soft destroy
def soft_destroy_method(&block)
if block_given?
self.class_eval do
def destroy_with_forgiveness
block.call(self)
end
@gfmurphy
gfmurphy / fizz_buzz.php
Created November 22, 2011 16:34
My Pre-FizzBuzz Test
<?php
// Make the following code better *in the simplest possible way*
// Assume $result is a resource identifier returned from a call to mysql_query with a select query as an argument in which you don't expect any results to be returned
if(mysql_num_results($result) > 0)
$error = true;
?>
@gfmurphy
gfmurphy / gah.rb
Created January 10, 2012 20:49
Sweet Sassy Rails
zone.try(:user).try(:has_carrier?, carrier.try(:name))
@gfmurphy
gfmurphy / order.rb
Created January 17, 2012 15:41
Spree Price Bucket Calculator Fix
Order.class_eval do
def amount
line_items.map(&:amount).sum
end
end
@gfmurphy
gfmurphy / resource_bs.rb
Created January 23, 2012 21:29
Le sigh...
def load_resource
"#{controller_name.classify}".constantize.find(params[:id])
end
@gfmurphy
gfmurphy / taxon_import.rb
Created February 20, 2012 16:13
Proposed Spree Data Import API
Spree::DataImport.for(:taxons).run("https://abcdef012356789:x@wherethedatalives.com/taxons.xml")
@gfmurphy
gfmurphy / simple_histogram.rb
Created April 16, 2013 13:56
Find top 16 most freq. occurring words greater than 4 characters
paragraphs.join("\n").split(/\W/)
.reject { |w| w.size < 4 }
.map(&:downcase)
.reduce(Hash.new(0)) { |words, word| words[word] += 1; words }
.sort { |a, b| a.last <=> b.last }
.take(16)
.map(&:first)
.join(' ')
@gfmurphy
gfmurphy / synch.cc
Created May 2, 2013 23:08
Mesa style wait and signal algorithm
void Condition_H::Wait() {
IntStatus oldLevel = interrupt->SetLevel(IntOff);
count++;
if (mon->next_count > 0) {
mon->next->V();
mon->next_count--;
}
else mon->mutex->V();
sem->P();
@gfmurphy
gfmurphy / gist:d408da3f91b17c266a0e
Last active August 29, 2015 14:15
Noindex deal criteria - i.e. instruct search engines to ignore deals (and remove from index) and *not* publish in xml sitemap.
# Deal types currently included in xml sitemap
# * "LocalDeal", "EscapesDeal", "AtHomeDeal", "FamiliesDeal"
# * live event deals are included
# URLs are generated with LS::Routing
# * Need to support a mobile version of the url for alternate content and mobile sitemap in near future.
def search_engine_ignore?(deal)
deal.exclusive? || deal.boomerang? || !deal.active?
end
# this logic expands to