Monday, December 28, 2015

Vì sao trẻ vừa lọt lòng không nên cho tắm ngay?

(ĐSPL) - Ở những giờ đầu tiên sau khi sinh, không nên tắm ngay cho trẻ sơ sinh, bởi nó sẽ ảnh hưởng đến sức đề kháng của trẻ và một số những hệ lụy khác.
Thông thường một đứa trẻ sinh ra, việc làm đầu tiên là bé được tắm rửa sạch sẽ. Nhưng hiện nay, theo xu thế sinh nở mới nhất, trẻ sinh ra không nên tắm luôn mà để đến vài ngày sau. Điều này giống cũng như việc cắt dây rốn muộn.
Vì sao trẻ vừa lọt lòng không nên cho tắm ngay? - Ảnh 1

Nên bỏ qua lần tắm đầu tiên cho trẻ vừa chào đời (trong khoảng 24h sau sinh). Ảnh minh họa.

Dưới đây là những lý do bạn không nên tắm cho trẻ sơ sinh quá sớm trong những giờ đầu tiên mới sinh sau.

Duy trì lớp da bảo vệ tự nhiên cho bé

Được biết, khi ở trong bụng mẹ, bé được bao bọc bởi nước ối. Điều này khiến da bé được phủ một lớp màu trắng để bảo vệ bé khỏi môi trường ngoài, lớp màu trắng này được gọi là vernix. Đó là một trong những lý do bạn không nên tắm ngay cho trẻ sơ sinh.
Giúp da bé thêm khỏe mạnh và dẻo dai
Theo các nghiên cứu, chất venix có tính miễn dịch cao và đây là lợi thế rất lớn của em bé mới sinh. Nó đồng thời là kem dưỡng ẩm giữ cho làn da bé mềm mại và dẻo dai cũng ngăn vi khuẩn xâm nhập.
Đây là nguyên nhân giải thích tại sao trong khoảng 24 giờ sau lần tắm đầu tiên của bé, có những lớp màu trắng đục bong ra. Toàn bộ cơ thể của bé sẽ được lột sạch lớp vernix (nhất là ở trên bàn tay và bàn chân).

Nước ối có vai trò cung cấp vitamin K cho trẻ

Sau khi sinh cơ thể trẻ vẫn còn dính lớp nước ối. Trong nước ối có chứa nhiều loại vi khuẩn có lợi giúp sản xuất vitamin K cung cấp cho trẻ. Vì vậy khi trẻ mới sinh ra, mẹ không nên tắm luôn mà hãy để lại lớp nước ối còn dính trên người bé.
Tăng sự liên kết giữa mẹ và bé
Khi bé chào đời, cần được gần gũi với mẹ, gần nguồn thức ăn nơi bé có thể nghe, ngửi hơi ấm của người mẹ. Vì vậy, nếu tắm cho trẻ quá sớm có thể làm gián đoạn quá trình em bé nhận biết mẹ, bé cảm thấy mất an toàn và có thể ảnh hưởng đến những cữ bú quan trọng đầu tiên.
Vì sao trẻ vừa lọt lòng không nên cho tắm ngay? - Ảnh 2
Ảnh minh họa.

Giúp ổn định nhiệt độ cơ thể

Trẻ vừa mới lọt lòng mẹ đang tìm cách duy trì nhiệt độ cơ thể mình. Nếu cho bé tắm quá sớm, có thể làm cho bé chới với với nhiệt độ mới. Vì điều này, có một số trường hợp, em bé sơ sinh cần đặt dưới đèn nhiệt để lấy lại nhiệt độ sau khi tắm.
Thay vào đó, hãy trì hoãn thời gian tắm, để bé tiếp xúc với mẹ thời gian vừa đủ và quen với nhiệt độ bên ngoài.

Tránh tăng đường huyết và hoóc-môn stress

