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 / Gemfile
Created June 15, 2014 09:36
MS Sql Server
group :db do
gem 'ruby-odbc', :require => 'odbc'
gem 'tiny_tds'
gem 'activerecord-sqlserver-adapter', '~> 3.1.0'
end
group :development do
gem 'rails'
end
class String
def to_len_lines(len=80)
self.dup.to_len_lines!(len)
end
def to_len_lines!(len=80)
((self.length/len.to_f).ceil).times{|i| self[i*len,0] = $/ }
end
end
class ApiKey < ActiveRecord::Base
belongs_to :user
around_create :generate_api_key
def generate_api_key
self.api_key = ""
chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_-.,"
@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