Skip to content

Instantly share code, notes, and snippets.

View ukazap's full-sized avatar

Ukaza Perdana ukazap

View GitHub Profile
@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 / ping_pong.rb
Last active September 7, 2019 02:21
Rack middleware for GAE health check without a trip to DB
module PingPong # App Engine health check without a trip to DB
class Middleware
def initialize app, ping_path = '/status'
@app = app
@ping_path = ping_path
Rails.backtrace_cleaner.add_silencer { |line| line =~ /#{File.basename(__FILE__)}/ }
end
def pong_code
200
@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 / 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