Switch from class to Python 3.6.1 NamedTuple
Since python 3.6, immutable object now can be defined with named tuple (with optional/default variable in 3.6.1). This brings python syntax of defining data model close to my favorite Scala case…
Since python 3.6, immutable object now can be defined with named tuple (with optional/default variable in 3.6.1). This brings python syntax of defining data model close to my favorite Scala case…
Configuration for running the examples. from pymongo import MongoClient import gridfs mongo_mydata = MongoClient("localhost:27017").mydata mongo_mydata_fs = gridfs.GridFS(mongo_mydata, collections='my_item_fs') A simple queueing system for pick…
import tensorflow import numpy as np tokenizer = tensorflow.keras.preprocessing.text.Tokenizer() tokenizer.fit_on_texts((x.content for x in TextData().generate())) tokenizer.word_index >>> {'p': 1, 'li': 2, 'the': 3,…
Docker has placed its own forwarding in the iptables, so blocking INPUT and OUTPUT would not protect services expose via docker publish port. In addition, Docker moves its own rules at the top of yours…
Every so often, a compact list of the non-zero element indices is preferred rather than a sparse array. >>> fit(['123 456', '111']) >>> transform(['123 456', '123', '456', '111']) [array(…
This happens so often but the solution is complicated # this works docker exec -it container_name bash # this works (typing and close with ctrl-d to EOF) docker exec -i container_name "bash" "-c" "cat -…
I rarely come across situation where I need Possessive quantifiers to do something that Greedy quantifiers could not perform. Greedy Reluctant Possessive Meaning X? X?? X?+ X, once or not at all X* X*? X*…
In a concurrent environment, we often see ConcurrentMap<Key, Integer>. An good example is tracking the number of subscriptions for a topic. Keeping this number thread-safe could be important if the number is…
What would the follow code print? public class Moo { private static Moo m = new Match (); private static final Boolean t = true; private Boolean b = t; public static void main(String[] args) throws Exception { System.out.…
Hurray!! I have used MarkDown more often than any other markup language. AsciiDoc is something completely new to me. http://asciidoctor.org/docs/asciidoc-syntax-quick-reference/…