Skip to content

Instantly share code, notes, and snippets.

@lifeisfoo
lifeisfoo / react-sse-example.html
Created March 5, 2024 16:18
A React SSE client that lists products
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>React SSE example</title>
<script src="https://unpkg.com/react@18/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
<!-- Don't use this in production: -->
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
@lifeisfoo
lifeisfoo / replicationwiki.md
Created March 4, 2023 10:03 — forked from judahschvimer/replicationwiki.md
Replication Internals Wiki

Replication in 3.4

Replication is the set of systems used to continuously copy data from a primary server to secondary servers so if the primary server fails a secondary server can take over soon. This process is intended to be mostly transparent to the user, with drivers taking care of routing queries to the requested replica. MongoDB supports two forms of replication: replica sets and master-slave.

Master-Slave

This article will focus on replica sets, which are the main way people use replication today. Master-slave has one master node and multiple slave nodes. Slaves replicate from the master and all failover is done manually. Slave nodes can only replicate from other slave nodes if the other slave nodes are configured as masters themselves.

Master-slave replication also allows for filtered replication. Slaves can replicate some chosen subset of the collections.

@lifeisfoo
lifeisfoo / react-inject-env-vars.md
Created May 13, 2022 08:05
interpolate-html-plugin

public/index.html


<link href="%PUBLIC_URL%/assets/favicon-32x32.png" />

// OR
@lifeisfoo
lifeisfoo / check-reachable-hosts.sh
Created June 9, 2021 11:06
A script to check if all hosts in /etc/hosts are reacheble, using fping
#!/bin/bash
input="/etc/hosts"
while IFS= read -r line
do
a=( $line )
fping "${a[1]}"
done < "$input"
@lifeisfoo
lifeisfoo / rex-ray-efs-minimum-aws-policy
Created February 6, 2018 14:02
Minimum rex ray aws policy for using efs driver
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "RexRayEFSMin",
"Effect": "Allow",
"Action": [
"elasticfilesystem:CreateFileSystem",
"elasticfilesystem:CreateMountTarget",
"ec2:DescribeSubnets",
@lifeisfoo
lifeisfoo / docker_setup_ubuntu.sh
Created February 2, 2018 00:13
Docker CE setup on ubuntu 16.04+
#!/bin/bash
# DOC https://docs.docker.com/install/linux/docker-ce/ubuntu/#install-docker-ce-1
apt-get remove docker docker-engine docker.io
apt-get update
apt-get install \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
@lifeisfoo
lifeisfoo / aws_s3_cp_policy
Created January 22, 2018 16:45
IAM policy for aws s3 cp command
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:AbortMultipartUpload",
"s3:PutObjectVersionAcl",
"s3:PutObjectAcl"
@lifeisfoo
lifeisfoo / s3cmd_sync_policy
Created January 22, 2018 11:40 — forked from ngstigator/s3cmd_sync_policy
IAM policy for s3cmd sync
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:ListAllMyBuckets",
"Resource": "arn:aws:s3:::*"
},
{
"Effect": "Allow",
@lifeisfoo
lifeisfoo / dokuwiki ubuntu 16.04
Last active July 10, 2021 14:32
10 steps - a simple guide to setup dokuwiki on nginx and ubuntu 16.04 (even on AWS EC2)
# 1. update apt
apt-get update
# 2. install nginx and php (source https://forum.dokuwiki.org/post/52724;?unb855sess=af28c8160e97b05e634124aa83451119)
apt-get install nginx php php-fpm php7.0-xml
# 3. download dokuwiki
curl https://download.dokuwiki.org/src/dokuwiki/dokuwiki-stable.tgz -o dokuwiki.tgz
tar xvf dokuwiki.tgz
dokuwiki-2017-02-19e /var/www/dokuwiki
@lifeisfoo
lifeisfoo / mongo-lowercase-subfield.js
Created November 28, 2016 15:22
Lowercase a field
db.products.find().forEach(
function(doc) {
if (!!doc.variants) {
for (i = 0, len = doc.variants.length; i < len; i++) {
doc.variants[i].sku = doc.variants[i].sku.toLowerCase();
}
}
db.products.save(doc);
}
)