Skip to content

Instantly share code, notes, and snippets.

const std = @import("std");
pub fn Matrix(comptime T: type, width: usize, height: usize) type {
return struct {
const Self = @This();
width: usize = width,
height: usize = height,
array: [height * width]T = undefined,
slice: MatrixSlice(T) = MatrixSlice(T){
@fengb
fengb / _comparison.zig
Created May 28, 2019 23:24
@memcpy vs std.mem.cpy
const std = @import("std");
const size = 64;
var targetBase: [size]u8 = undefined;
var srcBase: [size]u8 = []u8{42} ** size;
export var target = targetBase[0..size];
export var src = srcBase[0..size];
@fengb
fengb / writer.go
Created May 22, 2019 15:51
Go vs Zig error handling
func WriteResponse(w io.Writer, st Status, headers []Header, body io.Reader) error {
_, err := fmt.Fprintf(w, "HTTP/1.1 %d %s\r\n", st.Code, st.Reason)
if err != nil {
return err
}
for _, h := range headers {
_, err := fmt.Fprintf(w, "%s: %s\r\n", h.Key, h.Value)
if err != nil {
return err
@fengb
fengb / malloc.wat
Last active April 25, 2019 15:29
Using malloc from WASI-sysroot
(module
(type (;0;) (func))
(type (;1;) (func (param i32) (result i32)))
(type (;2;) (func (param i32)))
(func $__wasm_call_ctors (type 0))
(func $abort (type 0)
unreachable
unreachable)
(func $sbrk (type 1) (param i32) (result i32)
block ;; label = @1
@fengb
fengb / hello-world.gdl
Last active April 18, 2019 20:34
gd-lisp
((()())(()())(()())(()())(()())(()())(()())(()())((())())()(()())(()())(()())(()
())((())())()(()())(()())()(()())(()())(()())()(()())(()())(()())()(()())(())(()
)(())(())((()))(()(()))()(()())()(()())()((()))()()(()())((())())(())(()(()))(()
)((()))(()(()))()()(()()())()((()))((()))((()))(()()())(()())(()())(()())(()())(
()())(()())(()())(()()())(()()())(()())(()())(()())(()()())()()(()()())(())((())
)(()()())(())(()()())(()())(()())(()())(()()())((()))((()))((()))((()))((()))(((
)))(()()())((()))((()))((()))((()))((()))((()))((()))((()))(()()())()()(()())(()
()())()(()())(()())(()()()))
@fengb
fengb / lodash-then.js
Created December 5, 2018 18:52
await lodash value()
_.prototype.then = function(...args) { return Promise.resolve(this.value()).then(...args) }
/*
async function convert(array) {
const converted = await _.chain(array)
.filter(x => x % 2)
.map(x => x * 2)
}
*/
Project.joins(
activities: Activity.active.group(:project_id).select(:project_id, 'COUNT(*) as "count"')
).where(activities: { count: [1..2, 3..4] })
#!/bin/bash
target_ip=255.255.255.255
whitelist=(
localhost.localdomain
local
localhost
broadcasthost
0.0.0.0
```
✖ rejects after timeout
HeadlessChrome 0.0.0 (Mac OS X 10.12.6)
TypeError: { __flags:
{ ssfi: [Function: proxyGetter],
lockSsfi: undefined,
object: {},
message: undefined },
assert: [Function],
__methods:
@fengb
fengb / pipe.py
Last active October 24, 2017 19:31
from functools import partial
class l(object):
def __init__(self, func, *args, **kwargs):
self.func = func
self.args = args
self.kwargs = kwargs
def __ror__(self, lhs):
return self.func(lhs, *args, **kwargs)