Skip to content

Instantly share code, notes, and snippets.

@NightBlues
NightBlues / unix.ml
Created February 22, 2018 11:18
OCaml Unix iso datetime converting
module Unix = struct
include Unix
let tm_of_iso date =
let make y m d h mi s = Unix.(
{tm_sec=s;tm_min=mi;tm_hour=h;tm_mday=d;tm_mon=(m - 1);tm_year=(y - 1900);
tm_wday=0;tm_yday=0;tm_isdst=false}) in
Scanf.sscanf date "%u-%u-%uT%u:%u:%uZ" make
let iso_of_tm tm =
Unix.(Printf.sprintf "%u-%02u-%02uT%02u:%02u:%02uZ" (tm.tm_year + 1900) (tm.tm_mon + 1) tm.tm_mday
let read_line () =
try
Some (read_line ())
with End_of_file -> None
let read_lines () =
let rec loop acc =
match read_line () with
| None -> List.rev acc
| Some line -> loop (line::acc)
@NightBlues
NightBlues / validate.py
Created February 9, 2017 16:45
marshmallow mongoengine validate
def find_models():
import models
from mongoengine.base.common import _document_registry
def _checker(model_class):
schema_class = getattr(model_class, 'schema_class', None)
return schema_class is not None and issubclass(schema_class, Schema)
return filter(_checker, _document_registry.values())
@pytest.mark.parametrize('model', find_models())
import IPy
def gen_next_net(cidr):
"""
>>> from IPy import IP
>>> get_next_net(IP("10.0.0.0/28"))
IP('10.0.0.16/28')
>>> reduce(lambda acc, _: get_next_net(acc), range(10), IP("10.0.0.0/28"))
IP('10.0.0.160/28')
"""
from contextlib import contextmanager
import threading
dyn = threading.local()
@contextmanager
def dlet(**new):
old = {}
for name, value in new.items():
old[name] = getattr(dyn, name, None)

Keybase proof

I hereby claim:

  • I am nightblues on github.
  • I am nightblues (https://keybase.io/nightblues) on keybase.
  • I have a public key whose fingerprint is EA63 B4F1 1427 A033 64EC CA90 F49C F0CF 9CF8 25F7

To claim this, I am signing this object:

@NightBlues
NightBlues / cmd.sh
Last active December 13, 2016 16:47
tornado_gracefull_stop
parallel --no-notice curl localhost:8080/{} ::: 4 5 3 8 10
#include <iostream>
using namespace std;
class A {
public:
char a;
int i;
A (int i, char a) {
this->i = i;
this->a = a;
import uuid
import multiprocessing
import pwquality
pwq = pwquality.PWQSettings()
def check(i):
uuid_ = str(uuid.uuid4())
try:
import time
import threading
import tornado.httpserver
import tornado.ioloop
import tornado.web
import tornado.gen
def threaded(fn):
def run(*k, **kw):