Skip to content

Instantly share code, notes, and snippets.

View tochman's full-sized avatar
💭
Coding on my own SaaS project (Rails + React)

Thomas Ochman tochman

💭
Coding on my own SaaS project (Rails + React)
View GitHub Profile
require 'addressable/uri'
#Accepts options[:message] and options[:allowed_protocols]
class UriValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
uri = parse_uri(value)
if !uri
record.errors[attribute] << generic_failure_message
elsif !allowed_protocols.include?(uri.scheme)
record.errors[attribute] << "must begin with #{allowed_protocols_humanized}"
def choices(array)
'[' + array.join('|') + ']'
end
greetings = choices(%w[Hello Hi Hey])
titles = choices(%w[friend dear])
concerns = choices(
[
"are you #{choices(['today', 'these days'])}",
"is your #{choices(%w[sister mother father brother])}"
@tochman
tochman / Calender-UI.markdown
Created September 10, 2014 09:17
A Pen by Thomas ochman.
@tochman
tochman / event_creation_task.rb
Last active August 29, 2015 14:06
Create event instances?
event_instances = Event.find(:all)
event_instances.each do |event|
schedule = Schedule.from_yaml(event.schedule_yaml)
if schedule.occurs_on? Date.today + 5.days
#do stuff...
#like:
event_instance = [event.name, event.start_datetime].join('-')
EventInstance.find_or_create_by_name(name: event_instance, category: event.category, description: event.description)
#..and whatever information the instance need to inherit from its parent...
end
@tochman
tochman / commands.md
Last active August 29, 2015 14:06
Common git commands

Set-up

New repository for an existing code base

$ cd /path/to/my/codebase

$ git init

$ git add . or $ git add -A

def store_location
if conventional_get_request? && !black_listed_url?(black_listed_urls)
session[:previous_url] = request.fullpath
end
end
def clear_stored_location
session[:previous_url] = nil
end
@tochman
tochman / user.rb
Last active August 29, 2015 14:12
Legacy password handling. Could perhaps be used tin the bikeshare project as part of the qr-code validation??
##Methods for legacy password handling with Devise
def valid_password?(password)
if has_legacy_password?
return false unless valid_legacy_password?(password)
convert_legacy_password!(password)
true
else
super(password)
end
end
@tochman
tochman / _event_pre_month.rb
Created January 6, 2015 09:21
Event instances
<fieldset class="event_option" id="repeats_monthly_options">
<%= f.number_field :repeats_every_n_months %>
<%= f.select :repeats_monthly, Event::RepeatMonthlyOptions %>
<div class="control-group" id="event_repeats_monthly_each">
<label class="control-label">Each</label>
<div class="controls">
<% Event::DaysOfTheMonth.each do |day_of_the_month| %>
<%= label_tag "event_repeats_monthly_each_days_of_the_month_#{day_of_the_month}", day_of_the_month, :class => 'checkbox inline' do %>
<%= check_box_tag "event[repeats_monthly_each_days_of_the_month][#{day_of_the_month}]", day_of_the_month, f.object.repeats_monthly_each_days_of_the_month.include?(day_of_the_month), {:name => "event[repeats_monthly_each_days_of_the_month][]"} %>
<%= day_of_the_month %>
require 'spec_helper'
describe EventHelper do
it 'cover_for PairProgramming' do
event = mock_model(Event, category: 'PairProgramming')
result = helper.cover_for(event)
expect(result).to match /event-pairwithme-cover\.png/
end
it 'cover_for Scrum' do