Skip to content

Instantly share code, notes, and snippets.

@chrisdiana
chrisdiana / simple-http-server.py
Created Dec 23, 2020
Simple Python HTTP Server
View simple-http-server.py
#!/usr/bin/env python3
"""
Very simple HTTP server in python for logging requests
Usage::
./server.py [<port>]
"""
from http.server import BaseHTTPRequestHandler, HTTPServer
import logging
class S(BaseHTTPRequestHandler):
View Makefile
# Hello, and welcome to makefile basics.
#
# You will learn why `make` is so great, and why, despite its "weird" syntax,
# it is actually a highly expressive, efficient, and powerful way to build
# programs.
#
# Once you're done here, go to
# http://www.gnu.org/software/make/manual/make.html
# to learn SOOOO much more.
View redis-cluster-setup.md

Redis cluster setup

In order to setup redis cluster. We will need 3 redis instances.

  • 1 master
  • 2 slaves

redis-cluster folder structure

├── master ── redis.conf , sentinel.conf , redis-server
├── slave1 ── redis.conf , sentinel.conf , redis-server
View redis-cheetsheet.md

Redis

Set record

SET foo bar

Get record

GET foo
@chrisdiana
chrisdiana / python-application-structures.md
Last active Jul 8, 2021
Python Application Structures
View python-application-structures.md

One-Off Script

helloworld/
│
├── .gitignore
├── helloworld.py
├── LICENSE
├── README.md
├── requirements.txt
@chrisdiana
chrisdiana / amazon_linux_ec2_starter.sh
Last active Sep 7, 2021
Amazon Linux EC2 Starter
View amazon_linux_ec2_starter.sh
sudo yum update -y
sudo yum install -y tmux vim docker htop wget git w3m python3 htop curl
sudo service docker start
sudo usermod -a -G docker ec2-user
sudo pip3 install virtualenv
virtualenv -p python3 venv
aws configure
sudo systemctl enable docker
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
. ~/.nvm/nvm.sh
@chrisdiana
chrisdiana / docker_amazon_linux.sh
Last active Apr 22, 2021
Install Docker Amazon Linux
View docker_amazon_linux.sh
sudo yum update -y && yum install -y docker git tmux
sudo service docker start
sudo usermod -a -G docker ec2-user
sudo systemctl enable docker
@chrisdiana
chrisdiana / example.py
Last active Oct 6, 2020
Data Pipeline Function in Python
View example.py
import pandas as pd
data = {'col1': [1, 2, 2], 'col2': [3, 4, 5], 'col3': [1, 2, 3]}
df = pd.DataFrame(data)
def clean(df):
return df[['col1', 'col2']]
def equals_2(df, col):
View progress-dd.sh
sudo apt-get install pv
sudo dd if=/dev/disk2 | sudo pv -s 128G | sudo dd of=~/sd.bin bs=4096
dd if=/dev/urandom | pv | dd of=/dev/null
@chrisdiana
chrisdiana / postgres-cheatsheet.md
Created Sep 16, 2020 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet
View postgres-cheatsheet.md

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)