Skip to content

Instantly share code, notes, and snippets.

@nguyenbathanh
nguyenbathanh / encoder.py
Last active March 20, 2020 13:59
MongoEngineJSONEncoder. Dump the data in a BaseDocument ,QuerySet of Mongo documents to JSON
import datetime
import json
from bson import ObjectId
from mongoengine.base import BaseDocument
from mongoengine.queryset import QuerySet
class MongoengineEncoder(json.JSONEncoder):
def default(self, obj):
#!/usr/bin/env python3
import math
import turtle
turtle.speed(0)
# turtle.tracer(n=0, delay=0)
def square(length):
for i in range(4):
@danielrichman
danielrichman / flaskadapter.py
Last active December 16, 2020 19:55
logger adapters
class FlaskLoggerAdapter(logging.LoggerAdapter):
"""
A :class:`logging.LoggerAdapter` that adds request context
Adds the following attributes to log records (which can then be used in a
:class:`logging.Formatter` string).
* base_url: ``flask.request.base_url``
* flask_endpoint: ``flask.request.endpoint``
* remote_addr: ``flask.request.remote_addr``
@amatellanes
amatellanes / celery.sh
Last active September 19, 2025 15:58
Celery handy commands
/* Useful celery config.
app = Celery('tasks',
broker='redis://localhost:6379',
backend='redis://localhost:6379')
app.conf.update(
CELERY_TASK_RESULT_EXPIRES=3600,
CELERY_QUEUES=(
Queue('default', routing_key='tasks.#'),
@rezoo
rezoo / numpy.hpp
Last active July 14, 2025 13:57
Reimplementation of libnpy. This library is header-only and compatible with any environment including MSVC.
/*
* Copyright (c) 2012 Masaki Saito
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
proc ue_init {} {
lappend d + { }
for {set i 0} {$i < 256} {incr i} {
set c [format %c $i]
set x %[format %02x $i]
if {![string match {[a-zA-Z0-9]} $c]} {
lappend e $c $x
lappend d $x $c
}
}