Skip to content

Instantly share code, notes, and snippets.

@opan
opan / pgmetrics.json
Created February 25, 2020 03:44
Sample output from pgmetrics tools in JSON format
{
"meta": {
"version": "1.7",
"at": 1582601656,
"collected_dbs": [
"postgres"
],
"local": true
},
"start_time": 1582527353,
@opan
opan / Vagrantfile-etcd.rb
Last active August 21, 2019 04:47
Vagrantfile for setup Vault and ETCD
# -*- mode: ruby -*-
# vi: set ft=ruby :
$install_go = <<-SCRIPT
sudo apt-get update -y
wget https://dl.google.com/go/go1.12.7.linux-amd64.tar.gz
sudo tar -xvf go1.12.7.linux-amd64.tar.gz
sudo mv go /usr/local
cd ~
@opan
opan / postgresql-slave-volume
Created May 13, 2019 09:42
Setup postgreSQL slave volumn
# Check whether EBS volume already attached
lsblk
# Check EBS volume filesystem
sudo file -s /dev/xvdf
# If type of filesystem still 'data' it means no filesystem yet, we have to create it
sudo mkfs -t ext4 /dev/xvdf
@opan
opan / create-read-only-access.sql
Created May 13, 2019 06:42 — forked from ekarisky/create-read-only-access.sql
How to create read only user in PostgreSQL
-- Create a group with read-only access
CREATE ROLE readonly;
-- Grant access on public sheme to existing tables
GRANT USAGE ON SCHEMA public TO readonly;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readonly; -- grant access to future tables
-- Grant access to specific database, repeat code below for each database
GRANT CONNECT ON DATABASE db_name to readonly;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO readonly; -- grant access to future tables
@opan
opan / README-Template.md
Created March 26, 2018 03:23 — forked from PurpleBooth/README-Template.md
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@opan
opan / palindrome_prime_number_lazy.rb
Last active February 19, 2017 03:28
Generate palindromic prime numbers using Enum#lazy method
n = gets.to_i
# Get infinity list of number
2.upto(Float::INFINITY)
# Use Enum#lazy method
.lazy
# Find prime number
.select { |i| (2..Math.sqrt(i)).none? { |a| (i % a).zero? }}
# Limit infinity list of number by 200
.first(200)
# Find palindrome prime number
@opan
opan / ROT13 Algorithm in Ruby
Last active February 3, 2017 03:20
Solving ROT13 Algorithm logic in Ruby
#!/usr/bin/env ruby
str = "Jul qvq gur puvpxra pebff gur ebnq?"
def rot13(secret_messages)
upcase_alphabet = ("A".."Z").to_a
downcase_alphabet = ("a".."z").to_a
upcase_rot13 = []
upcase_length = upcase_alphabet.length
downcase_length = downcase_alphabet.length
@opan
opan / regex-japanese.txt
Created February 1, 2017 13:41 — forked from terrancesnyder/regex-japanese.txt
Regex for Japanese
Regex for matching ALL Japanese common & uncommon Kanji (4e00 – 9fcf) ~ The Big Kahuna!
([一-龯])
Regex for matching Hirgana or Katakana
([ぁ-んァ-ン])
Regex for matching Non-Hirgana or Non-Katakana
([^ぁ-んァ-ン])
Regex for matching Hirgana or Katakana or basic punctuation (、。’)
@opan
opan / yardoc_cheatsheet.md
Created September 7, 2016 13:12 — forked from chetan/yardoc_cheatsheet.md
YARD cheatsheet

YARD CHEATSHEET http://yardoc.org

cribbed from http://pastebin.com/xgzeAmBn

Templates to remind you of the options and formatting for the different types of objects you might want to document using YARD.

Modules

Namespace for classes and modules that handle serving documentation over HTTP

@opan
opan / rspec test model and controller examples
Created January 18, 2016 14:13
rspec test model and controller examples. Opan Mustopah
# start model test
require "spec_helper"
module Mesin
describe User do
before do
@customer = create(:role, :customer)
@super_admin = create(:role, :super_admin)
end