Skip to content

Instantly share code, notes, and snippets.

@dwilkie
dwilkie / rayo.md
Created January 30, 2024 07:16
Rayo Commands

Rayo Commands

Start FreeSWITCH Console

$ fs_cli -p secret

Get Rayo Status

@dwilkie
dwilkie / tcpdump.sh
Last active January 24, 2024 13:27
Docker tcpdump
sudo docker run -it --rm --net container:59da80a76475 nicolaka/netshoot # Replace 59da80a76475 with the running container ID
tcpdump -Xvv -i eth0 -s0 -w capture.pcap
curl -F "file=@capture.pcap" https://file.io
@dwilkie
dwilkie / import_stories.rb
Last active January 14, 2022 11:45
Import UNICEF IF Workplan into Pivotal Tracker
## import_stories.rb
# Imports stories from the UNICEF Workplan into Pivotal Tracker from CSV file.
### CSV file format
# Export the UNICEF worklplan as CSV.
### Usage
@dwilkie
dwilkie / import_contacts.rb
Last active December 9, 2021 08:51
Import contacts into SCFM
## import_contacts.rb
# Imports contacts into SCFM from CSV file.
### CSV file format
# CSV File must have a `phone_number` or `telephone_number` column
# which contains the phone number of the contact. The phone number
# must be in international E.164 format. All other additional columns
# are added to the contact's metadata with the key being the column header
@dwilkie
dwilkie / unicef_metrics.rb
Last active November 2, 2021 08:34
UNICEF Metrics
start_time = Time.new(2020, 10, 1).beginning_of_day
end_time = Time.new(2020, 12, 31).end_of_day
completed_calls = PhoneCall.completed.where(created_at: start_time..end_time).joins(:call_data_record)
number_of_unpaid_users = User.count # SCFM only for now
number_of_calls = completed_calls.count
number_of_minutes = completed_calls.sum("call_data_records.bill_sec") / 60
number_of_users = (completed_calls.pluck(:to) + completed_calls.pluck(:from)).uniq.count
@dwilkie
dwilkie / migrate_from_refile_to_activestorage.rb
Last active May 17, 2023 20:26
Migrate from Refile to ActiveStorage
CallDataRecord.find_each do |cdr|
next if cdr.file.attached?
cdr_url = "https://s3-ap-southeast-1.amazonaws.com/cdr.somleng.org/store/#{cdr.file_id}"
cdr.file.attach(
io: open(cdr_url),
filename: cdr.file_filename,
content_type: cdr.file_content_type
)
end
@dwilkie
dwilkie / elastic_beanstalk_db_backup.sh
Last active May 8, 2022 08:24
Elastic Beanstalk pg_dump
# On Elastic Beanstalk machine
yum install -y https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-6-x86_64/postgresql11-libs-11.4-1PGDG.rhel6.x86_64.rpm
yum install -y https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-6-x86_64/postgresql11-11.4-1PGDG.rhel6.x86_64.rpm
yum install -y https://download.postgresql.org/pub/repos/yum/11/redhat/rhel-6-x86_64/postgresql11-server-11.4-1PGDG.rhel6.x86_64.rpm
pg_dump --version
EB_SUPPORT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k support_dir)
EB_SCRIPT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k script_dir)
@dwilkie
dwilkie / scfm_paginate_contacts_example.rb
Created February 21, 2020 01:48
SCFM Paginate Contacts Example
require "net/http"
require "uri"
require "pry"
require "link-header-parser" # https://github.com/jgarber623/link-header-parser-ruby
require "time"
SOURCE_HOST = "https://dashboard.ews1294.info"
SOURCE_API_KEY = "[your API key]"
DESTINATION_HOST = "https://scfm.somleng.org"
@dwilkie
dwilkie / modify_contacts_metadata.rb
Created November 28, 2018 09:15
SCFM Modify Contacts
require "csv"
require "httparty"
DATA_FILE = "tmp/phone_test.csv".freeze
API_ENDPOINT = "https://scfm.somleng.org/api/contact_data".freeze
API_KEY = "REPLACE_ME".freeze
def update_contact!(row)
response = HTTParty.post(
API_ENDPOINT,
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say voice="Polly.Ricardo" language="pt-BR">Hello World</Say>
<Say voice="Polly.Vitoria" language="pt-BR">Hello World</Say>
</Response>