Skip to content

Instantly share code, notes, and snippets.

View valarpirai's full-sized avatar

Valar valarpirai

View GitHub Profile
@valarpirai
valarpirai / GeoLocation.js
Created February 11, 2016 09:55 — forked from ederoyd46/GeoLocation.js
Javascript for finding latitude and longitude range boundaries
//Javascript for finding latitude and longitude range boundaries.
//Based on the excellent Java example by http://janmatuschek.de/LatitudeLongitudeBoundingCoordinates
var GeoLocation = GeoLocation ? GeoLocation : {
TO_RADIAN: 0.0174532925,
TO_DEGREE: 57.2957795,
EARTH_RADIUS: 6371.01,
TO_MILE: 0.621371192,
TO_KM: 1.609344,
MIN_LAT: function() { return GeoLocation.degreeToRadian(-90) },
@valarpirai
valarpirai / onchange.sh
Created June 16, 2016 12:39 — forked from senko/onchange.sh
Watch current directory and execute a command if anything in it changes
#!/bin/bash
#
# Watch current directory (recursively) for file changes, and execute
# a command when a file or directory is created, modified or deleted.
#
# Written by: Senko Rasic <senko.rasic@dobarkod.hr>
#
# Requires Linux, bash and inotifywait (from inotify-tools package).
#
# To avoid executing the command multiple times when a sequence of
* {
background: #000 !important;
color: #0f0 !important;
outline: solid #f00 1px !important;
}
@valarpirai
valarpirai / python_decorator_guide.md
Created March 13, 2018 09:31 — forked from Zearin/python_decorator_guide.md
The best explanation of Python decorators I’ve ever seen. (An archived answer from StackOverflow.)

NOTE: This is a question I found on StackOverflow which I’ve archived here, because the answer is so effing phenomenal.


Q: How can I make a chain of function decorators in Python?


If you are not into long explanations, see [Paolo Bergantino’s answer][2].

@valarpirai
valarpirai / node_nginx_ssl.md
Created September 28, 2019 07:14 — forked from bradtraversy/node_nginx_ssl.md
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 / dnsmasq OS X.md
Created October 31, 2019 05:54 — forked from ogrrd/dnsmasq OS X.md
Setup dnsmasq on OS X

Never touch your local /etc/hosts file in OS X again

NOTE this has been done properly by a guy here: https://www.stevenrombauts.be/2018/01/use-dnsmasq-instead-of-etc-hosts/

You should go and do that now, ignore all of this.

To setup your computer to work with *.dev domains, e.g. project.dev, awesome.dev and so on, without having to add to your hosts file each time.

Requirements

@valarpirai
valarpirai / resp3.md
Created October 31, 2019 09:54 — forked from antirez/resp3.md
RESP3 protocol draft

RESP3 specification

Versions history:

  • 1.0, 2 May 2018, Initial draft to get community feedbacks.

Background

The Redis protocol has served us well in the past years, showing that, if carefully designed, a simple human readable protocol is not the bottleneck in the client server communication, and that the simplicity of the design is a major advantage in creating a healthy client libraries ecosystem.

Yet the Redis experience has shown that after about six years from its introduction (when it replaced the initial Redis protocol), the current RESP protocol could be improved, especially in order to make client implementations simpler and to support new features.

@valarpirai
valarpirai / Cheat Sheet.md
Last active April 12, 2024 16:41 — forked from vasanthk/System Design.md
System Design Cheatsheet

Golden rules for System Design

👉 For a Read-Heavy System - Consider using a Cache.

👉 For a Write-Heavy System - Use Message Queues for async processing

👉 For a Low Latency Requirement - Consider using a Cache and CDN.

👉 If we need a system to be ACID complaint, we should go for RDBMS or SQL Database

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.

#!/usr/bin/env python
#
# Converts any integer into a base [BASE] number. I have chosen 62
# as it is meant to represent the integers using all the alphanumeric
# characters, [no special characters] = {0..9}, {A..Z}, {a..z}
#
# I plan on using this to shorten the representation of possibly long ids,
# a la url shortenters
#