Skip to content

Instantly share code, notes, and snippets.

View nowlinuxing's full-sized avatar

Loose coupling nowlinuxing

View GitHub Profile
@nowlinuxing
nowlinuxing / .rubocop.yml
Last active December 9, 2018 16:05
Rubocop to sample snippets in ruby-2.5.3
inherit_from: .rubocop_todo.yml
Layout/SpaceBeforeBlockBraces:
Enabled: false
Style/NumericLiterals:
Enabled: false
@nowlinuxing
nowlinuxing / company.rb
Created January 18, 2016 13:23
Use octopus with a master DB with some slaves, and sharded some user DBs
# class CreateCompanies < ActiveRecord::Migration
# def change
# create_table :companies do |t|
# t.string :name
#
# t.timestamps null: false
# end
# end
# end
@nowlinuxing
nowlinuxing / proc_vs_yield.rb
Created July 3, 2015 11:21
Proc#call vs. yield
# Proc#call vs. yield - PB memo <http://d.hatena.ne.jp/nagachika/20111105/proc_call_versus_yield>
require 'benchmark'
n = 1_000_000
def m1
yield :m1
end
@nowlinuxing
nowlinuxing / gist:6bf79c9ad757985854c3
Created June 16, 2015 06:41
How to get the folder list under the specify folder using AWS-SDK v2
require 'aws-sdk'
client = Aws::S3::Client.new(
access_key_id: "your_access_key_id",
secret_access_key: "your_access_key",
)
s3.list_objects(bucket: "your-bucket", prefix: "path/to/folder", delimiter: "/").common_prefixes.map(&:prefix)
@nowlinuxing
nowlinuxing / gist:83ea2ddc50a968e3df65
Last active August 29, 2015 14:18
Copy the Amazon S3 objects between two buckets
# AWS SDK v1
require 'aws-sdk'
AWS.config(:access_key_id => 'foo', :secret_access_key => 'bar')
s3 = AWS::S3.new
key = "path/to/src"
s3.buckets['src_bucket'].objects.with_prefix(key).each do |o|
o.copy_to(o.key, bucket_name: "dst_bucket")
end
@nowlinuxing
nowlinuxing / gist:d452360748f3da54569a
Created January 25, 2015 09:55
Fluentd on Mac OS X
  1. Installation
  • Download DMG
  • Launch
    • sudo launchctl load /Library/LaunchDaemons/td-agent.plist
      • less /var/log/td-agent/td-agent.log
  • Post Sample Log
    • curl -X POST -d 'json={"json":"message"}' http://localhost:8888/debug.test
  • Send to S3
@nowlinuxing
nowlinuxing / import.sh
Created October 1, 2014 03:28
Generate test datas and import to MySQL via tempolary CSV file
#!/bin/sh
DB="some_db"
DB_USER="user"
DB_PASS="pass"
TABLE="users"
CSV_FILE="/tmp/users.csv"
N_RECORD=1000000
@nowlinuxing
nowlinuxing / database_rewinder.rb
Last active May 18, 2017 07:16
Database rewinder with sharding using ar-octopus
# spec/support/database_rewinder.rb
RSpec.configure do |config|
config.before(:suite) do
DatabaseRewinder['test']
Octopus.config[Rails.env].each do |shard, shard_config|
DatabaseRewinder.cleaners << DatabaseRewinder::Cleaner.new(
config: shard_config,
connection_name: shard,
@nowlinuxing
nowlinuxing / gist:104bd3273bae9de86461
Created June 12, 2014 09:58
Dump columns of a table on mysql into a file
SELECT id, name FROM users INTO OUTFILE work/users.tsv