Simplest way to post code to blogger for me:
<pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black;overflow-x:scroll">
In HTML mode put code in "Here"
</pre>
Unsorted Wiki
To remember and to share ...
3019/01/19
2020/06/04
Ruby Gem on Mac
# install hombrew ruby, so no mess-up with ruby come with Mac
brew install ruby
# add below path to your environment
export PATH="/usr/local/opt/ruby/bin:$PATH"
export PATH="/usr/local/lib/ruby/gems/2.7.0/bin:$PATH"
# install gem fastlyctl, you will find installed bin file in /usr/local/lib/ruby/gems/2.7.0/bin
gem install fastlyctl
# try it
fastlyctl version
Reference
https://stackoverflow.com/questions/51126403/you-dont-have-write-permissions-for-the-library-ruby-gems-2-3-0-directory-ma
2020/05/06
How tokio join macro works
tokio's join macro is pretty amazing
To find out how this join! macro works exactly, you can do blow to expand the macro to see exact code generated.
rustup toolchain install nightly
cargo install cargo-expand
cargo expandYou will find the expanded code like below
2020/05/05
Usage of serde_json
Some sample code shows behavior of serde_json.
I used to write code like
val.as_object().unwrap().get("field_name").unwrap().as_object().unwrap().get_("sub_field_name").as_str().unwrap().
Turns out that using index of serde_json makes code much less verbose.
2020/04/06
Rust Sync/Await
This blog https://os.phil-opp.com/async-await/ explains well the underlying mechanism of Rust sync and await.
Some useful quote of this long blog that helps to:
- Get an general idea of underlying mechanism
- How to use async/await
Quotes starts from here:
----------------------------------
There are two forms of multitasking: Cooperative, Preemptive multitasking.
The disadvantage of preemption is that each task requires its own stack. Compared to a shared stack, this results in a higher memory usage per task and often limits the number of tasks in the system.
cooperative multitasking lets each task run until it voluntarily gives up control of the CPU.
The idea is that either the programmer or the compiler inserts yield operations into the program.
The idea behind async/await is to let the programmer write code that looks like normal synchronous code, but is turned into asynchronous code by the compiler.
What the compiler does behind this scenes is to transform the body of the async function into a state machine, with each .await call representing a different state.
With a single future, we can always wait for each future manually using a loop as described above. However, this approach is very inefficient and not practical for programs that create a large number of futures.
The purpose of an executor is to allow spawning futures as independent tasks, typically through some sort of spawn method. The executor is then responsible for polling all futures until they are completed. The big advantage of managing all futures in a central place is that the executor can switch to a different future whenever a future returns Poll::Pending. Thus, asynchronous operations are run in parallel and the CPU is kept busy.
Many executor implementations can also take advantage of systems with multiple CPU cores. They create a thread pool that is able to utilize all cores if there is enough work available and use techniques such as work stealing to balance the load between cores. There are also special executor implementations for embedded systems that optimize for low latency and memory overhead.
----------------------------------
Some useful quote of this long blog that helps to:
- Get an general idea of underlying mechanism
- How to use async/await
Quotes starts from here:
----------------------------------
There are two forms of multitasking: Cooperative, Preemptive multitasking.
The disadvantage of preemption is that each task requires its own stack. Compared to a shared stack, this results in a higher memory usage per task and often limits the number of tasks in the system.
cooperative multitasking lets each task run until it voluntarily gives up control of the CPU.
The idea is that either the programmer or the compiler inserts yield operations into the program.
The idea behind async/await is to let the programmer write code that looks like normal synchronous code, but is turned into asynchronous code by the compiler.
What the compiler does behind this scenes is to transform the body of the async function into a state machine, with each .await call representing a different state.
With a single future, we can always wait for each future manually using a loop as described above. However, this approach is very inefficient and not practical for programs that create a large number of futures.
The purpose of an executor is to allow spawning futures as independent tasks, typically through some sort of spawn method. The executor is then responsible for polling all futures until they are completed. The big advantage of managing all futures in a central place is that the executor can switch to a different future whenever a future returns Poll::Pending. Thus, asynchronous operations are run in parallel and the CPU is kept busy.
Many executor implementations can also take advantage of systems with multiple CPU cores. They create a thread pool that is able to utilize all cores if there is enough work available and use techniques such as work stealing to balance the load between cores. There are also special executor implementations for embedded systems that optimize for low latency and memory overhead.
----------------------------------
2019/09/03
Golden summary of Encryption
Encryption helps ensure confidentiality. Hashing can help ensure integrity. Digital signatures or message authentication codes (MAC, including keyed hashing such as HMAC) can be used to verify authenticity.
2019/02/16
Notes of Creating Heroku Python App
Master Tutorial
---------------------------
https://devcenter.heroku.com/articles/getting-started-with-python
Install the pipenv
----------------------------
reference:
https://docs.python-guide.org/dev/virtualenvs/#virtualenvironments-ref
you only need to install the part with "Installing Pipenv"
pipenv install -r requirements.txt
pipenv shell # use ctrl+d to exit
pipenv run python main.py
App Create and Deploy
----------------------------
heroku create
git push heroku master
heroku ps:scale web=1
heroku open
Run local
----------------------------
pipenv shell
python manage.py collectstatic
heroku local web
# then open the browser
---------------------------
https://devcenter.heroku.com/articles/getting-started-with-python
Install the pipenv
----------------------------
reference:
https://docs.python-guide.org/dev/virtualenvs/#virtualenvironments-ref
you only need to install the part with "Installing Pipenv"
pipenv install -r requirements.txt
pipenv shell # use ctrl+d to exit
pipenv run python main.py
App Create and Deploy
----------------------------
heroku create
git push heroku master
heroku ps:scale web=1
heroku open
Run local
----------------------------
pipenv shell
python manage.py collectstatic
heroku local web
# then open the browser
Subscribe to:
Posts (Atom)
Post Code on Blogger
Simplest way to post code to blogger for me: <pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black;overflow-x:...
-
Explain There is not interrupt PIN for PCIe interrupt. When device wants to raise an interrupt, an interrupt message is sent to host via ...
-
Configure Space Addressing One of the major improvements the PCI Local Bus had over other I/O architectures was its configuration mechanism...
-
What is LMA and VMA Every loadable or allocatable output section has two addresses. The first is the VMA, or virtual memory address. This ...