Zettelkasten notes implemented as a library with a set of CLI utils
https://news.ycombinator.com/item?id=31969931
Tags: zettelkasten, software, personal-knowledge, application, tool, cli, fzf, search, wiki, imported, hacker-news
Id: 5017abd4-fb79-11ec-ad8c-0242ac110003
Read: Sun Jul 3 18:38:57 2022
https://news.ycombinator.com/item?id=32005678
Tags: imported, hacker-news
Id: d665c1c0-c1a4-11ed-a153-0242ac110004
Read: Wed Jul 6 19:31:01 2022
https://news.ycombinator.com/item?id=32066370
Tags: imported, hacker-news
Id: 98fd7b9c-c1a0-11ed-a0b4-0242ac110004
Read: Tue Jul 12 06:34:16 2022
A guide to understand AES in depth
https://news.ycombinator.com/item?id=32078749
Tags: aes, cryptography, tutorial, guide, imported, hacker-news
Id: c93acb66-13db-11ed-9c8a-0242ac110003
Read: Wed Jul 13 03:30:52 2022
https://news.ycombinator.com/item?id=32186203
Tags: imported, hacker-news
Id: 9b457f58-c1a0-11ed-9849-0242ac110004
Read: Thu Jul 21 22:50:29 2022
https://news.ycombinator.com/item?id=32245545
Tags: imported, hacker-news
Id: 9d9617ae-c1a0-11ed-9bee-0242ac110004
Read: Wed Jul 27 00:03:04 2022
https://news.ycombinator.com/item?id=32258783
Tags: imported, hacker-news
Id: 9fe13d68-c1a0-11ed-a2c3-0242ac110004
Read: Thu Jul 28 00:06:31 2022
Connecting from Python to C, using Cython
Have a look at the generate-kat-core
repo. At the time of writing, it’s not open-source yet.
Takeaways
Automate the creation of the library
Create a make goal to:
- Copy the library
LIBRARY
from its origin to its destination
- Compile the cython code
- Execute the above when executing the test goal (to always have an up-to-date version when committing)
If needed, in PyCharm, require the test configuration to execute the make goal first (as a prerequisite)
ORIGIN_PROJECT:=.
ORIGIN:=${ORIGIN_PROJECT}/binaries
DESTINATION:=.
all: clean list copy clean-post-copy
list:
ls -d $(shell realpath ${ORIGIN}) || true
find ${ORIGIN} -iname "*\.a"
.PHONY: list
clean:
rm -f ${DESTINATION}/*a ${DESTINATION}/*h
.PHONY: clean
copy:
cp ${ORIGIN}/lib/libLIBRARY*.a ${DESTINATION}/libLIBRARY.a
cp -R ${ORIGIN}/include/ ${DESTINATION}
.PHONY: copy
clean-post-copy:
rm -f *.zip
rm -rf ${ORIGIN}
.PHONY: clean-post-copy
Use the *.pyx
files to connect Python to the C functions
You can use the *.pyx
files to define the functions that will be called from Python. The *.pyx
files are Cython
files that can be compiled to C.
In these *.pyx
files, you can define the glue code that will call the C functions.
As such, we write test code for those *.pyx
files, to ensure the C functions are called correctly. Those tests are
end-to-end, allowing no test doubles.
Introduce restrictions in the glue code
- Because C requires the size of the array, you can inject a python array (e.g.,
bytes
or bytearray
). Python will
know the size of the array, and you can pass it to the C function:
def my_function(data: bytearray):
size = len(data)
c_function(c_data, size)
- If the C function requires a specific size (e.g., 4 bytes), you can check the size in the Python function:
def my_function(data: bytearray):
assert len(data) == 4, f"The data must be 4 bytes long. Currently = {len(data)} bytes"
c_function(c_data) # size can be optional if it's mandatory to be 4
- Bytes are immutable, while bytearray is mutable.
When a bytes
is passed to a C function, it’s passed as a pointer to the data.
Be careful when modifying the data in the C function. If you need to change the data, use a bytearray
.
Debugging
To remove defects in the *.pyx
files, convert once (“cythonize”).
from setuptools import setup
from Cython.Build import cythonize
setup(
ext_modules = cythonize("helloworld.pyx")
)
(From Cython: Basic Tutorial)
Links
Look around here, with the tag
generate-kat-core
How to create a Cython class that can wrap a cdef field.
Tags: cython, generate-kat-core, python, integration, binding
Id: eaf09838-ec8c-11ec-b5c3-0242ac110003
Read: Wed, 15 Jun 2022 09:24:12 +0000
Tags: stack-overflow, function-pointer, python, cython, generate-kat-core, integration, binding
Id: 143138ce-ec8d-11ec-aa16-0242ac110003
Read: Wed, 15 Jun 2022 09:25:21 +0000
Pointing to “WaveFunction” (#id8).
Examples of how a @cython.cclass with attributes gets converted to C.
Tags: cython, binding, generate-kat-core, cython.cclass, python, integration
Id: 4c981052-ec8d-11ec-a7c9-0242ac110003
Read: Wed, 15 Jun 2022 09:26:56 +0000
Tags: cython, struct, integration, generate-kat-core, python, binding
Id: 6356b910-ec8d-11ec-8ba6-0242ac110003
Read: Wed, 15 Jun 2022 09:27:34 +0000
https://news.ycombinator.com/item?id=31627089
Tags: imported, hacker-news
Id: 96b84628-c1a0-11ed-b3f2-0242ac110004
Read: Sun Jun 5 01:42:05 2022
An account of the interaction between AirPlay and Touch Bar (in mac)
https://news.ycombinator.com/item?id=31706283
Tags: airplay, debugging, touch-bar, mac-os, imported, hacker-news
Id: f82bd9d0-ebf2-11ec-a47b-0242ac110003
Read: Sat Jun 11 17:31:03 2022
How to create a Cython class that can wrap a cdef field.
Tags: cython, generate-kat-core, python, integration, binding
Id: eaf09838-ec8c-11ec-b5c3-0242ac110003
Read: Wed, 15 Jun 2022 09:24:12 +0000
Tags: stack-overflow, function-pointer, python, cython, generate-kat-core, integration, binding
Id: 143138ce-ec8d-11ec-aa16-0242ac110003
Read: Wed, 15 Jun 2022 09:25:21 +0000
Pointing to “WaveFunction” (#id8).
Examples of how a @cython.cclass with attributes gets converted to C.
Tags: cython, binding, generate-kat-core, cython.cclass, python, integration
Id: 4c981052-ec8d-11ec-a7c9-0242ac110003
Read: Wed, 15 Jun 2022 09:26:56 +0000
Tags: cython, struct, integration, generate-kat-core, python, binding
Id: 6356b910-ec8d-11ec-8ba6-0242ac110003
Read: Wed, 15 Jun 2022 09:27:34 +0000
https://news.ycombinator.com/item?id=31833026
Tags: imported, hacker-news
Id: d1b56a18-c1a4-11ed-8c56-0242ac110004
Read: Wed Jun 22 07:31:04 2022
https://news.ycombinator.com/item?id=31848499
Tags: rust, linux, kernel, programming-language, imported, hacker-news
Id: 6ffdee10-17dd-11ed-950f-0242ac110003
Read: Thu Jun 23 13:05:47 2022
https://news.ycombinator.com/item?id=31873967
Tags: imported, hacker-news
Id: d411469c-c1a4-11ed-b68f-0242ac110004
Read: Sat Jun 25 10:06:57 2022
https://news.ycombinator.com/item?id=31463454
Tags: imported, hacker-news
Id: 946cb19c-c1a0-11ed-9794-0242ac110004
Read: Sun May 22 00:00:29 2022
https://news.ycombinator.com/item?id=30999322
Tags: imported, hacker-news
Id: 9210a1a6-c1a0-11ed-a323-0242ac110004
Read: Tue Apr 12 06:29:35 2022
https://news.ycombinator.com/item?id=30529727
Tags: imported, hacker-news
Id: 4ca532b2-c1a0-11ed-8343-0242ac110004
Read: Wed Mar 2 17:10:32 2022
https://news.ycombinator.com/item?id=30529727
Tags: imported, hacker-news
Id: 759a178c-c1a0-11ed-be9f-0242ac110004
Read: Wed Mar 2 17:10:32 2022
https://news.ycombinator.com/item?id=30642452
Tags: imported, hacker-news
Id: 8f7db8ca-c1a0-11ed-a571-0242ac110004
Read: Fri Mar 11 16:58:34 2022
https://news.ycombinator.com/item?id=30674130
Tags: imported, hacker-news
Id: 762d7b26-c1a0-11ed-bb0c-0242ac110004
Read: Mon Mar 14 16:07:03 2022