Skip to content

Instantly share code, notes, and snippets.

View ukazap's full-sized avatar

Ukaza Perdana ukazap

View GitHub Profile
@ukazap
ukazap / UFW_ban_country.md
Created November 1, 2023 12:34 — forked from jasonruyle/UFW_ban_country.md
UFW to block countries
@ukazap
ukazap / observer.md
Created July 19, 2022 04:31 — forked from pnc/observer.md
Using Erlang observer/appmon remotely

Using OTP's observer (appmon replacement) remotely

$ ssh remote-host "epmd -names"
epmd: up and running on port 4369 with data:
name some_node at port 58769

Note the running on port for epmd itself and the port of the node you're interested in debugging. Reconnect to the remote host with these ports forwarded:

$ ssh -L 4369:localhost:4369 -L 58769:localhost:58769 remote-host
@ukazap
ukazap / ubuntu-20.04-macbook-pro.md
Created January 10, 2021 12:47 — forked from johnjeffers/ubuntu-20.04-macbook-pro.md
Ubuntu 20.04 on a 15" Retina MacBook Pro (Mid-2014)

Ubuntu 20.04 on a 15" Retina MacBook Pro (Mid-2014)

These are notes from my efforts to get Ubuntu 20.04 installed on my older MacBook Pro. I'm making this gist public in the hopes that it's helpful to others.

I did a Minimal install, but selected the option to install additional 3rd-party drivers.

Wifi doesn't work during the install (because it requires a 3rd-party driver), so you won't be able to choose to download updates while installing. No big deal, run a software update after the install.

The installer takes about 25 minutes to complete. Post-install, most things work. The only driver I had to manually install was for the FaceTime camera. More on that below.

@ukazap
ukazap / environment.js
Created September 24, 2019 01:51 — forked from wingrunr21/environment.js
Simple webpacker server side rendering
const webpack = require('webpack')
const { environment } = require('@rails/webpacker')
// Don't use commons chunk for server_side_render chunk
const entries = environment.toWebpackConfig().entry
const commonsChunkEligible = Object.keys(entries).filter(name => name !== 'server_side_render')
environment.plugins.set('CommonsChunkVendor', new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: (module, count) => {
@ukazap
ukazap / read-access.sql
Created July 4, 2019 07:16 — forked from oinopion/read-access.sql
How to create read only user in PostgreSQL
-- Create a group
CREATE ROLE readaccess;
-- Grant access to existing tables
GRANT USAGE ON SCHEMA public TO readaccess;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readaccess;
-- Grant access to future tables
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readaccess;
@ukazap
ukazap / exponential_backoff.rb
Created March 5, 2019 01:06 — forked from nathanl/exponential_backoff.rb
Exponential backoff in Ruby
# Exponential backoff in Ruby
begin
make_request
rescue RequestError => e
if retries <= max_retries
retries += 1
sleep 2 ** retries
retry
else
raise "Timeout: #{e.message}"
@ukazap
ukazap / model_extension.rb
Created October 18, 2018 06:28 — forked from brenes/model_extension.rb
Removing validation of a model declared on a gem
# We have to remove validations on email, as it's no longer needed.
# Based on a solution found at http://stackoverflow.com/questions/7545938/how-to-remove-validation-using-instance-eval-clause-in-rails
Model.class_eval do
_validators.reject!{ |key, _| key == :field }
_validate_callbacks.each do |callback|
callback.raw_filter.attributes.delete :field
end
@ukazap
ukazap / cloud-sql-proxy.service
Created October 15, 2018 03:25 — forked from goodwill/cloud-sql-proxy.service
Example Systemd file for starting cloud sql proxy at system start
[Install]
WantedBy=multi-user.target
[Unit]
Description=Google Cloud Compute Engine SQL Proxy
Requires=networking.service
After=networking.service
[Service]
Type=simple
@ukazap
ukazap / rails_locking.md
Created September 27, 2018 00:44 — forked from ryanermita/rails_locking.md
Optimistic and Pessimistic Locking in Rails

Optimistic Locking assumes that a database transaction conflict is very rare to happen. It uses a version number of the record to track the changes. It raise an error when other user tries to update the record while it is lock.

usage

Just add a lock_version column to the table you want to place the lock and Rails will automatically check this column before updating the record.

Pessimistic locking assumes that database transaction conflict is very likely to happen. It locks the record until the transaction is done. If the record is currently lock and the other user make a transaction, that second transaction will wait until the lock in first transaction is release.

usage

@ukazap
ukazap / steps.md
Created September 24, 2018 04:27 — forked from kyptin/steps.md
Accessing a rails console in Google App Engine (flexible)

If you're running a Rails app in Google App Engine's flexible environment, it takes a bit of setup to get to a rails console attached to your deployed environment. I wanted to document the steps for my own reference and also as an aid to others.

  1. Open the Google App Engine -> instances section of the Google Cloud Platform (GCP) console.

  2. Select the "SSH" drop-down for a running instance. (Which instance? Both of my instances are in the same cluster, and both are running Rails, so it didn't matter for me. YMMV.) You have a choice about how to connect via ssh.

    1. Choose "Open in browser window" to open a web-based SSH session, which is convenient but potentially awkward.

    2. Choose "View gcloud command" to view and copy a gcloud command that you can use from a terminal, which lets you use your favorite terminal app but may require the extra steps of installing the gcloud command and authenticating the gcloud command with GCP.