Skip to content

Instantly share code, notes, and snippets.

View quatermain's full-sized avatar

Oliver Kriška quatermain

  • Slovakia
View GitHub Profile
@wolves
wolves / tasks.ex
Last active April 1, 2022 14:05
Elixir curl Github API
repo_data = [name: "asdf"]
{status, result} = JSON.encode(repo_data)
IO.puts "RESULT: #{result}"
case System.cmd "curl", ["-XPOST", "-H", "Authorization: token #{github_token}", "https://api.github.com/user/repos", "-d", "#{result}"] do
{output, 0} -> IO.puts "#{output}"
{err, code} -> {:error, %Raygun.Error{message: err, command: "new", code: code}}
end
@kinopyo
kinopyo / custom_logger.rb
Created October 11, 2011 15:40
Custom logger file in Rails
# lib/custom_logger.rb
class CustomLogger < Logger
def format_message(severity, timestamp, progname, msg)
"#{timestamp.to_formatted_s(:db)} #{severity} #{msg}\n"
end
end
logfile = File.open("#{Rails.root}/log/custom.log", 'a') # create log file
logfile.sync = true # automatically flushes data to file
CUSTOM_LOGGER = CustomLogger.new(logfile) # constant accessible anywhere
@dimus
dimus / Hash.from_xml using Nokogiri
Created March 17, 2010 14:29
Adding Hash.from_xml method using Nokogiri
# USAGE: Hash.from_xml:(YOUR_XML_STRING)
require 'nokogiri'
# modified from http://stackoverflow.com/questions/1230741/convert-a-nokogiri-document-to-a-ruby-hash/1231297#1231297
class Hash
class << self
def from_xml(xml_io)
begin
result = Nokogiri::XML(xml_io)
return { result.root.name.to_sym => xml_node_to_hash(result.root)}