Skip to content

Instantly share code, notes, and snippets.

View nowlinuxing's full-sized avatar

Loose nowlinuxing

View GitHub Profile
@nowlinuxing
nowlinuxing / gist:7307059
Created November 4, 2013 18:27
Use Twitter via API
# use twitter.gem earlier than 5.0.0
require "pp"
require "twitter"
# 1. Comment out oauth_token and oauth_token_secret.
# 2. Visit https://dev.twitter.com/apps/new. Get consumer_key and consumer_secret.
# 3. Execute.
# 4. Visit the Developper's site agein.
# 5. Go to "settings", and get oauth_token and oauth_token_secret.
@nowlinuxing
nowlinuxing / README
Created May 8, 2014 02:51
Install libxml-ruby-2.3.3 @ Marvericks
I try to install libxml-ruby-2.3.3 at MacOSX Marvericks via gem (rbenv, Ruby-2.1.0), get below errors:
Building native extensions. This could take a while...
ERROR: Error installing libxml-ruby:
ERROR: Failed to build gem native extension.
/Users/***/.rbenv/versions/2.1.0/bin/ruby extconf.rb
extconf.rb:17:in `<main>': Use RbConfig instead of obsolete and deprecated Config.
extconf.rb:17:in `<main>': Use RbConfig instead of obsolete and deprecated Config.
checking for socket() in -lsocket... no
@nowlinuxing
nowlinuxing / gist:b036a3b9913ded4dd35a
Created June 6, 2014 02:17
Install rmagick.gem on MacOSX
http://stackoverflow.com/questions/13963404/rails-and-os-x-how-to-install-rmagick
$ cd `Magick-config --prefix`/lib
$ for f in libMagick*-*.[0-9].dylib; do ln -s $f `echo $f | sed -e 's/-.*\.dylib/.dylib/'`; done
@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
@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 / 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 / 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 / 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: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 / 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