Cocoa Oikawa

从零开始的 Rust 学习笔记(3)——Yet Another Way to Kill Your Brain

于是结合前面看到的语法,再加上 Google 的帮助,用 Rust 来写一个 Brainfuck 解释器吧~

这一篇与另一篇 post 联动,Brainfuck Interpreter in C++17——A Modern Approach to Kill Your Brain

其实在有了 C++ 写的经历之后,用 Rust 来重写一次,几乎就是熟悉一下 Rust 的基本语法,然后一些小的地方(比如 std::vector, std::stack, std::map 在 Rust 中的等价的类是什么)就靠着 Google 和 Rust 官方文档基本就可以写出来了

另外 Brainfuck 解释器的话,与别的很多东西比起来,似乎没有那么困难,写起来还是蛮快的

当然,有些 C++ 里的就没法依葫芦画瓢放到 Rust 里了,但终归只是一些小的修改~

Continue reading 从零开始的 Rust 学习笔记(3)——Yet Another Way to Kill Your Brain

从零开始的 Rust 学习笔记(0)

----------------------------
| Hello fellow Rustaceans  |
----------------------------
              \
               \
                  _~^~^~_
              \) /  o o  \ (/
                '_   -   _'
                / '-----' \

一点点前言~这个系列一大部分算是学习 Rust 语言的自用笔记,另一部分也算是分享给有需要的人,整体上来说会跟着「The Rust Programming Language」这本书来走,可能偶尔也会突然自己写点什么小东西~

虽然说是自用笔记,但是既然写了还是会尽力让看到的人能够看明白这样子;同时也因为是自用笔记,所以在跟着「The Rust Programming Language」书的时候,并不一定会在所有东西第一次出现时就解释得非常清晰,我会以自己的学习风格为主来写这个系列

首先是安装 Rust,https://www.rust-lang.org/learn/get-started,打开这个链接之后会见到如何安装 Rust 的操作。比如 macOS 或者其他 Unix-like 的系统的话,则是利用如下命令安装

curl https://sh.rustup.rs -sSf | sh
Continue reading 从零开始的 Rust 学习笔记(0)

Magic Image(3)——Implementation in Python3 with Either OpenCV3 or PIL

It has been 3 years since the last update on Magic Image, https://blog.0xbbc.com/2016/09/magic-image2-mathematical-model/, which talked about the mathematical model of creating the mix image.

And to be honest, the Python implementation actually wrote 4 months ago, but it only support OpenCV then. And today, out of personal interest, I added PIL support. Now it could run with PIL only. (But if it detects the existence of OpenCV, that would be preferred)

Continue reading Magic Image(3)——Implementation in Python3 with Either OpenCV3 or PIL

Maximum Rectangular Area in Histogram

The description of the maximum rectangular area in histogram problem is fairly simple. Given an array of the height of continuous bars with equal width, and the goal is to find the maximum rectangular area inside them. For example, the following figure shows the maximum rectangular area in pink of height array [1, 2, 3, 4, 5], which is 9.

Let's breakdown the problem. To form such a rectangular area, the following constraint must be satisfied.

All bars inside the area is at least as high as the rectangular.

Which suggests that no matter how we choose the rectangular, all involved bars must be continuous and the best height we could reach is limited to the lowest one.

As shown above, the maximum height of the rectangular area is limited to the lowest involved bar. (The height of the lowest one is mark in pink).

Continue reading Maximum Rectangular Area in Histogram

Rewrite the styled code in HTML generated by Apple to WordPress compatible HTML

My first blog writing was in 2013, and at that time, WordPress was able to handle the styled code correctly, i.e., the code preserved the syntax highlight when I copy it from Xcode / CodeRunner and paste into the WordPress editor. The editor was capable of converting or persevering the colour info, and it did a great job of formatting the styled code into HTML.

Just like this post, https://blog.0xbbc.com/2013/08/assertmacros-problem/. The code shown below

typedef int (*PYStdWriter)(void *, const char *, int);
static PYStdWriter _oldStdWrite;

could be nicely formatted into the corresponding HTML code

<span style="color: #bb2ca2;">typedef</span> <span style="color: #bb2ca2;">int</span> (*PYStdWriter)(<span style="color: #bb2ca2;">void</span> *, <span style="color: #bb2ca2;">const</span> <span style="color: #bb2ca2;">char</span> *, <span style="color: #bb2ca2;">int</span>);
<span style="color: #bb2ca2;">static</span> <span style="color: #4f8187;">PYStdWriter</span> _oldStdWrite;

However, it was about the time WordPress upgraded to 3.9, the aforementioned functionality was removed. Although there are tens of syntax highlighting plugins, but I don't really like the colour schemes they offer. Besides, sometimes I may need to highlight a small portion of code. Such as this post, https://blog.0xbbc.com/2017/05/the-reason-that-codesign-remove-signature-generates-malformed-macho-still-remains-mystery/

/*
* If this has a code signature load command reuse it and just change
* the size of that data.  But do not use the old data.
*/
if(object->code_sig_cmd != NULL){
    if(object->seg_linkedit != NULL){
        object->seg_linkedit->filesize += arch_signs[i].datasize - object->code_sig_cmd->datasize; 
        if(object->seg_linkedit->filesize > object->seg_linkedit->vmsize)

As you can see, using native HTML code could enable extra control and functionality.

Continue reading Rewrite the styled code in HTML generated by Apple to WordPress compatible HTML

すごーい!たーのしー!