博文

目前显示的是标签为“nim”的博文

Compiling the Nim program on the OpenWRT router across platforms on Linux

Nim   is a very fun language, let's see how to run a program written by Nim on a router. Ready to work Install the Nim compiler, if you use Debian GNU/Linux,  apt install nim you can A mipsel OpenWRT router Write a Nim program Come to Hello World: echo "hello world" Prepare OpenWRT's build toolchain aria2c 'http://archive.openwrt.org/chaos_calmer/15.05.1/ramips/mt7621/OpenWrt-SDK-15.05.1-ramips-mt7621_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64.tar.bz2' tar xvf OpenWrt-SDK-15.05.1-ramips-mt7621_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64.tar.bz2 Configure the PATH environment variable to let the Nim compiler find the build toolchain export PATH = /dev/shm/OpenWrt-SDK-15.05.1-ramips-mt7621_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64/staging_dir/toolchain-mipsel_1004kc+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin/: $PATH Start compiling! nim -d:release --opt = size -d:ssl --cpu:mipsel --os:linux --gcc.exe:mipsel-openwrt-linux-gcc --gcc.linke...

在Linux上跨平台编译OpenWRT路由器上的Nim程序

Nim  是个很好玩儿的语言,我们来看看怎么在路由器上运行Nim编写的程序 准备工作 安装好Nim编译器,如果你用Debian GNU/Linux, apt install nim 即可 一台mipsel的OpenWRT路由器 写个Nim程序 来个Hello World: echo "hello world" 准备OpenWRT的编译工具链 aria2c 'http://archive.openwrt.org/chaos_calmer/15.05.1/ramips/mt7621/OpenWrt-SDK-15.05.1-ramips-mt7621_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64.tar.bz2' tar xvf OpenWrt-SDK-15.05.1-ramips-mt7621_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64.tar.bz2 配置PATH环境变量,让Nim编译器找到编译工具链 export PATH = /dev/shm/OpenWrt-SDK-15.05.1-ramips-mt7621_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-x86_64/staging_dir/toolchain-mipsel_1004kc+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin/: $PATH 开始编译吧! nim -d:release --opt = size -d:ssl --cpu:mipsel --os:linux --gcc.exe:mipsel-openwrt-linux-gcc --gcc.linkerexe:mipsel-openwrt-linux-gcc c helloworld.nim 在我的机器上编译之后187KB,对比Golang编译出来的十几MB,真是轻量太多了, 如果还想再小,可以用 upx 神器压缩一下: upx -9 --best --lzma helloworld 这样就只要70KB了,对于只有几MB ROM的路由器,真是福音

一个用Nim语言实现的轻量级书签管理器

图片
https://github.com/muxueqz/skybook 特点 搜索功能:借助浏览器的自定义搜索引擎功能 存储为json文件,可以支持git版本化管理和备份到Github上 本地运行,不依赖网络服务,也不用担心服务器被关 跨平台,支持Linux/Windows/macOS 快速开始 安装好Nim编译器,如果你用Debian GNU/Linux, apt install nim 即可 安装 nimble install skybook skybook &> /dev/shm/skybook.log & 书签数据默认会保存在当前目录的 bookmarks.db 里,大家可以针对这个文件备份 截图

只用65行Nim代码写一个自己的区块链

图片
这篇文章的原文为英文,出自 Coral Health公司:  Code your own blockchain in less than 200 lines of Go! , 本篇转载的译文来自魏佳翻译的:  只用200行Go代码写一个自己的区块链! ,高可用架构的公众号 这篇教程改编自Go版本实现的区块链文章 (译文: 200行代码就能写出区块链)。我使用 Nim 语言实现了它 因为我们是一家从事医疗健康领域的科技公司,所以我们采用人类平静时的心跳数据(BPM心率)作为这篇文章中的示例数据。让我们先来统计一下你一分钟内的心跳数,然后记下来,这个数字可能会在接下来的内容中用到。 几乎每个开发者都听说过区块链但是大部分人还是不清楚它是如何工作的。他们可能只是因为比特币才知道区块链,或许还知道一些智能合约的东东。这篇文章尝试帮助你使用Go编写你自己的简单的区块链。通过本教程,你可以编写和运行一个本地的区块链,并且可以在浏览器中查看它。 通过本文,你将可以做到: 创建自己的区块链 理解 hash 函数是如何保持区块链的完整性 如何创造并添加新的块 多个节点如何竞争生成块 通过浏览器来查看整个链 所有其他关于区块链的基础知识 但是,对于比如 工作量证明算法(PoW)  以及 权益证明算法(PoS) 这类的共识算法文章中将不会涉及。同时为了让你更清楚的查看区块链以及块的添加,我们将网络交互的过程简化了,关于 P2P 网络比如“全网广播”这个过程等内容将在下一篇文章中补上。 让我们开始吧! 设置 我们假设你已经具备一点 Nim 语言的开发经验。在安装和配置 Nim 开发环境后之后,我们还要获取以下一些依赖: nimble install jester jester是Nim语言的一个Web框架,我们用它来提供Web服务 导入依赖 我们将所有的依赖包以声明的方式导入进去: import times import strutils import std / sha1 import jester 数据模型 接着我们来定义一个结构体,它代表组成区块链的每一个块的数据模型: type Block = object Index , BPM : int ...