Skip to content

Instantly share code, notes, and snippets.

View rubypanther's full-sized avatar

Paris Sinclair rubypanther

  • Eugene, Oregon, USA
View GitHub Profile
class ApiKey < ActiveRecord::Base
belongs_to :user
around_create :generate_api_key
def generate_api_key
self.api_key = ""
chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_-.,"
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
@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 Photo
def photo_filename= filename
if (self.photo = File.read(filename) rescue nil)
save!
end
end
end
# ...
diff -up ruby-1.9.1-p378/ext/openssl/ossl.c.ossl10 ruby-1.9.1-p378/ext/openssl/ossl.c
--- ruby-1.9.1-p378/ext/openssl/ossl.c.ossl10 2007-02-13 00:01:19.000000000 +0100
+++ ruby-1.9.1-p378/ext/openssl/ossl.c 2009-08-26 12:29:41.000000000 +0200
@@ -92,7 +92,7 @@ ossl_x509_ary2sk(VALUE ary)
#define OSSL_IMPL_SK2ARY(name, type) \
VALUE \
-ossl_##name##_sk2ary(STACK *sk) \
+ossl_##name##_sk2ary(STACK_OF(type) *sk) \
{ \
class String
def word_slice(range, max_extra_chars = 20)
offset = range.max + 1
string = self.slice(range)
if self[offset,max_extra_chars] =~ /(^[a-zA-Z0-9_-]+)/
string << $1
end
string
class Object
def unique_methods
self.methods - Object.new.methods
end
end
@rubypanther
rubypanther / application.rb
Created February 25, 2011 10:31
Monkey patch to make postgres views work with rails 3.x
class ApplicationController < ActionController::Base
require 'postgresql_view_monkey'
end
digraph G {
size = "5,5"; node[fontsize=16];
struct3 [shape=record,label="hello\nworld |{ b |{c|<here> d|e}| f}| g | h"];
// incoming
client -> server;
server -> client;
}
@rubypanther
rubypanther / indent_chomp.rb
Created March 31, 2011 03:20
remove extra indentation
#!/usr/bin/env ruby
data = if file = ARGV.shift
File.open(file).read
else
<<DATA
command "simple-prompt", "Toggle the simple prompt." do
case Pry.active_instance.prompt
when Pry::SIMPLE_PROMPT
Pry.active_instance.prompt = Pry::DEFAULT_PROMPT