Skip to content

Instantly share code, notes, and snippets.

View ukazap's full-sized avatar

Ukaza Perdana ukazap

View GitHub Profile
@ukazap
ukazap / Dockerfile
Last active May 19, 2019 14:14
Debian Stretch + Ruby 2.6.3 + Nodejs + Yarn + Google Cloud SDK
FROM bitnami/ruby:2.6.3
ARG DEBIAN_VERSION="stretch"
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - && \
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | \
tee /etc/apt/sources.list.d/yarn.list && \
echo "deb http://packages.cloud.google.com/apt cloud-sdk-$DEBIAN_VERSION main" | \
tee -a /etc/apt/sources.list.d/google-cloud-sdk.list && \
@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}"
class Array
def my_map
self.reduce([]) do |new_array, element|
new_array.push(yield(element))
end
end
end
[1, 2, 3].my_map { |x| x * 2 }
#=> [2, 4, 6]
@ukazap
ukazap / import_csv.rb
Last active December 2, 2018 13:39
Import passwords from a CSV file to password store (https://www.passwordstore.org)
# Put this script in ~/.password-store alongside import.csv
# This script requires the CSV to have these columns:
# `title`, `username`, `password`, `additional_secret`
require "csv"
require "fileutils"
require "gpgme" # gem install gpgme
gpg_recipients = "hello@ukazap.space"
@ukazap
ukazap / Dockerfile
Created November 27, 2018 11:13
Tried and true Dockerfile for custom Rails 5 runtime in Google App Engine
# This Dockerfile for a Ruby application was generated by gcloud.
# The base Dockerfile installs:
# * A number of packages needed by the Ruby runtime and by gems
# commonly used in Ruby web apps (such as libsqlite3)
# * A recent version of NodeJS
# * A recent version of the standard Ruby runtime to use by default
# * The bundler gem
FROM gcr.io/google-appengine/ruby:latest
@ukazap
ukazap / perpanjang sim.md
Created October 23, 2018 03:06
Perpanjang SIM C

Persyaratan perpanjangan SIM C, tes psikotes jalan gunung Sanghyang seberang pohon besar 90, surat keterangan sehat cari di Gunung Guntur 25.

@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.