Skip to content

Instantly share code, notes, and snippets.

View jozr's full-sized avatar
💗

Josephine jozr

💗
  • San Diego, USA
  • 05:24 (UTC -07:00)
View GitHub Profile
require 'prawn'
require 'prawn/table'
module Spree
class ExamplePdf < Prawn::Document
HEADER = ['I', 'II', 'III', 'IV']
WIDTH = 200
def initialize
@jozr
jozr / operations_manager
Last active August 29, 2015 14:24
Create operations manager role and rerun BW processes in Panda production
cd app
RAILS_ENV=production bundle exec rails c
# adding ops manager role with default users
operations_manager = Role.find_or_create(:name => "operations_manager")
california_first = Program.first(:identifier => "california_first")
users = User.where(:username => ["joe", "rhasan", "itatlonghari", "apintado"])
users.each { |user| Membership.find_or_create(:user => user, :role => operations_manager, :program => california_first) }
# rerunning BW processes
Bumbleworks.timeout = 15
SELECT COUNT(*)
FROM surveys
JOIN properties ON surveys.property_id = properties.id
JOIN owners_properties ON properties.id = owners_properties.property_id
WHERE owners_properties.property_id > 1
FROM financing_applications s
JOIN
(
SELECT COUNT(1),property_id
FROM owners_properties
GROUP BY property_id
HAVING COUNT(1) > 1
) p ON p.property_id=s.property_id
@jozr
jozr / query.sql
Last active October 26, 2015 18:43
SELECT financing_applications.id
FROM financing_applications
JOIN properties ON financing_applications.property_id = properties.id
JOIN addresses ON properties.address_id = addresses.id
WHERE addresses.county = 'Los Angeles'
AND financing_applications.notice_to_proceed_sent_at IS NULL
AND financing_applications.status != 'declined'
AND financing_applications.status != 'withdrawn'
AND financing_applications.application_document_process_identifier IS NOT NULL;
@jozr
jozr / migrate.rb
Last active July 18, 2018 09:25
SALT-821: Migrate "ConversationElements::Feedback" to "ConversationElements::Plaintext"
@count = Conversation.where("conversation_groups.conversation_elements._type" => "ConversationElements::Feedback").count
Conversation.where("conversation_groups.conversation_elements._type" => "ConversationElements::Feedback").each_with_index do |conversation, i|
percentage = (i.to_f / @count) * 100
puts "PROGRESS: #{percentage.to_s}" if percentage % 10 == 0
for group in conversation.conversation_groups do
for element in group.conversation_elements do
if element._type == "ConversationElements::Feedback"
text = element.text
group.conversation_elements << ConversationElements::Plaintext.new(text: text)
element.delete
def descendants_mapper(klass)
klass.subclasses.reduce({}) { |memo, subclass|
memo[subclass] = descendants_mapper(subclass); memo
}
end
{ MasterClass => descendants_mapper(MasterClass) }
# GETtable from:
# /visitor_funnel/placement_test/result
# or
# /funnel/placement_test/result
{
conversation_id: "abc123",
levels_count: 9, # should be offset by -1 considering the index_number
level: {
index_number: 4,
@jozr
jozr / levenshtein.js
Last active October 5, 2018 10:25
Levenshtein
const levenshteinDistance = (a, b) => {
const costs = Array.from({ length: b.length + 1 }, (_, i) => i)
for (let i = 1; i <= a.length; ++i) {
costs[0] = i
let offset = i - 1
for (let j = 1; j <= b.length; ++j) {
const arr = [
costs[j] + 1,
costs[j - 1] + 1,