Skip to content

Instantly share code, notes, and snippets.

View rubypanther's full-sized avatar

Paris Sinclair rubypanther

  • Eugene, Oregon, USA
View GitHub Profile
@rubypanther
rubypanther / gist:6044034
Created July 20, 2013 05:58
QGIS label expression
CASE
WHEN (SPECIES2 IS NOT NULL) THEN tostring( toint(2013 % YR_ORIGIN) ) || '\n' || tostring(SPECIES1)||'/'||tostring(SPECIES2 )
WHEN (SPECIES1 IS NOT NULL) THEN tostring( toint(2013 % YR_ORIGIN) ) || '\n' || tostring(SPECIES1)
ELSE
tostring( toint(2013 % YR_ORIGIN) )
END
@rubypanther
rubypanther / gist:5513058
Last active December 16, 2015 23:19
extconf.rb code for ruby_core_source
if RUBY_VERSION >= "1.9" and RUBY_VERSION <= "2.0"
begin
require "ruby_core_source"
rescue LoadError
require 'rubygems/user_interaction' # for 1.9.1
require 'rubygems/dependency_installer'
installer = Gem::DependencyInstaller.new
installer.install 'ruby_core_source'
Gem.refresh
@rubypanther
rubypanther / rb_ansi_to_iso.sed
Created September 8, 2012 01:57
Convert C comments for Ruby 2 (using sed)
s/\/\/(.*http:\/\/.*)$/\/* \1 *\//g
t
s/(http:\/\/.*)$/\1/g
t
s/\/\/(.*)$/\/* \1 *\//g
module DelegateDefault
def self.included base
base.send :extend, ClassMethods
end
module ClassMethods
def delegate_default args_hsh
include InstanceMethods
args_hsh.each do |attr,parent|
define_method attr do
@rubypanther
rubypanther / FICSBot.pm
Created May 29, 2012 21:34
FICS spellbot
package FICSBot;
use strict;
use warnings;
use base qw( Bot );
use IO::Select;
our $VERSION = "1.0.0";
our $DEBUG = 0;
@rubypanther
rubypanther / undefined_method_oddity_spec.rb
Created April 1, 2012 10:36
An RSpec "undefined method" oddity
class UndefinedMethodOddity
def foo
bar 1
bar 2
end
def bar(arg)
end
end
def self.active
s = arel_table
where(
s[:begins_at].lteq(Time.now.utc).or(s[:begins_at].eq(nil)).and(
s[:ends_at].gt(Time.now.utc).or(s[:ends_at]).eq(nil))
)
end
scope :voted_since, lambda{|since|
joins(:votes)
.where("`votes`.created_at >= ? AND `votes`.project_id = `users`.project_id", since.to_s(:db))
.group("`votes`.user_id")
.order("COUNT(`votes`.user_id) DESC")
}
def last_activity_description(date, user_id)
user_activity = UserActivity.find(:first, :conditions => ["Date(updated_at) <= ? and user_id = ?", dat
e, user_id], :order => 'updated_at DESC')
user_activity.activity.description
end
# better
def last_activity(date, user_id)
UserActivity.find(:first, :conditions => ["Date(updated_at) <= ? and user_id = ?", dat
e, user_id], :order => 'updated_at DESC').activity
def last_activity(date, user_id)
active_id = UserActivity.find(:first, :conditions => ["Date(updated_at) <= ? and user_id = ?", dat
e, user_id], :order => 'updated_at DESC').activity_id
end