跳至主要内容

博文

Workaround a jython runtime bug by interop with Java java.time

TypeError: unsupported operand type(s) for +: 'java.sql.Timestamp' and 'timedelta' I was working on a NIFI script recently. As the following code snip shows, I was trying to construct a series of timestamped string with Python’s datetime. import os.path from datetime import datetime, time, timedelta import subprocess now = datetime.now() dirs = [ (now + timedelta(milliseconds=(-100 * x))).strftime( '%Y%m%d%H/%M/%S/%f' )[0:-5] for x in range (0,100)] fullpaths = [ '/workspace/nifi_output/{}' . format (d) for d in dirs] existspaths = [fp for fp in fullpaths if os.path.exists(fp)] flowFile = session.get() if (flowFile == None ): flowFile = session.create() ep_length = len (existspaths) if ep_length > 1: session.putAttribute(flowFile, 'batch_path' , existspaths[1]) session.transfer(flowFile, REL_SUCCESS) elif ep_length == 1: session.putAttribute(flowFile, 'batch_path' , existspaths[0]) sessi...

clean up docker images daily and weekly

Here’s the crontab content I used @daily docker rmi `docker images -f dangling=true -q` @weekly docker rmi `docker images -f 'reference=100.98.97.206/*/*-ui:*' --format "{% raw %}{{.Repository}}:{{.Tag}}{% endraw %}"` reference document https://docs.docker.com/engine/reference/commandline/images/#filtering

My openapi workflow

The workflow I am trying to work with Recently, I was working on bring openapi to my workflow to minimize the API related effort on Restful project. My goal was to using openapi generator to generate client and server interface stubs. Then using this generated code as SDK in both frontend and backend so that I will not have to deal with HTTP and the restful details. My Goal No more restful coding API spec to code auto generation Minimized code maintenance effort Generate client and server code from same spec Multiple languages and framework support, vue, pure js, springboot, springboot-jersy Easy to regenerate at anytime. My project structure It feels like openapi-generator-cli fit my needs very well. At present, I only have one API spec file, So I just named it 'openapi.yaml'. In the future, if it requires me to split my openapi spec, I'll put them into a subdirectory named 'openapi'. As the openapi-generator-cli has a configuration param...

Where to find information of OpenAPI tools and steps to setup and run OpenAPI generator

All about the OpenAPI tools The OpenAPI tools are derived from swagger tools. They feels almost identical to new comer. The tool enables automatic generation of API documents and server-client interface libraries. Unlike the swagger tools, OpenAPI tools are more open there¡¯re all kinds of groups developed different kinds of tools base on the OpenAPI SPEC. While there¡¯re too many choices, it also brings difficulties to new user to getting start with the OpenAPI. Documents to read This is a list of links I¡¯d go through. The github project¡¯s readme includes a very long list of OpenAPI practice arities. https://www.baeldung.com/spring-rest-openapi-documentation https://www.baeldung.com/java-openapi-generator-server https://www.baeldung.com/java-dto-pattern https://openapi.tools/ https://openapi-generator.tech https://medium.com/swlh/openapi-swagger-ui-codegen-with-spring-boot-1afb1c0a570e https://github.com/OpenAPITools/openapi-generator An pathway to getting start...

Working with case insensitive Json in python

We want the json keys to be case-insensitive Okay, I hope this is not your case, as it is too weird to work this way. But If you have to. Or, If you must to. Solution is to: Just working in a specific case, upper or lower, and blindly convert all data to that case. To do this in Python, when you load a JSON file/string you can define a hook named object_pairs_hook as below: import pathlib my_file = pathlib.Path.cwd().join( 'my_example.json' ) def lower_case_keys (tuple_list): return dict ([(k.lower(), v) for k, v in tuple_list]) json.loads(my_file.read_text(encoding= 'UTF-8' ), object_pairs_hook=lower_case_keys) From here on, all your json operation should be using lower-cased keys.

find pylance directory

So your pylance upgrade very often? init snap here to rescue. ( defun find-pylance () ( let* ((vscode-extensions-directory (expand-file-name ".vscode/extensions" (getenv "UserProfile" ))) (pylance-directory (car (seq-filter ( lambda (elt) (string-match-p ".*pylance.*" elt)) (directory-files vscode-extensions-directory))))) (concat (file-name-as-directory vscode-extensions-directory) (file-name-as-directory pylance-directory) "dist/server.bundle.js" ))) (add-to-list 'eglot-server-programs `(python-mode . ( "node" ,(find-pylance) "--stdio" ))) (add-hook 'python-mode-hook 'eglot-ensure)