Khi sinh ra, trẻ đã bị tách khỏi mẹ để đi tắm, trẻ có thể sẽ khóc. Điều này làm cơ thể sản sinh một loại hoóc-môn gây stress để đáp ứng tình hình thực tế. Việc cơ thể phải làm việc căng thẳng hơn khi bé đi tắm cũng khiến bé dễ bị tuột đường huyết. Khi được ở bên mẹ đủ lâu, các cơ quan trong cơ thể bé có khuynh hướng thực hiện tốt chức năng của chúng hơn.
Một số lưu ý khác:
Tốt nhất, cha mẹ nên bỏ qua lần tắm đầu tiên từ sau khi con chào đời (trong khoảng sau khi sinh). Từ lần tắm thứ 2, mẹ hãy tắm chung cùng bé giúp bé cảm thấy rất an toàn khi không bị tách khỏi mẹ. Mẹ nên ôm con cùng ngồi trong bồn tắm, chớ nên thả bé một mình sẽ gây cho bé sự chới với và đơn độc.
Khi tắm, lưu ý sử dụng găng tay để ngăn chặn những vi trùng, vi khuẩn ở môi trường bệnh viện. Một nghiên cứu cho thấy, sử dụng găng tay với trẻ sơ sinh ngay cả khi tắm có tỷ lệ nhiễm trùng rất ít.

http://www.doisongphapluat.com/doi-song/suc-khoe-lam-dep/vi-sao-tre-vua-lot-long-khong-nen-cho-tam-ngay-a126435.html

Friday, December 25, 2015

Tuning Apache2 prefork MaxClients ServerLimit

Apache prefork settings, per apache performance tuning guidelines
quote:
The single biggest hardware issue affecting webserver performance is RAM.
A webserver should never ever have to swap, as swapping increases the latency
of each request beyond a point that users consider "fast enough". 
This causes users to hit stop and reload, further increasing the load.
You can, and should, control the MaxClients setting so that your server does
not spawn so many children it starts swapping. This procedure for doing this
is simple: determine the size of your average Apache process, by looking at
your process list via a tool such as top, and divide this into your total 
available memory, leaving some room for other processes.
you should set it up like this based on your input to:
  • Total Memory : 128 GB 
  • -10% memory for everything except apache: 115 GB
  • Now we need to figure out how much single apache process is using. 
To calculate this you can use following script :
pgrep apache2 | xargs -n1 -I{} cat /proc/{}/smaps | \
  awk '{if ($0 ~ /stack/) {pids+=1} else if ($0 ~/^Shared_/) 
    {shared+=$2} else if ($0 ~ /^Pss:/) {priv+=$2}} END {
      printf "%.2f MB\n",(priv+shared/(pids*pids))/1024}'
This is best estimate of how much single apache process is using memory while trying to proportionally dividing shared usage per number of active apache processes and adding it on top of Pss (proportional set size)
Finally you divide 115 GB with this figure and you get MaxClients/ServerLimit. From here you can relatively calculate other figures like 
  • StartServers 30% of MaxClients
  • MinSpareServers 5% of MaxClients
  • MaxSpareServers 10% of MaxClients
  • ServerLimit == MaxClients
  • MaxRequestsPerChild 10000 (as conservative alternative to address possible problem with memory leaky apps)
http://serverfault.com/questions/644622/tuning-apache2-prefork-maxclients-serverlimit

Saturday, October 10, 2015

delete client connections in redis using lua

Here are Lua script run in redis 2.6

>eval " local str_tmp = redis.call('client', 'list') for k,v in string.gmatch(str_tmp, '(addr)=(IP:%d+)') do redis.call('client', 'kill', v) end return" 0
>script flush

Tuesday, September 29, 2015

Recover MySQL root password

