Skip to content

Instantly share code, notes, and snippets.

View glaszig's full-sized avatar

glaszig

  • available for hire. contact me.
  • remote
View GitHub Profile
@michelson
michelson / async_method_job.rb
Created April 23, 2024 01:50
Asynchronously Concern
class AsyncMethodJob < ApplicationJob
queue_as :default
def perform(target:, method_name:, args:, queue_name: :default)
self.class.queue_as(queue_name)
# `target` could be either an instance or a class
target = target.constantize if target.is_a?(String) # Convert class name to class object if needed
target.send(method_name, *args)
end
end
@skoqaq
skoqaq / build4123.sublime4.key
Last active July 20, 2024 14:46
Sublime Text 4 License Key
—– BEGIN LICENSE —–
Mifeng User
Single User License
EA7E-1184812
C0DAA9CD 6BE825B5 FF935692 1750523A
EDF59D3F A3BD6C96 F8D33866 3F1CCCEA
1C25BE4D 25B1C4CC 5110C20E 5246CC42
D232C83B C99CCC42 0E32890C B6CBF018
B1D4C178 2F9DDB16 ABAA74E5 95304BEF
9D0CCFA9 8AF8F8E2 1E0A955E 4771A576
@nikokozak
nikokozak / template.ex
Created January 13, 2022 22:09
Naive re-implementation of Phoenix's templating macros.
defmodule Lector.Template do
@moduledoc """
Defines helper functions for rendering Templates.
What this allows is a naive re-implementation of how Phoenix handles views/templates.
When 'using' `Lector.Template`, files sharing the same module name as the view being used get pre-compiled
into named render functions. In other words, `Lector.Templates.Home` will pre-compile a `home.html.eex` file
in the same folder into a function of the same name (`Lector.Templates.Home.home(assigns)`), which renders
the template.
defmodule Acme.Repo do
use Ecto.Repo,
otp_app: :acme,
adapter: Ecto.Adapters.Postgres
def with_prefix(prefix) do
module_atom = Module.concat([Acme, Repo, WithPrefix, Macro.camelize(prefix)])
# We could not find a better way to see if this module already existed
if !Kernel.function_exported?(module_atom, :prefix, 0) do
@elpescador-nl
elpescador-nl / Build_nginx_brotli_FreeBSD.md
Created April 28, 2020 13:51
Build nginx with brotli support on FreeBSD
@dsazup
dsazup / app\Providers\AppServiceProvider.php
Created April 14, 2020 17:27
Laravel response()->to()
<?php
namespace App\Providers;
use Illuminate\Routing\ResponseFactory;
use Illuminate\Support\ServiceProvider;
use Illuminate\Contracts\Support\Responsable;
use Illuminate\Contracts\View\Factory as ViewFactoryContract;
use Illuminate\Contracts\Routing\ResponseFactory as ResponseFactoryContract;
@dsabanin
dsabanin / enable-xcode-debug-menu.sh
Last active November 7, 2022 16:17
Enable internal Xcode debug menu in Xcode 11
defaults write com.apple.dt.Xcode ShowDVTDebugMenu -bool YES
sudo mkdir -p /Applications/Xcode.app/Contents/Developer/AppleInternal/Library/Xcode
sudo touch /Applications/Xcode.app/Contents/Developer/AppleInternal/Library/Xcode/AppleInternal.plist
# Don't forget to restart Xcode
@fabiotatsuo
fabiotatsuo / rust.md
Last active May 20, 2024 00:03
Install Rust, Cargo and Rustup Toolchain inside FreeBSD 12 Jail
  1. Install rust

    jail-app is name of jail.

    $ jexec jail-app
    $ pkg install curl
    

    Download and install rustup
    $ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

@absyah
absyah / A helpful ActiveRecord setting only 1 person has ever used
Created August 2, 2019 03:23
Nate Berkopec's Ruby Performance Newsletters
A memory-saving ActiveRecord setting has been used by just one application ever, according to GitHub
There's a common performance problem in many Rails background jobs.
Background jobs often do operations across large sets of data. Basically, they do silly things like User.all.each(&:send_daily_newsletter).
So, there's a problem with that query. In development and test environments, User.all will probably return a few rows, maybe a dozen at most. Most developers have extremely limited seed data on their local machines.
In production, however, User.all will probably return quite a few rows. Depending on the app you work on, maybe a few hundred thousand.
There's a tiiiiiny issue with a result set that returns 100,000 rows, and it's not just that the SQL query will take a long time to return. It will have irreversible effects on your Ruby app too!
@supairish
supairish / capybara.rb
Created February 23, 2019 07:10 — forked from guzart/capybara.rb
Capybara configuration to run a webpack dev server for e2e testing
# spec/support/capybara.rb
require 'capybara/rails'
require 'capybara/rspec'
# port and url to webpack server
WEB_TEST_PORT = '5005'.freeze
WEB_TEST_URL = "http://localhost:#{WEB_TEST_PORT}".freeze
def capybara_wait_for_webpack_server
10.times.each do |_|