This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "share/atspre_staload.hats" | |
typedef amount = Nat | |
typedef ccn = $extype "int64_t" | |
typedef cvc = [i:nat | i < 9999] int(i) | |
datatype payment = | |
| card of (string, ccn, cvc, amount) | |
| paypal of (string, amount) | |
| cash of (amount) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const c = @cImport({ | |
@cInclude("stdio.h"); | |
}); | |
pub fn main() void { | |
const str = c"\x00" ++ "*" ** 8; | |
var s = @ptrCast([*]const u8, &str[8]); | |
while (s[0] != 0) : (s -= 1) { | |
_ = c.puts(s); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// on macOS: zig build-exe getr.zig --library c --libc-include-dir /usr/local/Cellar/musl-cross/0.9.7_1/libexec/x86_64-linux-musl/include | |
const std = @import("std"); | |
const c = @cImport({ | |
@cInclude("sys/resource.h"); | |
@cInclude("spawn.h"); | |
}); | |
const warn = std.debug.warn; | |
const report_time = | |
\\User time : {} s, {} us |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- gcc -c -fdump-ada-spec "getr.h" -C # where getr.h is #include <sys/resource.h> | |
... | |
pragma Convention (C_Pass_By_Copy, anon1055_anon1068_union); | |
pragma Unchecked_Union (anon1055_anon1068_union);type anon1055_anon1069_union (discr : unsigned := 0) is record | |
case discr is | |
when 0 => | |
ru_nivcsw : aliased long; -- /usr/include/x86_64-linux-gnu/bits/resource.h:281 | |
when others => | |
uu_ru_nivcsw_word : aliased x86_64_linux_gnu_bits_types_h.uu_syscall_slong_t; -- /usr/include/x86_64-linux-gnu/bits/resource.h:282 | |
end case; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// zig build-exe dns1.zig --library c | |
const c = @cImport({ | |
@cInclude("netdb.h"); | |
@cInclude("stdio.h"); | |
}); | |
pub fn main() void { | |
if (c.gethostbyname(c"irc.freenode.net")) |host| { | |
if (host[0].h_addr_list) |res| { | |
if (res[0]) |first| { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const warn = std.debug.warn; | |
pub fn main() void { | |
comptime var x1 = []f64{1, 2, 3}; | |
comptime var x2 = x1 ++ x1; // error to assign x1 here | |
comptime var x3 = ([]f64{1, 2, 3})[0..]; | |
x3 = x3 ++ x3; // no error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// from some C example with DEFINEs | |
const std = @import("std"); | |
fn SQ(x:f64) f64 { return x*x; } | |
fn M0(x:f64,y:f64) u8 { if (SQ(x) + SQ(y)<4) { return 0; } else { return 0xe0; } } | |
fn M1(x:f64,y:f64,x0:f64,y0:f64) u8 { return if (SQ(x)+SQ(y)<4) M0(SQ(x)-SQ(y)+x0,2*(x)*(y)+y0) else 0xc0; } | |
fn M2(x:f64,y:f64,x0:f64,y0:f64) u8 { return if (SQ(x)+SQ(y)<4) M1(SQ(x)-SQ(y)+x0,2*(x)*(y)+y0,x0,y0) else 0xa0; } | |
fn M3(x:f64,y:f64,x0:f64,y0:f64) u8 { return if (SQ(x)+SQ(y)<4) M2(SQ(x)-SQ(y)+x0,2*(x)*(y)+y0,x0,y0) else 0x80; } | |
fn M4(x:f64,y:f64,x0:f64,y0:f64) u8 { return if (SQ(x)+SQ(y)<4) M3(SQ(x)-SQ(y)+x0,2*(x)*(y)+y0,x0,y0) else 0x60; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -ru apr-1.4.8/threadproc/unix/proc.c apr-1.4.8.hack/threadproc/unix/proc.c | |
--- apr-1.4.8/threadproc/unix/proc.c 2011-11-07 12:33:35.000000000 -0600 | |
+++ apr-1.4.8.hack/threadproc/unix/proc.c 2019-03-11 13:23:52.356000000 -0500 | |
@@ -350,6 +350,8 @@ | |
{ | |
int i; | |
const char * const empty_envp[] = {NULL}; | |
+ struct rlimit limits; | |
+ int is_suphp = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# release performance against 400MB log: 2.5s | |
import re, tables, strformat, sequtils, algorithm | |
var emailcounts = initCountTable[string]() | |
let re_sender = re"^(?:\S+ ){3,4}<= ([^@]+@(\S+))" | |
for line in "exim_mainlog".lines: | |
if line =~ re_sender: | |
emailcounts.inc matches[0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# DNS query | |
import nativesockets | |
iterator items(ai: ptr AddrInfo): string = | |
var current = ai | |
while current != nil: | |
yield current.aiAddr.getAddrString | |
current = current.aiNext | |
let ips = getAddrInfo("www.nim-lang.org", |
OlderNewer