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"); | |
pub fn main() !void { | |
try serve(8008, handle); | |
} | |
fn serve(port: u16, handler: fn (*std.http.Server.Request) void) !void { | |
var addr = try std.net.Address.parseIp("127.0.0.1", port); | |
var svr = try addr.listen(.{}); | |
defer svr.deinit(); |
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"); | |
pub fn main() void { | |
const maybeA: ?u8 = 1; | |
const maybeB: ?u8 = 2; | |
const maybeC: ?u8 = 3; | |
if (maybeA, maybeB, maybeC) |a, b, c| { | |
std.debug.print("{d} {d} {d}\n", .{ a, b, c}); | |
} | |
} |
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 meta = std.meta; | |
const Example = struct { | |
foo: []const u8, | |
bar: i32, | |
const docs = std.EnumArray( | |
meta.FieldEnum(Example), | |
// 👇 type of value of metadata checked at comptime, can be any type declared |
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"); | |
pub fn main() !void { | |
var args = std.process.args(); | |
_ = args.next(); | |
const path = args.next() orelse { | |
bail("expected path argument. this is the path to the file we're appending metadata to"); | |
}; | |
const platform = args.next() orelse { | |
bail("expected duckdb platform argument. see https://duckdb.org/docs/extensions/working_with_extensions#platforms"); |
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
// remix of https://discordapp.com/channels/605571803288698900/1219282855679496243/1219706356718632981 | |
const std = @import("std"); | |
const Timestamp = struct { | |
seconds: i64, | |
pub fn format( | |
self: @This(), | |
comptime _: []const u8, | |
_: std.fmt.FormatOptions, |
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
// To execute Go code, please declare a func main() in a package "main" | |
package main | |
import ( | |
"log" | |
"reflect" | |
"time" | |
) |
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
import java.io.*; | |
import java.util.*; | |
import static org.junit.Assert.*; | |
// fmt: shift + cmd + f | |
// imports : shift + cmd + o | |
class Solution { | |
// impl | |
// 👇 |
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
[email protected] | |
exports java.io | |
exports java.lang | |
exports java.lang.annotation | |
exports java.lang.invoke | |
exports java.lang.module | |
exports java.lang.ref | |
exports java.lang.reflect | |
exports java.math | |
exports java.net |
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
import java.util.stream.*; | |
import java.util.concurrent.*; | |
import java.util.*; | |
public <T> Stream<T> nonRepeatingStream(List<T> src) { | |
IntSupplier index = () -> ThreadLocalRandom.current().nextInt(0, src.size()); | |
return Stream.iterate( | |
index.getAsInt(), | |
(prev) -> { | |
int next = index.getAsInt(); |
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
use rand; // 0.8.3 | |
use rand::Rng; | |
use std::iter::successors; | |
fn non_repeating<T: std::cmp::PartialEq + Clone>(src: &[T]) -> impl Iterator<Item = &T> + '_ { | |
let mut rng = rand::thread_rng(); | |
successors(Some(&src[rng.gen_range(0..src.len())]), move |n| { | |
let mut next = &src[rng.gen_range(0..src.len())]; | |
while *next == **n { | |
next = &src[rng.gen_range(0..src.len())]; |
NewerOlder