Skip to content

Instantly share code, notes, and snippets.

View mark's full-sized avatar
💭
Smoove

Mark Josef mark

💭
Smoove
View GitHub Profile
# (1) Search through the logs for the responses
# tail -n 1000000 current/log/production.log | grep '"id"=>"<EVALUATION RESPONSE ID GOES HERE>"'
# (2) Copy and paste results into output.txt file in the same directory as this, and then run this file
def print_responses(hsh)
needed = {}
hsh["responses"].keys.sort.each do |k|
@mark
mark / Output
Created December 7, 2010 15:28
You don't get anything approaching the nice syntax, but you can implement the X and Z metaoperators in Ruby
> :cons.X [1, 2], ['a', 'b']
=> [[1, "a"], [1, "b"], [2, "a"], [2, "b"]]
> :+.X [1, 2], [10, 11]
=> [11, 12, 12, 13]
> :strcat.X [1, 2], [10, 11]
=> ["110", "111", "210", "211"]
> :==.X [1, 2], [1, 1]
@mark
mark / ActiveRecord::Base#ids
Created February 1, 2011 19:18
application_model.rb
#######
# #
# ids #
# #
#######
public
def self.ids(query_options = {})
values(query_options).map &:to_i
@mark
mark / application.html.erb
Created February 9, 2011 20:42
evaluation_response.js
<%= hidden_field_tag 'env', Rails.env %>
@mark
mark / gist:833887
Created February 18, 2011 16:11
array_transformer.rb
class Array
def transform(new_array)
delta = ArrayTransformer.new
yield(delta)
(self - new_array).each { |item| delta.call_remove(item) }
(new_array - self).each { |item| delta.call_insert(item) }
self
end
def alphabetize_with_other(array)
if array.include? "Other"
rest = array - [ "Other" ]
sorted = rest.sort_by &:whatever
sorted << "Other"
else
array.sort_by &:whatever
end
end
class Object
def default!
@__is_default = true
self
end
def default?
@__is_default
end
@mark
mark / my_date.rb
Created April 13, 2011 15:44
This was the date class I wrote like 5 years ago
class MyDate
include Comparable
MyDatesInMonth = [nil, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
MonthsOfYear = [nil, :January, :February, :March, :April, :May, :June,
:July, :August, :September, :October, :November, :December]
MyDatesOfWeek = [:Sunday, :Monday, :Tuesday, :Wednesday, :Thursday, :Friday, :Saturday]
def initialize(year, month, day, fixed = true)
@mark
mark / digital_root.rb
Created May 12, 2011 01:47
Digital Roots for 999
PEOPLE = [1, 2, 3, 4, 5, 6, 7, 8]
def subset(set)
if set.empty?
[[]]
else
first = set[0]
rest = set[1..-1]
subset(rest) + subset(rest).map { |x| x << first }
@mark
mark / gist:1089671
Created July 18, 2011 14:28
Regular expression rake tasks
namespace :ticket do
rule "" do |t|
if t.name =~ /ticket:(\d+)/
puts "Looking for ticket ##{$1}"
puts `rake notes:custom ANNOTATION=TIX#{$1}`
end
end
end