Step # 1 : Stop the MySQL service:
# /etc/init.d/mysql stop
Output:
Stopping MySQL database server: mysqld.
Step # 2: Start the MySQL server w/o password:
# mysqld_safe --skip-grant-tables &
Output:
[1] 5988
Starting mysqld daemon with databases from /var/lib/mysql
mysqld_safe[6025]: started
Step # 3: Connect to the MySQL server using the MySQL client:
# mysql -u root
Output:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 4.1.15-Debian_1-log

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql>
Step # 4: Set a new MySQL root user password:
mysql> use mysql;
mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit
Step # 5: Stop the MySQL server:
# /etc/init.d/mysql stop
Output:
Stopping MySQL database server: mysqld
STOPPING server from pid file /var/run/mysqld/mysqld.pid
mysqld_safe[6186]: ended

[1]+  Done                    mysqld_safe --skip-grant-tables
Start the MySQL server and test it:
# /etc/init.d/mysql start
# mysql -u root -p

Source: https://www.howtoforge.com/setting-changing-resetting-mysql-root-passwords

Friday, September 11, 2015

mongo replica with authentication

- Have not to create anything before
- connect to mongod using the localhost exception

>use admin
>db.createUser(
    {
      user: "superuser",
      pwd: "12345678",
      roles: [ {role: "userAdminAnyDatabase", db: "admin"}, "root" ]
    }
)

