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
| import net | |
| // Connect with: `nc 127.0.0.1 12345` | |
| fn handle_connection(con net.Socket) { | |
| eprintln('new client connected') | |
| defer { eprintln('closing connection: $con') con.close() or { } } | |
| con.send_string("Welcome to V's TCP Echo server.\n") or { return } | |
| for { | |
| line := con.read_line() | |
| if line.len == 0 { return } | |
| eprintln('received line: ' + line.trim_space()) |
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
| import v.ast | |
| import v.table | |
| import v.token | |
| fn s(x ast.Stmt) ast.Stmt { return x } | |
| fn es(x ast.Expr) ast.Expr { return x } | |
| fn stmts_last_expr_opt(stmts []ast.Stmt) ?ast.ExprStmt { | |
| le := stmts[ stmts.len - 1 ] | |
| match le { |
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
| import os | |
| import rand | |
| import time | |
| import encoding.base64 | |
| fn main() { | |
| rand.seed(time.sys_mono_now()) | |
| mut ascii_data_output := '' | |
| mut key := '' | |
| process_menu := os.input('Enter the process you would like to occur:\n1. Encipher \n2. Decipher\n') |
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
| // Copyright (c) 2019-2020 Alexander Medvednikov. All rights reserved. | |
| // Use of this source code is governed by an MIT license | |
| // that can be found in the LICENSE file. | |
| module main | |
| import rand | |
| import time | |
| import gx | |
| import gg |
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
| /* | |
| ** 2001-09-15 | |
| ** | |
| ** The author disclaims copyright to this source code. In place of | |
| ** a legal notice, here is a blessing: | |
| ** | |
| ** May you do good and not evil. | |
| ** May you find forgiveness for yourself and forgive others. | |
| ** May you share freely, never taking more than you give. | |
| ** |
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
| import os | |
| import os.cmdline | |
| import rand | |
| import benchmark | |
| // | |
| // Example run with: | |
| // ./v -prod -cc tcc run rand_uuid4_compare.v -repetitions 1000000 | |
| // ./v -prod -cc gcc-9 run rand_uuid4_compare.v -repetitions 1000000 | |
| // ./v -prod -cc clang-10 run rand_uuid4_compare.v -repetitions 1000000 |
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
| import os | |
| import os.cmdline | |
| import rand | |
| import benchmark | |
| // | |
| // Example run with: | |
| // ./v -prod -cc tcc run rand_uuid_v4__vs__rand_ulid.v -repetitions 1000_000 | |
| // ./v -prod -cc gcc-9 run rand_uuid_v4__vs__rand_ulid.v -repetitions 1000_000 | |
| // ./v -prod -cc clang-10 run rand_uuid_v4__vs__rand_ulid.v -repetitions 1000_000 |
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
| type SuccessCode int | |
| type FailureCode int | |
| type Code = SuccessCode | FailureCode | |
| fn (x SuccessCode) hex() string { return 'my hex: ' + int(x).hex() } | |
| // | |
| fn (x SuccessCode) str() string { return 'SC(' + int(x).str() +')' } | |
| fn (x FailureCode) str() string { return 'FC(' + int(x).str() +')' } | |
| fn (x Code) str() string { | |
| mut res := '' |
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
| import os | |
| import json | |
| struct User { name string age int = 30 } | |
| fn main(){ | |
| u := User{ name: os.args[1..].join(' ') } | |
| smessage := json.encode(u) | |
| C.write(1, &smessage.len, 4) | |
| C.write(1, smessage.str, smessage.len) | |
| } |
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
| import json | |
| struct User { name string age int } | |
| fn main(){ | |
| mut len := 0 | |
| C.read(0, &len, 4) | |
| if len > 1024 { panic('input too large') } | |
| mut buf := malloc(len) | |
| C.read(0, buf, len) | |
| s := string(buf, len) | |
| println('received s: $s') |