Skip to content

Instantly share code, notes, and snippets.

View valarpirai's full-sized avatar

Valar valarpirai

View GitHub Profile
@valarpirai
valarpirai / app_config.rb
Last active January 31, 2022 11:48
Load configs from ERB based YML files in Rails application
module AppConfig
def self._config
@_config ||= ErbYaml.load_file("#{Rails.root}/config/app_configuration.yml")
end
def self.env
_config["env_name"]
end
end
@bradtraversy
bradtraversy / node_nginx_ssl.md
Last active July 25, 2024 06:56
Node app deploy with nginx & SSL

Node.js Deployment

Steps to deploy a Node.js app to DigitalOcean using PM2, NGINX as a reverse proxy and an SSL from LetsEncrypt

1. Sign up for Digital Ocean

If you use the referal link below, you get $10 free (1 or 2 months) https://m.do.co/c/5424d440c63a

2. Create a droplet and log in via ssh

I will be using the root user, but would suggest creating a new user

@valarpirai
valarpirai / Apache Access log format
Last active February 5, 2019 11:34
Apache detailed log format - Print Referer, User-Agent, X-Forwarded-For
<IfModule log_config_module>
<IfModule logio_module>
# You need to enable mod_logio.c to use %I and %O
CustomLog logs/ssl_request_log "%h %t %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %>s %D %b \"%{Referer}i\" \"%{User-Agent}i\" \"%{X-Forwarded-For}i\" %I %O"
</IfModule>
</IfModule>
@valarpirai
valarpirai / git-pull.sh
Created December 17, 2018 05:53
Iterate over the git repositories in current directory and do git pull
find . -maxdepth 1 -type d \( ! -name . \) -exec bash -c "pull()
{
echo '--------- $(pwd)'
if [ -d \".git\" ]; then
echo '######### Start git pull'
git pull
else
echo '********* Not a git Repo **********'
fi
}
@valarpirai
valarpirai / _upload_dir_s3.py
Last active November 16, 2019 12:13
Upload Directory to AWS S3 using boto3 python SDK. Files will be uploaded if last modified time newer than existing file. Also sets file MIME type.
#!/usr/bin/env python
import os
import sys
import boto3
from datetime import datetime, timezone
from urllib.request import pathname2url
import mimetypes
# upload_dir_s3.py /path/to/local/folder thebucketname /path/to/s3/folder
@valarpirai
valarpirai / character-count.js
Last active January 29, 2018 07:06
Character counting in Javascript
// FIRST METHOD
// Count using array
arr = new Array(26).fill(0);
s = "ABCAZZ" // Input String
for (var i = 0; i < s.length; i++) {
var index = s.charCodeAt(i) - 'A'.charCodeAt(0);
arr[index] += 1;
}
@StevenACoffman
StevenACoffman / _MicroService Proxy Gateway Solutions.md
Last active July 15, 2024 05:12
Microservice Proxy/Gateway Solutions

MicroService Proxy Gateway Solutions

Kong, Traefik, Caddy, Linkerd, Fabio, Vulcand, and Netflix Zuul seem to be the most common in microservice proxy/gateway solutions. Kubernetes Ingress is often a simple Ngnix, which is difficult to separate the popularity from other things.

Github Star Trend:

Github Star History for Kong vs traefik vs fabio vs caddy vs Zuul

This is just a picture of this link from March 2, 2019

Originally, I had included some other solution

@valarpirai
valarpirai / live-radio.json
Last active September 17, 2022 15:23
Tamil Live Streaming Radio URL list
[{"name":"Colombo","channels":[{"map":"r_PK61Dt","href":"/listen/coop-radio/r_PK61Dt","title":"Coop Radio","subtitle":"Maharagama","id":"id8a401705-6766-9164-17ce-a5346f2fa38e","name":"Coop Radio","src":"https://radio.garden/api/ara/content/listen/r_PK61Dt/channel.mp3?id8a401705-6766-9164-17ce-a5346f2fa38e"},{"map":"fo8bhE4s","href":"/listen/free-fm/fo8bhE4s","title":"Free FM","subtitle":"Kotikawatta","id":"id26060e93-15ee-1442-f1ac-0c7a7aec0e8d","name":"Free FM","src":"https://radio.garden/api/ara/content/listen/fo8bhE4s/channel.mp3?id26060e93-15ee-1442-f1ac-0c7a7aec0e8d"},{"href":"/listen/hirufm/xyIbSGbn","title":"Hiru FM 96.1","id":"idffeeb3c7-4ada-af94-0ab8-926609a1e0f2","name":"Hiru FM 96.1","src":"https://radio.garden/api/ara/content/listen/xyIbSGbn/channel.mp3?idffeeb3c7-4ada-af94-0ab8-926609a1e0f2"},{"map":"xyIbSGbn","href":"/listen/hirufm/xyIbSGbn","title":"Hiru FM 96.1","subtitle":"Colombo","id":"id420953ad-8179-234b-0ef9-b5587c5c4eca","name":"Hiru FM 96.1","src":"https://radio.garden/api/ara/conten

Scaling your API with rate limiters

The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.

In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.

Request rate limiter

This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.

@mdonkers
mdonkers / server.py
Last active July 22, 2024 13:51
Simple Python 3 HTTP server for logging all GET and POST requests
#!/usr/bin/env python3
"""
License: MIT License
Copyright (c) 2023 Miel Donkers
Very simple HTTP server in python for logging requests
Usage::
./server.py [<port>]
"""
from http.server import BaseHTTPRequestHandler, HTTPServer