Skip to content

Instantly share code, notes, and snippets.

View Chocksy's full-sized avatar
🏠
Working from home

Ciocanel Razvan Chocksy

🏠
Working from home
View GitHub Profile
@Chocksy
Chocksy / Makefile
Last active July 12, 2024 02:41
Docker for Rails + Puma + Nginx + Pagespeed + PostgreSQL + Redis + Memcached on Heroku | https://blog.epicpxls.com/docker-for-rails-puma-nginx-pagespeed-postgresql-redis-memcached-on-heroku-3272d88968f4
# Build the whole docker images.
# - we first copy all the variables from the figaro yml file to a .env file
# - then we build the docker images
# - we start the images
# - we create the database
# Call this with:
# - make build
build:
@ruby docker/env_vars.rb
@docker compose build
@Chocksy
Chocksy / cloudflare.rb
Created April 18, 2021 10:53
Simple adapter class that talks with Cloudflare API to allow for cache purge. It uses faraday for requests.
# frozen_string_literal: true
# Cloudflare adapter to help us communicate with the cloudflare API.
# Usage:
# cloudflare = Cloudflare.new(zone: '123', api_key: '2323', email: '[email protected]')
# cloudflare.purge_everything
# cloudflare.zones
class Cloudflare
CLOUDFLARE_API_ENDPOINT = 'https://api.cloudflare.com/client/v4'
@Chocksy
Chocksy / email_previews.rb
Last active April 2, 2021 18:45 — forked from Lukom/email_previews.rb
Preview Emails in ActiveAdmin / Rails 5.1
-# app/admin/email_previews.rb
# frozen_string_literal: true
ActiveAdmin.register_page 'Email Previews' do
menu parent: 'dashboard', priority: 10
content do
div 'Select a mailer from the sidebar.'
end
@Chocksy
Chocksy / .1details.md
Created June 3, 2020 12:34
Use Gemfile.local for puma-dev implementation
@Chocksy
Chocksy / ahoy_visit_geocode.rb
Last active April 23, 2020 14:27
Process ahoy visits geocode information. We can use this to retry previous visits that have no location data.
# Get all visits that have `ip` set and no `country`, `city`, `latitude` & `longitude` set.
# Schedule background jobs to process each visit and update it.
Visit.where.not(ip: nil).where(country: nil, city: nil, latitude: nil, longitude: nil).find_each { |visit| Ahoy::GeocodeJob.set(queue: Ahoy.job_queue).perform_later(visit) }
@Chocksy
Chocksy / db_migration.md
Last active March 3, 2020 12:53
Wordpress DB migration (via queries)

DB migration WP

  • export the wp_posts, wp_postmeta tables from the old DB.
  • import the exported data into 2 new tables wp_old_posts, wp_old_postmeta into the new DB.
  • change collation on the table from utf8mb4_unicode_ci to utf8mb4_unicode_520_ci
  • add to the current/new table a column old_id (to store the id of the row in the old table. In our case wp_posts)
  • make a similar query to this:
INSERT INTO wp_posts (old_id, post_author, post_date, post_date_gmt, post_content, post_title, post_excerpt, post_status, comment_status, ping_status, post_password, post_name, to_ping, pinged, post_modified, post_modified_gmt, post_content_filtered, post_parent, guid, menu_order, post_type, post_mime_type, comment_count) 
SELECT * FROM wp_old_posts;
@Chocksy
Chocksy / idea.properties
Last active February 18, 2020 11:24
Rubymine config options
# custom RubyMine properties
editor.zero.latency.typing=true
/**
* Retrieves all the rows in the active spreadsheet that contain data and logs the
* values for each row.
* For more information on using the Spreadsheet API, see
* https://developers.google.com/apps-script/service_spreadsheet
*/
function readRows() {
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var numRows = rows.getNumRows();
@Chocksy
Chocksy / ActiveRecordPluckToHash.rb
Created January 21, 2019 18:44
Add .pluck_to_hash to ActiveRecord. The result will get the columns specified as keys for the hash and their values.
module ActiveRecordPluckToHash
def pluck_to_hash(*keys)
formatted_keys = keys.map do |k|
"'#{k.to_s.split(/\b.\b/i)[-1].strip}', #{k}"
end.join(', ')
pluck(Arel.sql("json_build_object(#{formatted_keys})")).map(&:with_indifferent_access)
end
end
@Chocksy
Chocksy / kill_sidekiq_job.rb
Last active February 20, 2025 02:06
Kill sidekiq jobs by process id for busy jobs and by jid for other sets.
# FOR BUSY JOBS
# take the process_id from the /busy page in sidekiq and kill the longest running one.
workers = Sidekiq::Workers.new
long_process_id = 'integration.3:4:71111aaa111' # Eg: 'integration.3:4:71d1d7f4ef5a'
workers.each do |process_id, thread_id, work|
process = Sidekiq::Process.new('identity' => process_id)
process.stop! if process_id == long_process_id
end
# FOR SCHEDULED JOBS