Skip to content

Instantly share code, notes, and snippets.

@ahsandar
ahsandar / json_log_formatter.ex
Last active September 16, 2021 06:04
Elixir log formatter to outout JSON messages to log
defmodule Formatter.Log do
@moduledoc """
This is a good resource to learn about formatters
https://timber.io/blog/the-ultimate-guide-to-logging-in-elixir/
"""
def format(level, message, timestamp, metadata) do
message
|> Jason.decode()
|> case do
@ahsandar
ahsandar / fork_detach.rb
Created June 5, 2020 05:30
backgrond job processing suing ruby process library uses ahsandar/fury to run shell commands
module ForkDetach
def chk_download_complete(job_list)
loop do
process_output = []
job_list.each do | job|
process_output << format_process_output(Fury.run_now("ps ho pid,state -p #{job}"))
end
break if wait_process_completion(process_output)
end
@ahsandar
ahsandar / URI-monkey-patch.rb
Created October 13, 2017 04:38 — forked from psychocandy/URI-monkey-patch.rb
Fix ArgumentError invalid %-encoding for malformed URLs
# The following should prevent an ArgumentError "invalid %-encoding (...%)" exception from being raised for malformed URLs.
# To use this code simply drop this in your rails app initializers.
# See: https://github.com/rack/rack/issues/337
# Taken from: http://stackoverflow.com/a/11162317/1075006
module URI
major, minor, patch = RUBY_VERSION.split('.').map { |v| v.to_i }
@ahsandar
ahsandar / gist:da5b78d01c94e2d5ebea7737a7870b1c
Created October 3, 2017 03:47 — forked from jrochkind/gist:59b6330e3f52710cc49e
Monkey patch to ActiveRecord to forbid
######################
#
# Monkey patch to ActiveRecord to prevent 'implicit' checkouts. Currently tested with Rails 4.0.8, prob
# should work fine in Rails 4.1 too.
#
# If you create a thread yourself, if it uses ActiveRecord objects without
# explicitly checking out a connection, one will still be checked out implicitly.
# If it is never checked back in with `ActiveRecord::Base.clear_active_connections!`,
# then it will be leaked.
#