Skip to content

Instantly share code, notes, and snippets.

View ivan-kleshnin's full-sized avatar
🏠
Working from home

Ivan Kleshnin ivan-kleshnin

🏠
Working from home
View GitHub Profile
@ivan-kleshnin
ivan-kleshnin / .goaccessrc
Last active August 29, 2015 14:10
How to reveal hackers and spammers in standard nginx logs (OS X instruction)
# put this file in home folder
date_format %d/%b/%Y
log_format %h %^[%d:%^] "%r" %s %b "%R" "%u"
@ivan-kleshnin
ivan-kleshnin / gist:6b17b0f6ac863cb17217
Created October 9, 2014 09:40
MongoDB: order positions by timedelta between CLOSE_DATE and NOW
from pymongo import MongoClient
from bson import SON
from time import mktime
from datetime import datetime, timedelta
from time import mktime
from pprint import pprint
from random import randrange, randint, choice
def seed_position_times(db):
@ivan-kleshnin
ivan-kleshnin / gist:601503b9062ba45863d5
Last active December 30, 2022 05:57
Brainstorming middleware ordering... Wider application though.
;; 0. Given that `app` is a RING handler
;; 1. We have 6 functions: 3 to modify requests, 3 to modify responses
;; 1.1. Request modifiers
(defn modify-request-first [handler]
(fn [request]
(println "modify-request-first") ; "println" is a placeholder for real code
(handler request)))
class PPrintMixin:
def __str__(self):
return '<{}: id={!r}>'.format(type(self).__name__, self.id)
def __repr__(self):
attrs = []
for name in self._fields.keys():
value = getattr(self, name)
if isinstance(value, (Document, EmbeddedDocument)):
attrs.append('\n {} = {!s},'.format(name, value))