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 / database.py
Created October 31, 2013 10:44
Generic mongodb class written in pymongo. It depends from a log and a configparser. Those dependencies are simple to delete.
from pymongo import MongoClient
import logging
logger = logging.getLogger(__name__)
from config.config import configParser
class Database(object):
'''
Generic class to access MongoDB.
@ricleal
ricleal / rvo.cpp
Created December 3, 2013 16:15
RVO: Return value optimization and NRVO: Named return value optimization
/**
* RVO: Return value optimization and NRVO: Named return value optimization
*
* Trying to get the last line of this to work...
*
* Still creates a new object when I assign m14 = fChangeClassRetRef(m14); :(
*
* I guess this is a problem with the compiler itself.
*
*/
@ricleal
ricleal / vietnam_prob.py
Last active September 12, 2015 15:38
vietnam_prob
import numpy as np
res = 66
def eq(x):
return x[0] + 13 * x[1] / x[2] + x[3] + 12 * x[4] - x[5] - 11 + x[6] * x[7] / x[8] - 10
# Brute force!
it = 0
while True:
@ricleal
ricleal / test_proxy.py
Last active July 1, 2018 20:12
UGLY HTTP connection with Auto Proxy & proxy.pac detection on Linux, OSx or Windows
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2
import json
from pprint import pprint
import sys
import re
@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
@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

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 / 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'),
]
@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 / 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)