This file contains hidden or 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
// This is for the development branch of Zig. | |
// See https://gist.github.com/karlseguin/c6bea5b35e4e8d26af6f81c22cb5d76b for a version that works | |
// on Zig 0.14.1. | |
// in your build.zig, you can specify a custom test runner: | |
// const tests = b.addTest(.{ | |
// .root_module = $MODULE_BEING_TESTED, | |
// .test_runner = .{ .path = b.path("test_runner.zig"), .mode = .simple }, | |
// }); |
This file contains hidden or 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 zul = @import("zul"); | |
const Allocator = std.mem.Allocator; | |
const WriteCtx = struct { | |
times: u32, | |
data: []const u8, | |
expected: []const u8, | |
arr: std.ArrayList(u8), |
This file contains hidden or 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 LOOPS = 1000; | |
pub fn main() !void { | |
var in: [10000]u8 = undefined; | |
try std.os.getrandom(&in); | |
var fbs = std.io.fixedBufferStream(&in); | |
var out: [10000]u8 = undefined; |
This file contains hidden or 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
// This is for the stable version of Zig (0.14.1) | |
// See https://gist.github.com/karlseguin/e8e74cf5260435ec7cbf3e4c71605722 | |
// for a version that tracks Zig's development branch. | |
// in your build.zig, you can specify a custom test runner: | |
// const tests = b.addTest(.{ | |
// .target = target, | |
// .optimize = optimize, | |
// .test_runner = .{ .path = b.path("test_runner.zig"), .mode = .simple }, // add this line | |
// .root_source_file = b.path("src/main.zig"), |
This file contains hidden or 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 ITERATIONS = 1_000_000; | |
pub fn main() !void { | |
benchmark("needle.len == 1, haystack.len == 11 ", "hello world", "w", 6); | |
benchmark("needle.len == 1, haystack.len == 3091", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris sit amet erat elit. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Mauris cursus quis eros quis vestibulum. Vestibulum in convallis nulla. Nulla mauris velit, tempus id varius sit amet, sodales et magna. Aenean vel augue vitae erat luctus maximus. Nam dignissim diam felis, id fermentum neque dapibus quis. Quisque volutpat ac nibh a blandit. Aenean id felis aliquam, aliquet lorem vel, lobortis ligula. Morbi lacinia risus ac dictum accumsan. Maecenas dapibus elit in magna porta tempus. Proin luctus neque sed erat sagittis gravida. Praesent at lacinia libero.Curabitur sagittis risus ut suscipit cursus. Maecenas at gravida turpis, id malesuada felis. Praesent velit dui, pulvinar eget vehicula sed, semper |
This file contains hidden or 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 mem = std.mem; | |
const ITERATIONS = 20_000; | |
pub fn main() !void { | |
try benchmark("empty", "", true); | |
try benchmark("short.ascii", "it's over 9000!!", true); | |
try benchmark("long.ascii", "Lorem ipsum dolor sit amet, pri legere suscipit repudiare at, cu vix aliquip pertinacia quaerendum, in eam dicat cetero eripuit. Duo odio nonumy viderer at, et sea vidit dolor animal, has persius conceptam id. Vide idque copiosae ut qui, ut lorem atomorum mei, in eos suscipit eleifend. Illud principes no eos, pri dolorem singulis ne, ex pri malorum argumentum scribentur. Et altera regione per. Disputando contentiones no mei, et vel discere meliore constituam. Te quo legere nostrum deleniti, ad eros putent tritani per.Repudiandae mediocritatem ut est, ex sea dicit evertitur. Per tritani detraxit an. Pro no fastidii tractatos, per purto affert accusata no, affert consequat mel ea. Cum ex postulant gubergren, has quot vidit argumentum no.Eu est esse feugait, mea no augue debet constituam. Sea s |
This file contains hidden or 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
# see https://www.openmymind.net/Elixir-Without-Ecto/ | |
defmodule A.DB do | |
defmacro __using__(_) do | |
quote location: :keep do | |
@name __MODULE__ | |
def child_spec(opts) do | |
%{ | |
id: __MODULE__, |
This file contains hidden or 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
// For Zig 0.12 | |
const std = @import("std"); | |
const net = std.net; | |
const ArenaAllocator = std.heap.ArenaAllocator; | |
pub fn main() anyerror!void { | |
var gpa = std.heap.GeneralPurposeAllocator(.{}){}; | |
const allocator = gpa.allocator(); |
This file contains hidden or 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
# WAFs are a waste of time. False positives negatively impact actual users. | |
# And for what? Protection against vulnerabilities that, if you still have | |
# in this day in age, you're in more trouble than you think. | |
# Still, to keep my logs clean, I like to run something like the follwoing: | |
location ~ \.php$ { access_log off; return 444; } | |
location ~ \.asp$ { access_log off; return 444; } | |
location ~ \.aspx$ { access_log off; return 444; } | |
location ~ /Admincenter/ { access_log off; return 444; } | |
location /console/ { access_log off; return 444; } |
This file contains hidden or 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
var Util util | |
type util struct{} | |
func (_ util) PadLeft(s string, n int) string { | |
//... | |
} | |
// ... |
NewerOlder