Skip to main content

Posts

Why won't react re-render on state change?

If you mutate the state directly it won't re-render. Instead of... [cart, setCart] = useState([1,2,3]) const updateCart = (item) => {   prevCart = cart   prevCart.push(item)   setCart(prevCart) } Do this.... const updateCart = (item) => {   let prevCart = []   cart.forEach(item => {       prevCart.push(item)   });   setCart(prevCart) }
Recent posts

Backup dockerized mongodb

### Backup mongo db container on docker host ``` docker run --rm --network [network] --link [db_container]:mongo -v /Users/sam/db_backups:/backup mongo bash -c 'mongodump -u [username] -p [password] --out /backup --host mongo:27017' ``` ### Restore mongodb database ``` docker run --rm --network [network] --link [db_container]:mongo -v /Users/sam/db_backups:/backup mongo bash -c 'mongorestore -u [mong_username] -p [mong_password] /backup --host mongo:27017' ``` The restore will wipe everything that existed before-hand.

Attach existing volume to container with docker-compose

`docker volume create my_vol` in docker-compose.yml, declare volumes with property `external: true`. This tells docker compose not to create volumes. If external = false, then docker compose will prefix the volume declared with the directory name. Example: /home   /sam     /docker       /my_app         - docker-compose.yml The volume name will end up being `my_app_my_vol` Example docker-compose.yml: ``` version: "3" volumes:   my_vol:     external: true services:   my_app:     volumes:       - my_vol:/data <-- attach volume to /data inside container ... ... ```

Setup net-snmp on Ubuntu 12.04

This is the bare minimum to set up snmp on Ubuntu to allow monitoring from Cacti or similar apt-get update apt-get install snmpd snmp-mibs-downloader snmpconf  - Choose /etc/snmp/snmpd.conf  - Choose snmpd.conf  - Choose 3 for 'Access Control'  - Choose 3 for RO community  - Type community name  - Press enter or type allowed network/host  - Press enter to allow all OID mv snmpd.conf /etc/snmp/ service snmpd restart

IPTables example

Allow tcp port 80 from source address 192.168.10/24 iptables -A INPUT -i 10 -P TCP -S 192.168.1.0/24 --dport 80 -j ACCEPT Drop tcp port 80 from range of addresses iptables -A INPUT -i 10 -p tcp --dport 80 -m iprange --src-range 192.168.1.1-192.168.1.254 -j DROP List chain with rule numbers iptables -nL INPUT -v --line-numbers Delete particular rule iptables -D INPUT 10

DHCP option 121

http://tools.ietf.org/html/rfc3442 This is used to add a classless  static route to the DHCP clients. To add option 121 to a Mikrotik DHCP server, it's value is specified in HEX. The format is as follows. 0xnnddddddddgggggggg where n=mask, d=destination, g=gateway. To convert ip address to HEX, you convert each octet, so 192=C0, 168=A8, 55=37, 1=01 You can use a tool such as  http://www.miniwebtool.com/ip-address-to-hex-converter/?ip=192.168.55.1 Example: To add a route to the destination network of 192.168.55.0/24 via gateway 172.16.10.1. /ip dhcp-server option add name=classlessroutes code=121 value=0x18C0A837AC100A01 where 18 is 24 in hex. *note: depending on the subnet mask, you may only need to specify 0-4 octets. In fact only the non-zero, or network portion of the subnet. Here is a table from the RFC. subnet mask Number of octets 0 0 1- 8 1