Skip to content

Instantly share code, notes, and snippets.

View SahSantoshh's full-sized avatar
🏠
WFH

Santosh Prasad Sah SahSantoshh

🏠
WFH
View GitHub Profile
@SahSantoshh
SahSantoshh / arel_visitor_mysql_error_solution
Last active April 6, 2022 07:48
LoadError: cannot load such file -- arel/visitors/mysql
If got following error while migrating rails app, which uses mysql-5.7,
```
rake aborted!
LoadError: cannot load such file -- arel/visitors/mysql
/home/santosh/Documents/Danfhe/kirus/config/application.rb:7:in `<top (required)>'
/home/santosh/Documents/Danfhe/kirus/Rakefile:4:in `require_relative'
/home/santosh/Documents/Danfhe/kirus/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)
```
@SahSantoshh
SahSantoshh / docker-compose.yml
Created April 6, 2022 07:37
docker, docker-compose, mysql, mysql5.7, utf8 charset, sql mode traditional
version: "3.9"
services:
db:
image: mysql:5.7
restart: always
command: mysqld --sql_mode="" --character-set-server=utf8 --collation-server=utf8_general_ci
environment:
MYSQL_DATABASE: 'kirus_development'
MYSQL_ROOT_PASSWORD: 'password'
MYSQL_PASSWORD: 'password'
@SahSantoshh
SahSantoshh / streaming.rake
Created May 23, 2020 12:27
streaming.rake
namespace :streaming do
desc 'Fetch updates of Accounts data from salesforce push stream and update in database'
task accounts_and_contacts: :environment do
subscriber = SalesforceSubscriber.new
subscriber.create_account_push_topic
subscriber.create_contact_push_topic
subscriber.subscribe
end
end
@SahSantoshh
SahSantoshh / readme.md
Last active May 23, 2020 10:44
Envoronment Variables
  • USERNAME: User name of user who have access to read accounts and contacts records
  • PASSWORD: Password of the user
  • SECURITY_TOKEN: Security token of the user. Check doc for details.
  • CLIENT_ID: create a connected app Consumer Key
  • CLIENT_SECRET: create a connected app Consumer Secret
  • ACCOUNT_PUSH_TOPIC_NAME: Topic name for subscribing accounts for realtime changes. max_char: 25
  • CONTACT_PUSH_TOPIC_NAME: Topic name for subscribing contacts for realtime changes. max_char: 25
  • REDIS_URL: redis server url
def subscribe
EM.run do
# Subscribe to the account PushTopic.
account_topic = ENV['ACCOUNT_PUSH_TOPIC_NAME']
contact_topic = ENV['CONTACT_PUSH_TOPIC_NAME']
@client.subscription "/topic/#{account_topic}" do |message|
Logger.new(LOG_PATH).info('Account Received')
message.inspect
end
@SahSantoshh
SahSantoshh / salesforce_subscriber.rb
Created May 23, 2020 10:28
create_contact_push_topic
def create_contact_push_topic
# Create a PushTopic for subscribing to Contact changes.
contact_topic = @client.create!('PushTopic',
ApiVersion: '48.0',
Name: ENV['CONTACT_PUSH_TOPIC_NAME'],
Description: 'all contact records',
NotifyForOperations: 'All',
NotifyForFields: 'All',
Query: 'select Id, FirstName, LastName, Title, Email, Phone, MobilePhone, OtherPhone, AccountId, OwnerId, IsDeleted from Contact')
@SahSantoshh
SahSantoshh / salesforce_subscriber.rb
Created May 23, 2020 10:23
create_account_push_topic
def create_account_push_topic
account_topic = @client.create!('PushTopic',
ApiVersion: '48.0',
Name: ENV['ACCOUNT_PUSH_TOPIC_NAME'],
Description: 'all account records',
NotifyForOperations: 'All',
NotifyForFields: 'All',
Query: 'select Id, Name, Phone, Type, BillingStreet,BillingCity, BillingState, BillingPostalCode, BillingCountry, Ownerid, ParentId, IsDeleted from Account')
Logger.new(LOG_PATH).info('Account Push Topic Id: ' + account_topic)
nd
# Restforce uses faye as the underlying implementation for CometD.
require 'restforce'
require 'faye'
class SalesforceSubscriber
attr_reader :client
LOG_PATH = "#{Rails.root}/log/#{Rails.env}_salesforce.log"
# Initialize a client with your username/password/oauth token/etc.
def initialize
@SahSantoshh
SahSantoshh / gist:3c78117c85dda07db921aba052009d34
Created May 23, 2020 07:29
ror-sf-integration-needed-gem
gem 'cookiejar', git: 'https://github.com/MissionCapital/cookiejar.git'
gem 'faye', '0.8.9'
gem 'restforce', '~> 4.2.2'
@SahSantoshh
SahSantoshh / vs-code workspace.json
Last active June 18, 2019 04:09
VS-code ruby setup, auto format on save
{
"editor.tabSize": 2,
// Time (ms) to wait after keypress before running enabled linters. Ensures
// linters are only run when typing has finished and not for every keypress
"ruby.lintDebounceTime": 500,
// Basic settings: turn linter(s) on
"ruby.lint": {
"reek": true,
"rubocop": true,
"ruby": true, //Runs ruby -wc