🏄♂️
- GitHub Staff
- rickwinfrey.com
- @rewinfrey.bsky.social
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
-- situation was strange: | |
-- resource_attributes is a json column | |
-- needed to do a time interval comparison for a where clause in the query, but the resource_attributes->'created_at' | |
-- attribute was actually a json array that looked like this: | |
-- [nil, '2015-08-07 23:43:23TZ'] | |
-- I needed a way to compare against the second element in that array (the timestamp string) | |
-- and thanks to a helpful SO post I was able to create a postgres function allowing me to isolate the timestamp from the | |
-- containing json array | |
-- http://stackoverflow.com/questions/18833970/querying-inside-postgres-json-arrays |
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
def daylight_savings_time_starts(year) | |
date = Date.new(year, 3, 1) | |
return Date.new(year, 3, 8) if date.wday == 0 | |
return Date.new(year, 3, (7 - date.wday + 7 + 1)) | |
end | |
def daylight_savings_time_stops(year) | |
date = Date.new(year, 11, 1) | |
return date if date.wday == 0 | |
return Date.new(year, 11, (7 - date.wday + 1)) |
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
clean_data <- function(dataset) { | |
na.omit(dataset) | |
} | |
randomize <- function(dataset) { | |
dataset$randomized <- runif(length(dataset[,1])) | |
dataset | |
} | |
randomize_ordered <- function(dataset) { |
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
# Support for Rspec / Capybara subdomain integration testing | |
# Make sure this file is required by spec_helper.rb | |
# (e.g. save as spec/support/subdomains.rb) | |
def switch_to_subdomain(subdomain) | |
# lvh.me always resolves to 127.0.0.1 | |
hostname = subdomain ? "#{subdomain}.lvh.me" : "lvh.me" | |
Capybara.app_host = "http://#{hostname}" | |
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
# original implementation refactored after extract method (but still using static methods) | |
# criticism for this approach is: | |
# - dependencies are passed between method calls, rather than referenced via instance methods | |
# - cannot declare static methods as private (this is not valid) | |
# - there are multiple responsibilities (I'd argue this is not valid) | |
# - can be difficult to test | |
class SyncToAnalyticsService | |
ConnectionFailure = Class.new(StandardError) |
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
SELECT organizations.name, | |
organizations.id, | |
organizations.ancestry, | |
tmp.average_activated_time_of_children from organizations | |
JOIN ( | |
SELECT org.ancestry, | |
AVG(org.updated_at - org.created_at) as average_activated_time_of_children, | |
CAST(substring(org.ancestry from '\d+(?!\/)$') as integer) as organization_id | |
FROM organizations org | |
INNER JOIN accounts acc ON acc.organization_id=org.id |
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
{ | |
1: { | |
sectionName: "Section One", | |
sectionId: 1 | |
questions: { | |
1: { | |
prompt: "This is question one", | |
questionType: "basic-input" | |
questionId: 12 | |
}, |
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
// assets/javascripts/interview_guides_edit_helper.js | |
(function($) { | |
var InterviewGuidesEditHelper = {}; | |
// init function is called from the view with the options passed in | |
InterviewGuidesEditHelper.init = function(options) { | |
this.parentSelector = options.parentSelector; | |
this.sectionSortableClass = options.sectionSortableClass; | |
this.questionSortableClass = options.questionSortableClass; | |
this.deletedSectionSortableClass = options.deletedSectionSortableClass; |
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
result = -> (builder, number) { builder.call(builder, number) }.call( | |
-> (recurse, number) { | |
return 1 if number == 0 | |
return number * recurse.call(recurse, number - 1) | |
}, | |
5 | |
) | |
result # => 120 |
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
# this would be called in the controller, | |
# whose return value is the Strategy class | |
class CandidateJobDocumentStrategyFactory | |
def self.strategy_for(document_type) | |
case document_type | |
when :resume then resume_strategy | |
when :cover_letter then cover_letter_strategy | |
when :application then application_strategy | |
end |