Skip to content

Instantly share code, notes, and snippets.

// returns true if mattern appears in string
public static boolean iregex(String pattern, String string) {
Pattern p = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(string);
return m.find();
}
<%
nav_classes = { "articles" => nil, "episodes" => nil }
nav_classes[controller_name.underscore] = "current"
%>
<%= link_to "", articles_path, :id => "articles", :class => nav_classes["articles"] %>
<%= link_to "", episodes_path, :id => "episodes", :class => nav_classes["episodes"] %>
require 'lib/scrubyt'
@extractor = Scrubyt::Extractor.new do
fetch "http://www.google.com/search?&q=ruby"
books "ul.results li" do
title "//h2"
author "p.author"
book_detail "h2 a" do
name "//title"
summary "//p[1]"
end
var HijaxDefaultAnimations = new Class({
initAnimations: function(hijaxMaster) {
this.hijaxMaster = hijaxMaster;
this.initOutAnimations();
},
hijaxMaster: undefined,
initOutAnimations: function() {
this.hijaxMaster.addEvent('animateOut', function() {
contents = $('content').getChildren();
// "this" here is not evaluated until inside the event handler -----------v
I have indices on orfs.contig_id and contigs.assembly_id. It only seems to be using the latter for some reason.
@nilbus
nilbus / gist:1061632
Created July 2, 2011 20:47
Edward's Expertiza TODO
4. Integrate Project D (replace Goldberg pieces and upgrade Rails)
5. Integrate and update Cucumber test framework
6. Finish up my work on reputation integration
7. Fix bugs assigned to me
8. Integrate other projects from last semester
9. Fix bugs from the issue tracker
# Import the college board schools
imported_schools = import_from(dat_file)
# Find schools matching CBIDs, combine ones with the same CBID, and update that school's data
for each college_board_school in imported_schools:
matching_robertson_schools = find_schools_by_cbid(college_board_school.cbid) # There are sometimes several that match a CBID
keeper_school = matching_robertson_schools.first
keeper_school.update_info_using(college_board_school)
duplicate_schools = matching_robertson_schools[1..-1]
for each duplicate in duplicate_schools:
@nilbus
nilbus / factory.coffee
Created September 5, 2011 15:00
How do I create a new instance of a class from within a class method?
class TreeNode
constructor: (@tree, @id, @name, @data={}, @children=[]) ->
@set_color() unless @data.$color
@name = @id if !@name? or @name.blank()
@create_root: (tree) -> # acts as a TreeNode class method. Called like TreeNode.create_root(tree)
new this tree, 'root'
# "new this" is incorrect and does not work.
# I want to call the equivalent of "new VariationTreeNode(...)" or "new ProfileTreeNode(...)",
@nilbus
nilbus / config\initializers\action_logger.rb
Created October 29, 2011 04:16
This initializer would replace all the modifications to the controllers
# No need to require aquarium; adding aquarium to the Gemfile takes care of that
class ActionController::Base
include Aquarium::DSL
around :methods => :all do |join_point, object, *args|
logger.info "[info] Entering: #{join_point.target_type.name}##{join_point.method_name}: object = #{object}, args = #{args}"
result = join_point.proceed
logger.info "[info] Leaving: #{join_point.target_type.name}##{join_point.method_name}: object = #{object}, args = #{args}"
result # block needs to return the result of the "proceed"!
end
@nilbus
nilbus / gist:1327577
Created October 31, 2011 14:14
Error occurs when doing some things in TorqueBox 2.x
/!\ FAILSAFE /!\ 10/31/2011 09:59 AM
Status: 500 Internal Server Error
private method `split' called for nil:NilClass
vfs:/home/edwarda/torquebox/robertson_scholars/vendor/plugins/feedback_notifier/lib/feedback_notification/feedback_notifiable.rb:56:in `post_data'
vfs:/home/edwarda/torquebox/robertson_scholars/vendor/plugins/feedback_notifier/lib/feedback_notification/feedback_notifiable.rb:51:in `post_data_from_exception'
vfs:/home/edwarda/torquebox/robertson_scholars/vendor/plugins/feedback_notifier/lib/feedback_notification/feedback_notifiable.rb:9:in `rescue_action_in_public'
/home/edwarda/.rvm/gems/jruby-1.6.5@robertson_scholars/gems/actionpack-2.3.14/lib/action_controller/rescue.rb:154:in `rescue_action_without_handler'
/home/edwarda/.rvm/gems/jruby-1.6.5@robertson_scholars/gems/actionpack-2.3.14/lib/action_controller/rescue.rb:73:in `rescue_action'
org/jruby/RubyKernel.java:2097:in `send'
/home/edwarda/.rvm/gems/jruby-1.6.5@robertson_scholars/gems/actionpack-2.3.14/lib/