A (more) complete cheatsheet for Arel, including NamedFunction functions, raw SQL and window functions.
posts = Arel::Table.new(:posts)
posts = Post.arel_table # ActiveRecord| import Base from "controllers/base"; | |
| export default class extends Base { | |
| static targets = ["checkbox", "toggler", "count", "menu", "hide"]; | |
| mount() { | |
| this.on("turbo:morph", document, this.update); | |
| this.on("click", this.togglerTarget, this.toggle); | |
| } |
| # frozen_string_literal: true | |
| class ApplicationService | |
| def self.call(...) | |
| new(...).call | |
| end | |
| def initialize(...) | |
| end | |
| end |
| # frozen_string_literal: true | |
| # RE: https://github.com/rails/rails/issues/50776#issuecomment-2148033957 | |
| require "bundler/inline" | |
| gemfile(true) do | |
| source "https://rubygems.org" | |
| gem "rails", "7.1.3.3" |
| /* | |
| ERB template chunk from The Feed's display of emails: | |
| <section class="postings postings--feed-style" id="postings" | |
| data-controller="pagination" data-pagination-root-margin-value="40px"> | |
| <%= render partial: "postings/snippet", collection: @page.records, as: :posting, cached: true %> | |
| <%= link_to(spinner_tag, url_for(page: @page.next_param), | |
| class: "pagination-link", data: { pagination_target: "nextPageLink", preload: @page.first? }) unless @page.last? %> | |
| </section> |
| package csrf | |
| import "errors" | |
| // This is just an example on how to reduce redundant code in Go | |
| // Original file: https://github.com/gofiber/csrf/blob/dde96da6711a2cc01709a66730c2e16328b22047/main.go | |
| // csrfFromExtractor returns a function can be used to bind to a parameter name to extract a csrf token from a Ctx. | |
| func csrfFromExtractor(errMessage string, extractor func(c *fiber.Ctx, param string) string) func(string) func(c *fiber.Ctx) (string, error) { | |
| return func(param string) func(c *fiber.Ctx) (string, error) { |
Concurrency is a domain I have wanted to explore for a long time because the locks and the race conditions have always intimidated me. I recall somebody suggesting concurrency patterns in golang because they said "you share the data and not the variables".
Amused by that, I searched for "concurrency in golang" and bumped into this awesome slide by Rob Pike: https://talks.golang.org/2012/waza.slide#1 which does a great job of explaining channels, concurrency patterns and a mini-architecture of load-balancer (also explains the above one-liner).
Let's dig in:
Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...
// see: https://github.com/chadoe/docker-cleanup-volumes
$ docker volume rm $(docker volume ls -qf dangling=true)
$ docker volume ls -qf dangling=true | xargs -r docker volume rm
| # Original Rails controller and action | |
| class EmployeesController < ApplicationController | |
| def create | |
| @employee = Employee.new(employee_params) | |
| if @employee.save | |
| redirect_to @employee, notice: "Employee #{@employee.name} created" | |
| else | |
| render :new | |
| end |
| # Thee will be more information here when I share the entire problem space I'm working on, but | |
| # in short, this is preview material for my second talk in a series called "What Computer Scientists Know". | |
| # The first talk is on recursion, and goes through several examples., leading up to a problem based | |
| # on a simple puzzle that initial estimates based on performance of a previous puzzle would take years | |
| # to solve on modern computers with the techniques shown in Ruby. That sets the stage for improving the | |
| # performance of that problem with threading, concurrency, and related tuning. | |
| # | |
| # The second talk is on threading and concurrency, touching on algorithmic performance as well. | |
| # Using some knowledge of the problem (board symmetry, illegal moves, etc), we reduce the problem space | |
| # to about .5% of what we initially thought it was. Still, the initial single threaded solution took more |