Skip to content

Instantly share code, notes, and snippets.

View ricleal's full-sized avatar
☢️
Coding the World a Better Place

Ricardo Ferraz Leal ricleal

☢️
Coding the World a Better Place
View GitHub Profile
@ricleal
ricleal / rate_limiter.go
Created January 28, 2024 21:17
go rate limiter
package main
import (
"context"
"encoding/json"
"fmt"
"net/http"
"sync"
"time"
@ricleal
ricleal / http_server.py
Last active August 22, 2024 10:37
colorized simple echo http server
#!/usr/bin/env python3
'''
start as: http_server.py -p 8080
'''
from email import header
import http.server
import socketserver
import argparse
@ricleal
ricleal / n-producers_n-consumers.go
Last active June 23, 2023 02:37
N-Producers fanout N-Consumers with registry
package main
import (
"fmt"
"math/rand"
"sync"
"time"
)
var ch chan int
@ricleal
ricleal / main.go
Last active September 17, 2022 07:23
Go Clean Archicture
package main
import "fmt"
// Reference: https://user-images.githubusercontent.com/20016700/47955442-f0a66c00-dfa0-11e8-83f9-2856ed6ba159.png
// outer
// starts the call
type Controller struct {
@ricleal
ricleal / q2d.py
Created April 15, 2019 21:35
Mantid SANS Qx Qy Data test
import matplotlib.pyplot as plt
import numpy as np
# binnned values
qx = np.linspace(0.001, 0.9, 193)
qy = np.linspace(0.001, 0.7, 257)
dqx = np.sqrt(qx)
dqy = np.sqrt(qy)
@ricleal
ricleal / README-setup-socket-activated-systemd-service.md
Last active January 18, 2023 15:32 — forked from drmalex07/README-setup-socket-activated-systemd-service.md
An example inetd-like socket-activated service. #systemd #inetd #systemd.socket

Linux sockets and system d

Define a socket unit

The key point here is to specify Accept=yes, which will make the socket accept connections (behaving like inetd) and pass only the resulting connection socket to the service handler.

Create /etc/systemd/system/baz.socket:

[Unit]
@ricleal
ricleal / urls.py
Created March 28, 2018 21:44
Overriding as_view in Django
#coding: utf-8
from django.conf.urls import url
from .views import PostListView, DummyView
urlpatterns = [
url(r'^$', PostListView.as_view(), name='list'),
url(r'^dummy/$', DummyView.as_view(), name='dummy'),
]

Keybase proof

I hereby claim:

  • I am ricleal on github.
  • I am ricleal (https://keybase.io/ricleal) on keybase.
  • I have a public key whose fingerprint is C09D 6F9F 106D 24E3 F6E5 6146 D02C 956B 145F 841D

To claim this, I am signing this object:

@ricleal
ricleal / tornado_mongo.py
Created July 15, 2016 14:17 — forked from bootandy/tornado_mongo.py
Very simple sample code of tornado and mongodb
from datetime import datetime
from pymongo.connection import Connection
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
from tornado.options import define, options
@ricleal
ricleal / README.md
Last active September 4, 2015 20:08
Replace Conditions (if statements) with Polymorphism

From the command line create an executable that according to a prototol:

  • http
  • https
  • ftp

Returns a partially built URL: scheme://domain:port

$ ./executable ftp
ftp://ornl.gov:20