Skip to content

Instantly share code, notes, and snippets.

View mmasashi's full-sized avatar

Masashi mmasashi

View GitHub Profile
@mmasashi
mmasashi / install_mysql_server.md
Last active April 26, 2024 01:37
How to install mysql-server from source code

Install MySQL

Install dependencies

sudo yum install ncurses-devel

Download MySQL source code

@mmasashi
mmasashi / downgrade_rubygems.sh
Created January 3, 2014 19:48
Downgrade rubygems version.
$ gem -v
2.0.3
$ gem list rubygems-update
$ gem uninstall -v 2.0.3 rubygems-update
$ gem install -v 1.8.24 rubygems-update
$ update_rubygems
$ gem -v
1.8.24
@mmasashi
mmasashi / test_patch.py
Last active August 22, 2023 12:33
Behavior of mock, patch, pytest mocker, examples
import contextlib
import pytest
from unittest.mock import patch
class A(object):
def say(self, msg):
return f'A say {msg!r}.'
@contextlib.contextmanager
r53 = AWS::Route53.new(
:access_key_id => 'aws-key-id',
:secret_access_key => 'aws-secret-key')
response = r53.client.list_resource_record_sets(
:hosted_zone_id => "zone-id",
:start_record_name => 'xxx.example.com',
:start_record_type => 'CNAME'
)
puts response[:resource_record_sets].map{|r| r[:name]}
@mmasashi
mmasashi / num_commits_per_day.sql
Created December 2, 2014 23:32
Number of commits per day (Amazon Redshift)
select trunc(startwork), count(distinct xid) from stl_commit_stats where xid > 0 group by trunc(startwork) order by 1;
@mmasashi
mmasashi / README.md
Last active May 1, 2021 10:38
Install Oracle instant client (sqlplus) v12.1 on MacOSX

Install Oracle instant client (sqlplus) on MacOSX

  1. Get Oracle instant client for MacOSX
  1. Unarchive downloaded zip files into a same directory
  • ex: $HOME/Downloads/instantclient_12_1
  1. Create install.sh and copy the following code and past it on that file.
@mmasashi
mmasashi / delete_dup_records_redshift.rb
Last active August 31, 2020 22:04
Duplicate Record Delete Query Generator For Amazon Redshift
# Duplicate record delete query generator for Amazon Redshift
# By running a generated query, duplicate rows in a specified table will be removed.
#
# Usage:
# ruby delete_dup_records_redshift.rb <table-name> <priary-keys-with-comma-separator>
unless ARGV.count == 2
puts <<EOT
Usage:
ruby delete_dup_records_redshift.rb <table name> <primary keys>
@mmasashi
mmasashi / example_query.txt
Last active July 9, 2020 22:10
Get primary key columns on PostgreSQL/Amazon Redshift
-- Get primary keys for "fsb_schema_7_7379bca4"."m_test_table_multi_pk"
SELECT
f.attnum AS number,
c.relname AS table_name,
f.attname AS column_name
FROM pg_attribute f
JOIN pg_class c ON c.oid = f.attrelid
JOIN pg_type t ON t.oid = f.atttypid
LEFT JOIN pg_attrdef d ON d.adrelid = c.oid AND d.adnum = f.attnum
@mmasashi
mmasashi / exit_code_matches.rb
Last active May 26, 2020 19:43 — forked from stevenharman/exit_code_matches.rb
Exit code matcher for rspec 3
RSpec::Matchers.define :terminate do |code|
actual = nil
def supports_block_expectations?
true
end
match do |block|
begin
block.call
@mmasashi
mmasashi / creaet_read_only_user.sql
Created November 14, 2016 20:24
Create read-only user on MySQL
CREATE USER r_only_user identified by 'password';
GRANT SELECT, SHOW VIEW, PROCESS, REPLICATION CLIENT ON *.* TO 'r_only_user'@'%' IDENTIFIED BY 'password';
GRANT SELECT, SHOW VIEW, PROCESS, REPLICATION CLIENT ON *.* TO 'r_only_user'@'localhost' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;