-
Collecting material: For a number of topics that I may write about in the future, I have text files where I collect information as I come across it during coding, on the web, on Twitter, etc.
-
Outline: The collected material is my starting point. I rearrange it into an outline which I refine until I’m happy with it. Refining includes adding/removing/rearranging items and doing more research when I notice gaps in my knowledge.
-
Skeletal draft: I add bullet points and code examples until almost all of the content exists at least in skeletal form. This process often uncovers knowledge gaps and flaws in the structure of the content which I then can fix.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Stick this in your home directory and point your Global Git config at it by running: | |
# | |
# $ git config --global core.attributesfile ~/.gitattributes | |
# | |
# See https://tekin.co.uk/2020/10/better-git-diff-output-for-ruby-python-elixir-and-more for more details | |
*.c diff=cpp | |
*.h diff=cpp | |
*.c++ diff=cpp | |
*.h++ diff=cpp |
For MacOS Catalina, visit Install mysql2 on MacOS Catalina
Installing mysql2
gem errors on MacOS Mojave.
Make sure openssl
is installed on Mac via Homebrew.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
# usage: | |
# $ das_download.rb email password | |
# based on various gists from this thread https://gist.github.com/maca/1798070 | |
require "mechanize" | |
require "fileutils" | |
class DasDownloader | |
attr_reader :agent, :email, :password |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; without composition | |
(repeat 2 (apply * (map #(* 3 %) (map max [1 2] [4 5])))) | |
;; with composition | |
((comp (partial repeat 2) | |
(partial apply *) | |
(partial map (partial * 3))) | |
(map max [1 2] [4 5])) | |
;; with thread macro |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/jobs/example_job.rb | |
class ExampleJob < ActiveJob::Base | |
queue_as :default | |
rescue_from(ActiveRecord::RecordNotFound) do | |
retry_job wait: 1.minute, queue: :default | |
end | |
def perform(param_1, param_2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_record/log_subscriber' | |
class SlowQueryLog < ActiveSupport::LogSubscriber | |
if Rails.configuration.respond_to?(:slow_query_log_threshold_in_ms) | |
if @@threshold = Rails.configuration.slow_query_log_threshold_in_ms | |
@@threshold = @@threshold.to_i == 0 ? nil : @@threshold.to_i | |
end | |
else | |
@@threshold = nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#$null_stream = $stdout | |
$null_stream = File.open(File::NULL, 'w') | |
require 'rspec' | |
def start_runner | |
RSpec::Core::Runner.run [], $null_stream, $null_stream | |
end | |
tp = TracePoint.new(:inline_cache_hit, :inline_cache_miss) do |x| | |
p x.event |
You won’t find rants on how functional programming improves you, your sanity and your life overall here. There are some examples in the very beginning to save you some time on reading the whole post, just come along if you don’t like how they look like.
By the way, this is not even a blog, so formally this is not even a blog post. This is not a library or a new paradigm. It’s just a few pieces of code that might come handy for your daily job.
Example:
[1, 3.14, -4].map &_.safe{ magnitude odd? } # => [true, nil, false]
NewerOlder