This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'byebug' | |
lambda { | |
setups = [] | |
events = {} | |
Kernel.send :define_method, :event do |name, &block| | |
events[name] = block | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready -> | |
$("#post_content").keyup -> | |
urls = findUrls($("#post_content").text()) | |
youtube_pattern = ///http://(?:www\.)?youtu(?:be\.com/watch\?v=|\.be/)(\w*)(&(amp;)?[\w\?=]*)?/// | |
flickr_pattern = ///flickr.com\/photos/// | |
soundcloud_pattern = ///w.soundcloud.com/// | |
check_for_assets(youtube_pattern, urls, $("#post_has_video")) | |
check_for_assets(flickr_pattern, urls, $("#post_has_picture")) | |
check_for_assets(soundcloud_pattern, urls, $("#post_has_audio")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Refile | |
class << self | |
def attachment_url(object, name, *args, prefix: nil, filename: nil, format: nil, host: nil, disposition: nil) | |
attacher = object.send(:"#{name}_attacher") | |
file = attacher.get | |
return unless file | |
host ||= Refile.host | |
prefix ||= Refile.mount_point | |
filename ||= attacher.basename || name.to_s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RSpec.describe Game do | |
it 'accepts an initial seed pattern' do | |
seed = [ | |
[1, 1], | |
[1, 1] | |
] | |
@game = Game.new(seed) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SummaryGenerator | |
def self.summarize(raw_text) | |
sentences = raw_text.gsub(/\s+/, ' ').strip.split(/\.|\?|!/) | |
sentences_sorted = sentences.sort_by { |sentence| sentence.length } | |
one_third = sentences_sorted.length / 3 | |
middle_third = sentences_sorted.slice(one_third, one_third + 1) | |
ideal_sentences = sentences_sorted.select { |sentence| sentence =~ /is|are/ } | |
ideal_sentences.join(".") | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Summarizer | |
def self.call(raw_text, percentage = 25) | |
@@text = raw_text | |
arrayify.sort_by_length.get_middle_percent(percentage).glean_important_sentences.make_pretty | |
@@text | |
end | |
def self.arrayify |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WeightFormatter | |
PROCESSABLE_WEIGHT_UNITS = ["grams", "ounces"] | |
def self.call(weight_unit, weight) | |
unless PROCESSABLE_WEIGHT_TYPES.include?(weight_unit) | |
return "#{weight} #{weight_unit}" | |
end | |
send("process_#{weight_unit.downcase}", weight) | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class @RealtimeForm | |
constructor: (form) -> | |
@form = $(form) | |
@behavior = @form.data("realtime") | |
@monitorInputs() | |
monitorInputs: => | |
@radio_inputs = new RadioGroupInput @form.find(":radio"), @behavior | |
@inputs = $.map @form.find(":input").not(":input[type=submit]").not(":input[type=radio]"), (input, i) => | |
new TextyInput(input, @behavior) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# from http://blog.rubyroidlabs.com/2016/04/web-scraping-2/ | |
def strip_bad_chars(text) | |
text.gsub!(/"/, "'"); | |
text.gsub!(/\u2018/, "'"); | |
text.gsub!(/[”“]/, '"'); | |
text.gsub!(/’/, "'"); | |
text | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pseudocode | |
# assuming message is set by the teacher, and isn't stored on a 1-1 message/parent basis | |
# but a 1 message - many parents basis | |
class Message < ActiveRecord::Base | |
has_many :translations | |
def translated_message(language_code='en') | |
translation = translations.where(language_code: language_code).first | |
if translation |
OlderNewer