My software’s language had to be switched from English to Japanese in Docker mysql. My server is ubuntu.
Conclusion
# Dockerfile
RUN apt-get update && apt-get install -y locales \
&& sed -i -e 's/# \(ja_JP.UTF-8\)/\1/' /etc/locale.gen \
&& locale-gen \
&& update-locale LANG=ja_JP.UTF-8
It is possible to replace characters by…
Sometimes, we need data sandbox in take tasks such as load testing. When I was assigned to the development of load testing, I used this way.
ActiveRecord::Base.connection.begin_transaction # sandbox data
User.create(name: 'John Doe')ActiveRecord::Base.connection.rollback_transaction
In this case, a user is created, but the data is deleted after rollback_transaction.
My LinkedIn account is below! Please contact me!
https://www.linkedin.com/in/tomoharu-tsutsumi-56051a126/
We sometimes want to develop global function which is common in software. For example, it is a function that notifies users of errors. In that case, we can use window object.
import notify from 'path/to/notify'window.notify = notifyfunction a () {
notify()
}
function b () {
notify()
}
My LinkedIn account is below! Please contact me!
https://www.linkedin.com/in/tomoharu-tsutsumi-56051a126/
Basically, while writing ruby codes, I avoid using inheritance because inheritance sometimes produce unnecessary tight couplings.
Example
class Vehicle
def start_engine
end def stop_engine
end
end
class Car < Vehicle
def drive
start_engine
stop_engine
end
end
In this case, Car class knows about the codes of Vehicle class. If we create objects that don’t use an engine, it will necessary to take much time to change the codes.
Solution
We should use compositions. In other words, we should define Engine object.
class Car
def initialize
@engine = Engine.new
end def drive
@engine.start
@engine.stop
end
end class Engine
def start
end def stop
end
end
In this case, Engine class was separated from Car class. Moreover, it has become easy to make new objects that don’t use an engine.