Skip to content

Instantly share code, notes, and snippets.

View Hamada92's full-sized avatar

Ahmad Al-kheat Hamada92

View GitHub Profile
require "uri"
require "json"
require "net/http"
def recursive_fetch(url)
url = URI(url)
https = Net::HTTP.new(url.host, url.port)
https.use_ssl = true
@Hamada92
Hamada92 / script.rb
Last active July 22, 2019 22:06
how to create new avatar names
# open AvatarUploader and re-define the filename method dynamically- because ewe can't deploy this code,
# it doesn't work for new records as the processing happens async and can't gauarentee that model.id exists, so we
# should run it only after the record is created.
AvatarUploader.class_eval do
def filename
token = OpenSSL::HMAC.hexdigest('SHA256', ENV['AWS_SECRET'], model.id.to_s)
"#{token}.#{file.extension}"
end
end
#csv is the wave 1-5 files for centers.
childcare = Childcare.first
CSV.parse(csv, headers: true).each_with_index do |row, index|
center_kindercare_id = row['Location ID']
region_id = row['Location Region'].to_i
district_id = row['Location District'].to_i
label = construct_region_label(region_id: region_id, district_id: district_id)
region = Region.where(label: label).first_or_create! do |r|
r.childcare_id = childcare.id
@Hamada92
Hamada92 / gist:24f9f521bdf2bac7830c5b3f1cd81dac
Created April 10, 2017 13:28
Kafka 0.8 and Zookeeper installation on El Capitan
visit https://kafka.apache.org/downloads
download 0.8.0 Release (Binary Download)
cd /tmp
cp ~/Downloads/kafka_2.8.0-0.8.0.tar.gz .
tar -zxvf kafka_2.8.0-0.8.0.tar.gz -C /usr/local/
sbt update
sbt package
cd /usr/local/kafka_2.8.0-0.8.0
bin/zookeeper-server-start.sh config/zookeeper.properties
bin/kafka-server-start.sh config/server.properties