#bash #recommended 233333 #haha #tech
https://github.com/benrady/shinatra/blob/master/shinatra.sh
https://github.com/benrady/shinatra/blob/master/shinatra.sh
#!/usr/bin/env bash
RESPONSE="HTTP/1.1 200 OK\r\nConnection: keep-alive\r\n\r\n${2:-"OK"}\r\n"
while { echo -en "$RESPONSE"; } | nc -l "${1:-8080}"; do
echo "================================================"
done
GitHub
benrady/shinatra
A simple web server in 5 lines of bash. Contribute to benrady/shinatra development by creating an account on GitHub.
duangsuse 买的 《Lua 设计与实现》还是 5.1 时代,之前也没听说过,大概是和 ES6 的修改一样吧,同样位长现在允许 number 和 double 同时使用
不用怕损失精度、溢出什么的了 #lua #PL
Androlua+ 虽然 port 了个 Lua5.3 的过去,但是实际上很多特性没有专门介绍(反正讲了很多人也懒得学),包括 number 细化区分
https://www.lua.org/manual/5.3/manual.html#2
There are eight basic types in Lua: nil, boolean, number, string, function, userdata, thread, and table.
The type nil has one single value, nil, whose main property is to be different from any other value; it usually represents the absence of a useful value.
The type boolean has two values, false and true. Both nil and false make a condition false; any other value makes it true.
The type number represents both integer numbers and real (floating-point) numbers.
The type string represents immutable sequences of bytes. Lua is 8-bit clean: strings can contain any 8-bit value, including embedded zeros ('\0'). Lua is also encoding-agnostic; it makes no assumptions about the contents of a string.
The type number uses two internal representations, or two subtypes, one called integer and the other called float.
Lua has explicit rules about when each representation is used, but it also converts between them automatically as needed (see §3.4.3).
Therefore, the programmer may choose to mostly ignore the difference between integers and floats or to assume complete control over the representation of each number.
Standard Lua uses 64-bit integers and double-precision (64-bit) floats, but you can also compile Lua so that it uses 32-bit integers and/or single-precision (32-bit) floats. The option with 32 bits for both integers and floats is particularly attractive for small machines and embedded systems. (See macro LUA_32BITS in file luaconf.h.)
不用怕损失精度、溢出什么的了 #lua #PL
Androlua+ 虽然 port 了个 Lua5.3 的过去,但是实际上很多特性没有专门介绍(反正讲了很多人也懒得学),包括 number 细化区分
https://www.lua.org/manual/5.3/manual.html#2
There are eight basic types in Lua: nil, boolean, number, string, function, userdata, thread, and table.
The type nil has one single value, nil, whose main property is to be different from any other value; it usually represents the absence of a useful value.
The type boolean has two values, false and true. Both nil and false make a condition false; any other value makes it true.
The type number represents both integer numbers and real (floating-point) numbers.
The type string represents immutable sequences of bytes. Lua is 8-bit clean: strings can contain any 8-bit value, including embedded zeros ('\0'). Lua is also encoding-agnostic; it makes no assumptions about the contents of a string.
The type number uses two internal representations, or two subtypes, one called integer and the other called float.
Lua has explicit rules about when each representation is used, but it also converts between them automatically as needed (see §3.4.3).
Therefore, the programmer may choose to mostly ignore the difference between integers and floats or to assume complete control over the representation of each number.
Standard Lua uses 64-bit integers and double-precision (64-bit) floats, but you can also compile Lua so that it uses 32-bit integers and/or single-precision (32-bit) floats. The option with 32 bits for both integers and floats is particularly attractive for small machines and embedded systems. (See macro LUA_32BITS in file luaconf.h.)
此外,Lua 5.3 还加入了位运算特性,也是一个值得注意的部分(貌似 5.2 就有)
Lua 作为嵌入式辅助语言是非常缺少高性能实现啊... 😶
Lua 作为嵌入式辅助语言是非常缺少高性能实现啊... 😶
#javascript #blog (虽然很简单)算法整理
https://blog.lwl12.com/read/ife-s-task01.html "IFE 2015 Summer Game Qihang TASK01"
虽然只是很简单的表达式,我推敲了一会,主要是考虑概率平不平均,实际上很平均(主要是我数学不好 233
Math.random 会返回一个小数,介于 0 到 1 之间
三倍之后,0.1 0.2 0.3 (下的)会舍为 1 ( 0.9 最高
0.4 0.5 0.6 会舍为 2 ( 1.8 最高
0.7 0.8 0.9 会舍为 3 ( 2.7 最高
然后就是
btw: JavaScript 没 goto 语法啊...
不知道能不能再搞个什么特别的加速啥的(billion 级的数据 23333 XD
https://blog.lwl12.com/read/ife-s-task01.html "IFE 2015 Summer Game Qihang TASK01"
Math.ceil(Math.random() * 3)虽然只是很简单的表达式,我推敲了一会,主要是考虑概率平不平均,实际上很平均(主要是我数学不好 233
Math.random 会返回一个小数,介于 0 到 1 之间
三倍之后,0.1 0.2 0.3 (下的)会舍为 1 ( 0.9 最高
0.4 0.5 0.6 会舍为 2 ( 1.8 最高
0.7 0.8 0.9 会舍为 3 ( 2.7 最高
然后就是
function randomPos() {
return Math.ceil(Math.random() * 3);
}
function judge(userPos, botPos) {
if (userPos == botPos) return 0;
// 1: 石头 2: 剪刀 3: 布
if (userPos == 3 && botPos == 1) return -1;
if (botPos == 1 && userPos == 3) return 1;
if (userPos > botPos) return -1;
return 1; // bot wins
}btw: JavaScript 没 goto 语法啊...
不知道能不能再搞个什么特别的加速啥的(billion 级的数据 23333 XD
Forwarded from duangsues.is_a? SaltedFish
JavaScript Number 数值一大就要溢出(划掉)损失精度,气死
还有我的 NodeJS v8 上居然没有 Integer 类,这是为何,而且 "use strict" 了尾递归优化也不能生效...
还有我的 NodeJS v8 上居然没有 Integer 类,这是为何,而且 "use strict" 了尾递归优化也不能生效...
(define fibonacci#cs #pl #scheme Y 组合子版本的 Fibonacci(其实只是我懒得输入
(lambda (nth)
; 不会写了...
))
(fibonacci n 1 2) 然后从 《The Little Schemer》儿童书上抄写的模式 XD至于为什么用 Y Combinator 实现递归是因为我不想多定义一个符号了(
(define fibonacci或者,也可以使用匿名函数版本 这个我没有抄模式...
(lambda (n a b)
(cond
((= 0 n) a + b)
(else (fibonacci (- n 1) b (+ a b))))))
(define fibo (lambda (n) (fibonacci n 1 2)))
(define fibonacci
((lambda (fibonacci-def)
(lambda (n)
(cond
((= n 0) 0)
(else (fibonacci-def fibonacci-def (- n 1) 0 1))))) ; 我把这里能访问到的 fibonacci-def 传给了真正的子程序
(lambda (l nth a b) ; 第一项是这个 lambda 自身
(cond
((= nth 0) (+ a b))
(else (l l (- nth 1) b (+ a b)))))))
; 这是真的演算 lambda
(lambda (nth a b)
(cond
((= nth 0) (+ a b))
(else (fibonacci-def (- n 1)))))
duangsuse::Echo
由于使用了尾调用优化,Chez Scheme 可以轻松地把递归转化为高效率循环,Scheme 使用递归实现循环,目前这居然还是我第一次看到 TCO... 好感动 2333
我的 JavaScript Node v8.x
奇妙的是,它居然还使用了 RangeError...
> fibonacci(999)
1.8412729310978296e+209
> fibonacci(9999)
RangeError: Maximum call stack size exceeded
奇妙的是,它居然还使用了 RangeError...
duangsuse::Echo
(define fibonacci (lambda (nth) ; 不会写了... )) #cs #pl #scheme Y 组合子版本的 Fibonacci(其实只是我懒得输入 (fibonacci n 1 2) 然后从 《The Little Schemer》儿童书上抄写的模式 XD 至于为什么用 Y Combinator 实现递归是因为我不想多定义一个符号了( (define fibonacci (lambda (n a b)…
真正的 Y 组合子(应用序 Y 组合子,Applicative-Order Y Combinator)长这样:
https://gist.github.com/z5h/5102747
这里有更多应用序 Y 组合子,Clojure 编写
(define Y鬼知道它是做什么的... cs::PL 和递归基础之一(跑
(lambda (λ)
((lambda (f) (f f))
(lambda (f)
(λ (lambda (ϡ) (f f) ϡ))))))
https://gist.github.com/z5h/5102747
这里有更多应用序 Y 组合子,Clojure 编写
Gist
Applicative-Order Y Combinator (Clojure Version)
Applicative-Order Y Combinator (Clojure Version). GitHub Gist: instantly share code, notes, and snippets.
duangsuse::Echo
🐶 Sticker
最近观察到人数回落,Cheers! 🎉
频道本来是给一些乐意学习并了解新知识、有趣的技术的人来的
所以可能不实用。作者自己水平不行而且连 Android 应用都不会写、PHP 也不会、Web 应用没写几个、游戏同上
是给类似的菜鸡们写的,一起进步,不然为何不去 @ice1000 或者 RednaxelaFX 等 CS 狂那里
如果你对这些无用的知识不感兴趣,欢迎 Leave Channel.
我很乐意有很多人看频道的消息,但是这些也都是虚的,现在除了高中生和部分大学生,大概没几个人愿意学不实用、不简单的知识了
duangsuse 的自我介绍现在是 "菜是原罪" Technical unfamiliar is the root of all evil
就是说 要通过不断的学习和尝试、写代码来弥补自己技术上,不管是哪方面哪怕是诸如动画效果、PHP 程序一类的无知,当然原话谁说的不重要(
频道本来是给一些乐意学习并了解新知识、有趣的技术的人来的
所以可能不实用。作者自己水平不行而且连 Android 应用都不会写、PHP 也不会、Web 应用没写几个、游戏同上
是给类似的菜鸡们写的,一起进步,不然为何不去 @ice1000 或者 RednaxelaFX 等 CS 狂那里
如果你对这些无用的知识不感兴趣,欢迎 Leave Channel.
我很乐意有很多人看频道的消息,但是这些也都是虚的,现在除了高中生和部分大学生,大概没几个人愿意学不实用、不简单的知识了
duangsuse 的自我介绍现在是 "菜是原罪" Technical unfamiliar is the root of all evil
就是说 要通过不断的学习和尝试、写代码来弥补自己技术上,不管是哪方面哪怕是诸如动画效果、PHP 程序一类的无知,当然原话谁说的不重要(
duangsuse::Echo pinned «最近观察到人数回落,Cheers! 🎉 频道本来是给一些乐意学习并了解新知识、有趣的技术的人来的 所以可能不实用。作者自己水平不行而且连 Android 应用都不会写、PHP 也不会、Web 应用没写几个、游戏同上 是给类似的菜鸡们写的,一起进步,不然为何不去 @ice1000 或者 RednaxelaFX 等 CS 狂那里 如果你对这些无用的知识不感兴趣,欢迎 Leave Channel. 我很乐意有很多人看频道的消息,但是这些也都是虚的,现在除了高中生和部分大学生,大概没几个人愿意学不实用、不简单的知识了…»