Skip to content

Instantly share code, notes, and snippets.

View zentetsukenz's full-sized avatar
📷

Wiwatta Mongkhonchit zentetsukenz

📷
  • Opn
  • Bangkok, Thailand
View GitHub Profile
@zentetsukenz
zentetsukenz / javascript_array_pluck.js
Created October 3, 2015 11:25
Javascript simple array pluck
function pluck (arrayOfObject, property) {
return arrayOfObject.map(function (item) {
return item[property];
});
};
ActiveRecord::Base.transaction do
100.times do |i|
Item.create({
name: "item #{i + 1}"
})
end
end
add_foreign_key :source_table_name, :target_table_name, column: :explicit_column_name
@zentetsukenz
zentetsukenz / ruby_sum_array_of_object.rb
Created February 1, 2016 11:37
Sum array of object
array_of_objects.map { |object| object.field_to_sum }.inject(:+)
@zentetsukenz
zentetsukenz / ruby_hash_value_mismatch.rb
Created February 2, 2016 11:20
Find mismatch value between 2 hash
def find_mismatch_value_between_hash(a, b)
pivot_hash = a
another_hash = b
result_hash = {}
pivot_hash.keys.each do |k|
pivot_value = pivot_hash[k]
another_value = another_hash[k]
@zentetsukenz
zentetsukenz / benchmarking.rb
Created February 8, 2016 05:05
Benchmark somethings and get the raw result in file
# gem install ascii_charts # if necessary
require 'ascii_charts'
require 'benchmark'
require './test.rb'
include Benchmark
class Runner
def self.run
new.run
@zentetsukenz
zentetsukenz / ruby_sum_object_array.rb
Last active February 23, 2016 17:14
Ruby sum array of object map reduce style
Class A
attr_accessor :name, :value
def initialize
@value = rand(10)
@name = "Mr. #{@value}_#{rand(100)}"
end
end
a = Array.new(10).collect { |e| e = A.new }

Keybase proof

I hereby claim:

  • I am zentetsukenz on github.
  • I am zentetsuken (https://keybase.io/zentetsuken) on keybase.
  • I have a public key whose fingerprint is A806 B364 D7DA 20B7 6823 313B D576 6A02 170C 4847

To claim this, I am signing this object:

@zentetsukenz
zentetsukenz / ruby_on_rails_deployment.md
Last active September 22, 2023 18:32
Deploy Ruby on Rails application with Docker Compose and Capistrano with ease

Docker

Files and Folders.

|
|\_ app
|...
|\_ docker
| |
@zentetsukenz
zentetsukenz / connect_to_host_database_from_docker.md
Last active December 4, 2022 13:48
Step of how to connect to host database from Docker network

Connect to host database

  1. Create new database user with password for docker.
  2. Configure postgresql.conf to listen for connection from docker network which usually is 172.17.0.0/16. The file's usually located at /usr/local/var/postgres/postgresql.conf for Mac OS X.

Example, add this entry into postgresql.conf file.

listen_addresses = '172.17.0.0/16, localhost'