Skip to content

Instantly share code, notes, and snippets.

View ZempTime's full-sized avatar

Chris Zempel ZempTime

View GitHub Profile
require 'byebug'
lambda {
setups = []
events = {}
Kernel.send :define_method, :event do |name, &block|
events[name] = block
end
@ZempTime
ZempTime / gist:859706f2b63d6e1fecba
Last active August 29, 2015 14:13
Check for video, audio, picture content
$(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"))
@ZempTime
ZempTime / refile_patch.rb
Last active August 29, 2015 14:13
Refile Attachment Disposition
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
RSpec.describe Game do
it 'accepts an initial seed pattern' do
seed = [
[1, 1],
[1, 1]
]
@game = Game.new(seed)
@ZempTime
ZempTime / gist:0b5995e8ec30f69738de
Last active August 29, 2015 14:20
SummaryGenerator for RebootU
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
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
@ZempTime
ZempTime / weight_formatter.rb
Last active August 29, 2015 14:22
Weight Formatter
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
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)
@ZempTime
ZempTime / scraping_ideas.rb
Last active August 11, 2016 15:41
Page Scraping Logic/Ideas
# 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
@ZempTime
ZempTime / translation.rb
Last active July 19, 2017 22:54
Translation Model
# 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