Skip to content

Instantly share code, notes, and snippets.

@mrkplt
mrkplt / business_object.rb
Last active August 29, 2015 14:12
A sort of fast mock up of how I think you could implement business logic that would be separated from data layer and controller.
class BusinessObject
class LambdaError < StandardError; end;
class NotImplementedError < StandardError; end;
def initialize(lambda_hash = {})
post_init(lambda_hash)
end
def perform
raise NotImplementedError, 'must implement perform.'
@mrkplt
mrkplt / view_model.rb
Last active August 29, 2015 14:11
A quick view model implementation
class ViewModel
def initialize(klass)
@klass = klass
end
private
attr_accessor :klass
def method_missing(method_sym, *arguments, &block)
@mrkplt
mrkplt / gist:c6fb95cb613fed2075bc
Created July 10, 2014 14:44
Turn in a string into a valid local variable name.
def variablize(string)
sanitized_string = string.chomp('=')
sanitized_string = sanitized_string.gsub(/([^a-z0-9_])/i, '_')
sanitized_string[0] = sanitized_string[0].downcase.sub(/[0-9]/, '_')
sanitized_string
end
# extracted from http://www.thekua.com/atwork/2011/07/ruby-script-to-capture-http-traffic/
require 'webrick'
include WEBrick
class Simple < WEBrick::HTTPServlet::AbstractServlet
def do_POST(request, response)
puts "Body: " + request.body
puts "Header: " + request.raw_header.to_s
@mrkplt
mrkplt / potty_mouth.rb
Last active August 29, 2015 14:00
You've got a potty mouth
require 'csv_class_maker'
CsvClassMaker.generate_class('MyTweets', '/Users/mplatt/Downloads/tweets/tweets.csv')
curses = Regexp.new('piss|fuck|shit|dick|ass|damn', true)
all_tweets_count = MyTweets.all.size
my_curses_count = MyTweets.all.select{ |t| t if t.text.match(curses) }.size
{
"auto_indent": true,
"bold_folder_labels": true,
"detect_indentation": true,
"fade_fold_buttons": false,
"font_face": "Fira Mono OT",
"font_size": 13.0,
"highlight_line": true,
"ignored_packages":
[