=========To create use in database===========
>use another_database
>db.createUser({user: "name", pwd: "password", roles: ['read', 'readWrite', 'dbAmin', 'dbOwner', 'userAdmin', ... http://docs.mongodb.org/v2.6/reference/built-in-roles/ ]})
====================End======================
- Close mongod
 
- Create keyFile
#openssl rand -base64 741 > mongodb-keyfile
#chmod 600 mongodb-keyfile
 
- Copy key file to each member of replica set
 
- Start mongod: mongod --auth --setParameter enableLocalhostAuthBypass=0 --setParameter enableTestCommands=0 --dbpath /your/path --replSet rs0 --smallfiles --oplogSize 128 --keyFile /path/to/mongodb-keyfile 
  Or edit in file config

dbpath=/var/lib/mongodb
logpath=/var/log/mongodb/mongod.log
logappend=true
bind_ip = 127.0.0.1
auth = true
smallfiles = true
oplogSize = 128
keyFile = /path/to/mongodb-keyfile
replSet = rs0
setParameter=enableLocalhostAuthBypass=0
setParameter=enableTestCommands=0

- Connect to mongod
#./mongo
>use admin
>db.auth('superuser', '12345678');
>rs.initiate()
- Add secondaries 
>rs.add('host:port')

================================================================================
db.getCollectionNames().forEach(function(c) { if (c.indexOf("system.") == -1) db[c].drop();

Tuesday, August 25, 2015

Objective C Object and Message (Note)

Creating Object, In Objective C, every objects are child of NSObject. NSObject alloc class method returns a new instance of the specified class type.
An id is an Objective C type used to hold a reference to  any Objective C object.

Object Initialization, the alloc method allocates storage for an object and set its instance variables to zero. NSObject implements an init method that provides the foundation for initialization.

Message Dispatch, messaging is fundamental concept in OOP. It is mechanism used to invoke a method on an object. The receiving object of a message determines at runtime which of its instance method to invoke. Instance methods have access to an object's instance variables along with its instance method.
[orderObject  addItem:burgerObject  forPrice:3.5];
orderObject is the object the message is sent to, addItem: forPrice: information identifies the method's actual name.

Message Forwarding enables an object to perform user-defined processing when it receives a message not mapped to its set of methods. Message forwarding can be used to provide many of features typically associated with OOP multiple inheritance. There are two types of message forwarding

  • Fast forwarding can implement fast forwarding by overriding the NSObject forwardingTargetForSelector: method to forward the method to another object. This technique makes it appear like the implementations of your object and the forwarding object are combined. This simulates the behavior of multiple inheritance of class implementations. It works well if you have a target class that defines all the possible messages that your object can consume.
  • Normal forwarding can implement normal forwarding by overriding the NSObject forwardInvocation: method. This technique enables your object to use the full contents of the message (target, method name, parameters).

Monday, August 17, 2015

Objective C Using Class (Note)

An Objective-C class is comprised of an interface and an implementation.

The interface declares the class properties and methods.

The implementation defines class instance variables, properties and methods.

Scope of instance variables:

  • @private The instance variable is only accessible within class that declares it and other instances of this class type.
  • @protected The instance variable is accessible within the class that declares it and the instance methods of any of its subclasses. This is default scope.
  • @public The instance variable is accessible from everywhere.
  • @package The instance variable is accessible from any other class instances or functions, but outside the package, it is treated as private. This scope can be useful for libraries or framework classes. 
Properties, in many programming language, methods can access an object internal state -- often referred to as getter/setter methods -- must be manual code. Objective C provides declared properties to both automate and simplify this task. A property differs from an instance variable in that it doesn’t directly access an object’s internal state, but rather provides a convenient mechanism (i.e., getter/ setter methods) for accessing this data, and thus may include other logic. Objective-C declared properties enable the compiler to generate these methods automatically according to your provided specification. This reduces the amount of code you have to write and maintain, and increases program consistency and reliability.

  • nonatomic Accessors are not atomic and, consequently, could provide different results when accessed concurrently by multiple threads. If not specified, accessors are atomic; that is, their values are always fully set/retrieved.
  • assign The setter method performs a simple assignment of properties value without using copy or retain. This is default setting.
  • retain On assignment, the input value will be sent retain message and the previous value will be sent a release message.
  • copy A copy of new message will be set on assignment and the previous value will be sent a release message.
  • strong This attribute (used when ARC memory management is applied on a property) is equivalent to the retain attribute.
  • weak This attribute (used when ARC memory management is applied on a property) is similar to the assign attribute except that if the affect property is released, its value is set to nil.
  • read/write The property can be read or written to. Both getter and setter methods must be implemented. This is the default setting.
  • read-only The property can be read but not written to. The getter method must be implemented.
  • getter=getterName Renames the getter to the specified getterName.
  • setter=setterName Renames the setter to the specified setterName.
Through use of the @synthesize keyword, the compiler can auto generate property definitions. A properties is synthesized in the corresponding class implementation section.


The method type identifier specifies whether the method is a class or an instance method. A class method is declared with a + (plus) sign and indicates that the method has class scope, meaning that it operates at the class level and does not have access to the instance variables of the class (unless they are passed as parameters to the method). An instance method is declared with a – (minus) sign and indicates that the method has object scope. It operates at the instance level and has direct access to the instance variables of the object and its parent objects (subject to the access controls on the instance variables).

A protocol declares methods and properties that can be implemented by any class. A class interface is directly associated with a specific class and, hence, a class hierarchy. On the other hand, a protocol is not associated with any particular class, thus it can be used to capture similarities among classes that are not hierarchically related. Protocols provide Objective-C with the capability to support the concept of multiple inheritance of specification (i.e., of method declarations). A protocol can also be used to define the messages that an object can send (by specifying properties that conform to a protocol).

A category enables the addition of new functionality to an existing class without subclassing it. Typically, categories are used 1) to extend classes defined by others (even if you don’t have access to the source code); 2) as an alternative to a subclass; or 3) to distribute the implementation of a new class into multiple source files. An extension can be considered an anonymous category; however, its declarations must be implemented in the main implementation block of the class. Extensions can also declare instance variables and properties.

An interface may employ inheritance to obtain the properties and methods of subclasses in a class hierarchy.

By convention, a class interface is stored (on disk) in a header file (suffixed with .h) and its implementation is stored in a file suffixed with .m.

Xcode provides templates for creating Objective-C classes, protocols, categories, and extensions, thereby making it easy to get started developing your own classes.
This has been a detailed primer on developing classes using Objective-C and Xcode, so this is
a good time to take a break and review what you’ve gone over. In the next chapter, you’ll pick up where you left off by exploring the details of object messaging using Objective-C.