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
# advisory_documents | |
# id: integer | |
class AdvisoryDocument < ApplicationRecord | |
has_many :signed_advisory_documents | |
has_many :users, through: :signed_advisory_documents | |
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
const useWebsocketDataChannel = (createDataChannel) => { | |
const dataChannelRef = useRef() | |
const [connected, setConnected] = useState(false) | |
const receivedCallbackRef = useRef() | |
useEffect(() => { | |
dataChannelRef.current = createDataChannel({ | |
connected: () => setConnected(true), | |
received: receivedCallbackRef.current | |
}) |
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
const callEvery = (...functions) => (returnValue) => | |
functions.reduce((previousValue, currentFunction) => { | |
if (currentFunction === undefined) return previousValue | |
return currentFunction(returnValue) | |
}, returnValue) | |
export default chainEventHandler |
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
// Async example (returns a promise) | |
// Use case: you need a function to validate values after specific events (i.e. onSubmit) | |
const useFormValidation = (schema, values) => async () => { | |
try { | |
const isValidated = await schema.validate(values, { | |
abortEarly: false | |
}) | |
return isValidated | |
} catch (error) { | |
const { errors } = error |
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
EventOrOrganization.current = 193 | |
ticket_items_by_day = { | |
'2019-05-30' => TicketItem.find(1557), | |
'2019-05-31' => TicketItem.find(1558), | |
'2019-06-01' => TicketItem.find(1559) | |
} | |
Shift.all.includes(attendances: :member).find_each do |shift| | |
shift.attendances.each do |attendance| |
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 'csv' | |
class CsvReader | |
def parse(filename='/home/vlatko/rails_projects/inscale-interview/user_ticker_info.csv') | |
data = [] | |
CSV.foreach(filename, :headers => true, :converters => :all, :header_converters => :symbol) do |row| | |
data << user_existance_validator(hashed_row) | |
end | |
data.compact | |
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 MembersBatchesController < ApplicationController | |
respond_to :html | |
before_action :find_models, except: [:restore_modal, :restore] | |
def add_to_team_modal | |
hide_team_ids = @member_ids.count == 1 ? Member.find(@member_ids).first.team_ids : [] | |
@members = Member.find(@member_ids) | |
@allowed = @members.all? { |member| policy(member).add_to_team? && CollectionPolicy.new(current_member, member.teams).all_allow?(:manage?) } |
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
# Simple example implementation of User and TicketElement: | |
# | |
# class User < ActiveRecord::Base | |
# has_and_belongs_to_many :ticket_elements | |
# end | |
# | |
# class TicketElement < ActiveRecord::Base | |
# has_and_belongs_to_many :users | |
# 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 CollectionPolicy | |
attr_reader :collection, :user | |
def initialize(collection) | |
@user = user | |
@collection = collection | |
end | |
def all_allow?(action) | |
collection.all? do |record| |
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
# Inspired by http://postgresapp.com/documentation/install.html | |
# This will list all current databases | |
psql --list | |
# Find the databases you want to move over, i took all Rails development databases | |
psql --list | grep development | awk '{print $1;}' | |
# Then use this list in a for loop to make a db dump for each db | |
mkdir postgresql_dumps |
NewerOlder