Compare commits

..

41 Commits

Author SHA1 Message Date
root d1749b61da (bash) adding suffix to each element of an array 2026-04-13 09:22:21 +02:00
scbj fc655cd6ad (graphviz) initial testing 2026-04-10 09:40:36 +02:00
root 118fcef730 (bash) arrays are weird 2026-02-19 23:47:58 +01:00
scbj 7477a1dc37 (bash) test tput to format text output 2026-02-03 15:43:18 +01:00
scbj 0f7acf58e7 (clang) tested array initialisation in 2026-02-03 10:02:31 +01:00
scbj ac3fa61211 (clang) added targets rebuild and run 2026-02-03 10:02:24 +01:00
root 8bc0c27ab2 (bash) robust way to get path to script 2026-01-29 15:06:39 +01:00
scbj faecef25ce (clang) renamed C project to clang 2026-01-09 14:01:23 +01:00
scbj a08e7d979c (clang) const void* const pointer confusion 2026-01-09 14:00:32 +01:00
scbj 56a7cb865a (clang) added project for C 2026-01-09 14:00:28 +01:00
scbj cb463b0207 (rust) temperature type and conversions 2025-11-26 14:55:39 +01:00
scbj 5900789ce4 (zig) extended vector.rs 2025-10-06 21:33:33 +02:00
scbj 42f5119f42 (zig) fixed output of vector.drain() 2025-10-06 15:25:34 +02:00
root f7d6c7c902 (zig) started implementing vector type 2025-10-05 23:28:58 +02:00
scbj 52365e7b08 (rust) get tcpstream peer address 2025-09-23 10:40:28 +02:00
scbj 28a1d3dada (rust) **very** basic restapi with axum 2025-09-18 10:39:50 +02:00
scbj 1e7c7d7cba (rust) removed obsolete code 2025-09-18 08:56:48 +02:00
scbj 8749cbdad7 (rust) macaddress type tests 2025-09-08 16:13:23 +02:00
root e34990fc31 (zig) read and write files 2025-09-08 16:11:46 +02:00
scbj 34ec866782 (rust) tcpstream io with vectors 2025-09-08 15:55:52 +02:00
scbj cd7b47d3e7 (rust) tested communcication over tcp with cobs and cbor 2025-07-31 16:15:49 +02:00
scbj 462d45ffd0 (rust) started another cobs test 2025-07-31 16:15:43 +02:00
scbj f5a20d500e (zig) filesystem tests 2025-07-18 16:54:09 +02:00
scbj 753163d28e (zig) added symbolic link to executable 2025-07-18 10:07:15 +02:00
scbj e5a338ae64 (rust) tested cobs crate 2025-07-18 10:06:09 +02:00
scbj 860fed5810 (zig) added test project for zig 2025-07-10 09:59:17 +02:00
root 1d3c3b1930 (rust) ciborium! 2025-07-07 14:50:20 +02:00
scbj b02682ab70 (rust) quick serde/json tryout 2025-07-04 14:52:37 +02:00
scbj b86e403814 (rust) reading interface addresses 2025-06-26 08:51:31 +02:00
root 1acb77331b (rust) PathBuf push() behaviour 2025-06-24 19:26:51 +02:00
scbj 2b52a3d949 (bash) test on behaviour of sourcing 2025-06-23 10:55:58 +02:00
scbj 9b426e85e0 (bash) renamed bash test file to bash-test.sh .. 2025-06-23 10:53:25 +02:00
scbj a545b29f03 (rust) prost: test of protobuf en/decoding and transmission via tcp 2025-06-03 15:50:25 +02:00
scbj a7d09cb062 (rust) prost: added simple protobuf sample for testing 2025-06-02 16:05:05 +02:00
root 4933c7dd14 added small-lorem.md with one paragraph for quick debugging of shell
commands
2025-05-29 16:37:18 +02:00
root 954c450b7e (rust) file transfer via tcp
added lorem.md for tests
2025-05-20 13:46:46 +02:00
root 705aea3ba9 (rust) sending files via tcp 2025-05-20 13:46:42 +02:00
scbj 5ce940c8b9 (rust) sqlx: inserted a rust type and sql column for the log type 2025-05-20 12:23:13 +02:00
scbj 3dc3d46a21 (rust) sqlx tests for armasuisse 2025-05-15 15:35:13 +02:00
root d1297d6e83 (rust) very basic command handler 2025-04-29 10:46:08 +02:00
root 115cc27152 initial commit 2025-04-29 08:51:10 +02:00
21 changed files with 2053 additions and 120 deletions
-117
View File
@@ -1,117 +0,0 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too.
When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights.
We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations.
Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and modification follow.
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program.
You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License.
c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program.
In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License.
3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable.
If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance.
5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License.
7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice.
This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation.
10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found.
one line to give the program's name and an idea of what it does. Copyright (C) yyyy name of author
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker.
signature of Ty Coon, 1 April 1989 Ty Coon, President of Vice
-3
View File
@@ -1,3 +0,0 @@
# test-projects
projects to test specific features of programming languages
Executable
+11
View File
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
array=("test0" "test1" "test2")
suffix="henlo"
echo "${array[@]}"
echo ""
array=("${array[@]/%/${suffix}}")
echo "${array[@]}"
+13
View File
@@ -0,0 +1,13 @@
bin/
*.o
*.pdf
*.a
*.so
*.tar
*.zip
*.xz
*.gz
+66
View File
@@ -0,0 +1,66 @@
SHELL := /usr/bin/env bash
PREFIX :=
CC := $(PREFIX)gcc
LD := $(PREFIX)ld
SIZE := $(PREFIX)size
GDB := $(PREFIX)gdb
NAME := c-test-project
SRC_DIR := ./src
INC_DIR := ./inc
BIN_DIR := ./bin
OBJ_DIR := $(BIN_DIR)/obj
OPT_LEVEL := -g3 \
-O0
C_SRC := main.c
C_DEF :=
C_DEF := $(addprefix -D, $(C_DEF))
C_INC := $(INC_DIR)
C_INC := $(addprefix -I, $(C_INC))
C_FLAGS := $(C_DEF) \
$(C_INC) \
$(OPT_LEVEL) \
-Wall \
-Wextra \
-Wpedantic \
-Wconversion \
-Wsign-conversion \
-Wsign-compare \
-Wcast-align=strict \
-Wfloat-equal \
-Wlogical-op \
-Wno-unused-command-line-argument \
-Werror
BINARY := $(BIN_DIR)/$(NAME)
MKDIR := $(BIN_DIR) $(OBJ_DIR)
VPATH := $(SRC_DIR)
.PHONY: all clean rebuild run test
all: $(MKDIR) $(BINARY)
clean:
@rm -rf $(MKDIR)
rebuild: clean all
run: all
./$(BINARY)
$(MKDIR):
@mkdir -p $@
$(BINARY): $(C_SRC)
gcc $(C_FLAGS) $^ -o $@
+26
View File
@@ -0,0 +1,26 @@
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#define STRING_LEN ((size_t) 16)
int main(void)
{
char string[STRING_LEN] = {'\0'};
int n;
for (n = 0; n < (int)STRING_LEN; n++)
{
printf("%2d: [0x%02X]\n", n, string[n]);
}
(void) strcpy(&string[0], "hello there");
printf("\n");
for (n = 0; n < (int)STRING_LEN; n++)
{
printf("%02d: [0x%02X]\n", n, string[n]);
}
}
+1380
View File
File diff suppressed because it is too large Load Diff
+4
View File
@@ -0,0 +1,4 @@
target
Cargo.lock
test*
log.db*
+18
View File
@@ -0,0 +1,18 @@
[package]
name = "rust"
version = "0.1.0"
edition = "2021"
[dependencies]
anyhow = "1.0"
axum = "0.8.4"
chrono = { version = "0.4.41", features = ["serde"] }
ciborium = "0.2.2"
clap = { version = "4.5.0", features = ["derive"] }
cobs = { version = "0.4.0" }
dirs = "5.0.1"
serde = { version = "1.0.219", features = ["derive"] }
serde_json = "1.0.141"
thiserror = "2.0.12"
tokio = { version = "1.46.1", features = ["full"] }
+1
View File
@@ -0,0 +1 @@
target/debug/rust
+1
View File
@@ -0,0 +1 @@
stable
+115
View File
@@ -0,0 +1,115 @@
#![allow(dead_code, unused)]
use serde::{Deserialize, Serialize};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
for n in 0..16 {
let measurement: u16 = 65_535 / 16 * n;
let millikelvin = (((measurement as u32) * 21_875u32) >> 13) + 228_150u32;
let temperature = Temperature::from_millikelvin(millikelvin);
println!("raw = {measurement}, converted = {millikelvin}, temperature = {temperature}");
}
let measurement: u16 = 65_535;
let millikelvin = (((measurement as u32) * 21_875u32) >> 13) + 228_150u32;
let temperature = Temperature::from_millikelvin(millikelvin);
println!("raw = {measurement}, converted = {millikelvin}, temperature = {temperature}");
Ok(())
}
#[derive(Clone, Debug, thiserror::Error)]
pub enum TemperatureError {
#[error("provided input is invalid: {0}")]
InvalidInput(f32),
#[error("conversion between units changed the value noticeably")]
ConversionError,
}
/// type for temperature
/// represents the temperature in Millikelvin
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
pub struct Temperature{
value: u32,
}
impl Temperature {
#[allow(non_upper_case_globals)]
const CELSIUS_OFFSET_C: f32 = 273.15f32;
/// create a new instance of `Temperature` from a value in Millikelvin
/// this function is an alias for `from_millikelvin()`
pub fn new(millikelvin: u32) -> Self {
Self::from_millikelvin(millikelvin)
}
/// create a new instance of `Temperature` from a value in Millikelvin
pub fn from_millikelvin(millikelvin: u32) -> Self {
Self { value: millikelvin }
}
/// create a new instance of `Temperature` from a value in degrees Celsius
pub fn from_celsius(celsius: f32) -> Result<Self, TemperatureError> {
if celsius < -Self::CELSIUS_OFFSET_C { return Err(TemperatureError::InvalidInput(celsius)) }
Ok(Self { value: Self::celsius_to_millikelvin(celsius)? })
}
/// returns the temperature value in Millikelvin
pub fn get_millikelvin(&self) -> u32 {
self.value
}
/// returns the temperature value in degrees celsius
pub fn get_celsius(&self) -> Result<f32, TemperatureError> {
Self::millikelvin_to_celsius(self.value)
}
fn celsius_to_millikelvin(celsius: f32) -> Result<u32, TemperatureError> {
const ACCEPTABLE_INACCURACY: f32 = 1.0 / 16.0;
let millikelvin: u32 = Self::celsius_to_millikelvin_unchecked(celsius);
let celsius_converted: f32 = Self::millikelvin_to_celsius_unchecked(millikelvin);
if f32::abs(celsius - celsius_converted) > ACCEPTABLE_INACCURACY {
return Err(TemperatureError::ConversionError);
}
Ok(millikelvin)
}
fn millikelvin_to_celsius(millikelvin: u32) -> Result<f32, TemperatureError> {
const ACCEPTABLE_INACCURACY: u32 = 80;
let celsius: f32 = Self::millikelvin_to_celsius_unchecked(millikelvin);
let millikelvin_converted: u32 = Self::celsius_to_millikelvin_unchecked(celsius);
if millikelvin.wrapping_sub(millikelvin_converted) > ACCEPTABLE_INACCURACY {
return Err(TemperatureError::ConversionError);
}
Ok(celsius)
}
fn celsius_to_millikelvin_unchecked(celsius: f32) -> u32 {
((celsius + Self::CELSIUS_OFFSET_C) * 1000.0) as u32
}
fn millikelvin_to_celsius_unchecked(millikelvin: u32) -> f32 {
let millicelsius: f32 = (millikelvin as f32) / 1000.0;
millicelsius - Self::CELSIUS_OFFSET_C
}
}
impl std::fmt::Display for Temperature {
// display `Temperatures` in degrees Celsius
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if let Ok(value) = Self::millikelvin_to_celsius(self.value) {
write!(f, "{:.2?}°C", value)?;
} else {
return Err(std::fmt::Error::default());
}
Ok(())
}
}
+16
View File
@@ -0,0 +1,16 @@
# Lorem Ipsum
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Sed ut elementum leo, in iaculis lectus.
Aliquam facilisis finibus ex ac tincidunt.
Phasellus porta ornare lorem varius blandit.
Phasellus lacinia quam porttitor massa mollis, accumsan mattis ligula iaculis.
Maecenas nisl nisl, viverra sed gravida facilisis, varius at lorem.
Integer eros nisl, mattis ac dapibus id, cursus eu tellus.
Cras at odio ex.
Mauris in lacus neque.
Donec eleifend rutrum dolor quis aliquet.
Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
Proin malesuada posuere purus.
Morbi id consectetur magna.
Integer nec turpis dapibus, tincidunt felis sodales, mattis augue.
+10
View File
@@ -0,0 +1,10 @@
digraph {
node [shape = "rect", style = "rounded", fontname = "JetBrainsMono"];
entry [label = "", shape = "circle", style = "filled", color = "black"];
adc_init [label = "initialise ADC"];
loop [label = "", shape = "circle", style = "filled", color = "gray"];
entry -> adc_init
adc_init -> loop
loop -> entry
}
+2
View File
@@ -0,0 +1,2 @@
zig-out
.zig-cache
Symlink
+1
View File
@@ -0,0 +1 @@
zig-out/bin/zig
+116
View File
@@ -0,0 +1,116 @@
const std = @import("std");
// Although this function looks imperative, note that its job is to
// declaratively construct a build graph that will be executed by an external
// runner.
pub fn build(b: *std.Build) void {
// Standard target options allows the person running `zig build` to choose
// what target to build for. Here we do not override the defaults, which
// means any target is allowed, and the default is native. Other options
// for restricting supported target set are available.
const target = b.standardTargetOptions(.{});
// Standard optimization options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
// set a preferred release mode, allowing the user to decide how to optimize.
const optimize = b.standardOptimizeOption(.{});
// This creates a "module", which represents a collection of source files alongside
// some compilation options, such as optimization mode and linked system libraries.
// Every executable or library we compile will be based on one or more modules.
const lib_mod = b.createModule(.{
// `root_source_file` is the Zig "entry point" of the module. If a module
// only contains e.g. external object files, you can make this `null`.
// In this case the main source file is merely a path, however, in more
// complicated build scripts, this could be a generated file.
.root_source_file = b.path("src/root.zig"),
.target = target,
.optimize = optimize,
});
// We will also create a module for our other entry point, 'main.zig'.
const exe_mod = b.createModule(.{
// `root_source_file` is the Zig "entry point" of the module. If a module
// only contains e.g. external object files, you can make this `null`.
// In this case the main source file is merely a path, however, in more
// complicated build scripts, this could be a generated file.
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
// Modules can depend on one another using the `std.Build.Module.addImport` function.
// This is what allows Zig source code to use `@import("foo")` where 'foo' is not a
// file path. In this case, we set up `exe_mod` to import `lib_mod`.
exe_mod.addImport("zig_lib", lib_mod);
// Now, we will create a static library based on the module we created above.
// This creates a `std.Build.Step.Compile`, which is the build step responsible
// for actually invoking the compiler.
const lib = b.addLibrary(.{
.linkage = .static,
.name = "zig",
.root_module = lib_mod,
});
// This declares intent for the library to be installed into the standard
// location when the user invokes the "install" step (the default step when
// running `zig build`).
b.installArtifact(lib);
// This creates another `std.Build.Step.Compile`, but this one builds an executable
// rather than a static library.
const exe = b.addExecutable(.{
.name = "zig",
.root_module = exe_mod,
});
// This declares intent for the executable to be installed into the
// standard location when the user invokes the "install" step (the default
// step when running `zig build`).
b.installArtifact(exe);
// This *creates* a Run step in the build graph, to be executed when another
// step is evaluated that depends on it. The next line below will establish
// such a dependency.
const run_cmd = b.addRunArtifact(exe);
// By making the run step depend on the install step, it will be run from the
// installation directory rather than directly from within the cache directory.
// This is not necessary, however, if the application depends on other installed
// files, this ensures they will be present and in the expected location.
run_cmd.step.dependOn(b.getInstallStep());
// This allows the user to pass arguments to the application in the build
// command itself, like this: `zig build run -- arg1 arg2 etc`
if (b.args) |args| {
run_cmd.addArgs(args);
}
// This creates a build step. It will be visible in the `zig build --help` menu,
// and can be selected like this: `zig build run`
// This will evaluate the `run` step rather than the default, which is "install".
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
// Creates a step for unit testing. This only builds the test executable
// but does not run it.
const lib_unit_tests = b.addTest(.{
.root_module = lib_mod,
});
const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
const exe_unit_tests = b.addTest(.{
.root_module = exe_mod,
});
const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);
// Similar to creating the run step earlier, this exposes a `test` step to
// the `zig build --help` menu, providing a way for the user to request
// running the unit tests.
const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&run_lib_unit_tests.step);
test_step.dependOn(&run_exe_unit_tests.step);
}
+86
View File
@@ -0,0 +1,86 @@
.{
// This is the default name used by packages depending on this one. For
// example, when a user runs `zig fetch --save <url>`, this field is used
// as the key in the `dependencies` table. Although the user can choose a
// different name, most users will stick with this provided value.
//
// It is redundant to include "zig" in this name because it is already
// within the Zig package namespace.
.name = .zig,
// This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication.
.version = "0.0.0",
// Together with name, this represents a globally unique package
// identifier. This field is generated by the Zig toolchain when the
// package is first created, and then *never changes*. This allows
// unambiguous detection of one package being an updated version of
// another.
//
// When forking a Zig project, this id should be regenerated (delete the
// field and run `zig build`) if the upstream project is still maintained.
// Otherwise, the fork is *hostile*, attempting to take control over the
// original project's identity. Thus it is recommended to leave the comment
// on the following line intact, so that it shows up in code reviews that
// modify the field.
.fingerprint = 0xc1ce10817981a2b1, // Changing this has security and trust implications.
// Tracks the earliest Zig version that the package considers to be a
// supported use case.
.minimum_zig_version = "0.14.1",
// This field is optional.
// Each dependency must either provide a `url` and `hash`, or a `path`.
// `zig build --fetch` can be used to fetch all dependencies of a package, recursively.
// Once all dependencies are fetched, `zig build` no longer requires
// internet connectivity.
.dependencies = .{
// See `zig fetch --save <url>` for a command-line interface for adding dependencies.
//.example = .{
// // When updating this field to a new URL, be sure to delete the corresponding
// // `hash`, otherwise you are communicating that you expect to find the old hash at
// // the new URL. If the contents of a URL change this will result in a hash mismatch
// // which will prevent zig from using it.
// .url = "https://example.com/foo.tar.gz",
//
// // This is computed from the file contents of the directory of files that is
// // obtained after fetching `url` and applying the inclusion rules given by
// // `paths`.
// //
// // This field is the source of truth; packages do not come from a `url`; they
// // come from a `hash`. `url` is just one of many possible mirrors for how to
// // obtain a package matching this `hash`.
// //
// // Uses the [multihash](https://multiformats.io/multihash/) format.
// .hash = "...",
//
// // When this is provided, the package is found in a directory relative to the
// // build root. In this case the package's hash is irrelevant and therefore not
// // computed. This field and `url` are mutually exclusive.
// .path = "foo",
//
// // When this is set to `true`, a package is declared to be lazily
// // fetched. This makes the dependency only get fetched if it is
// // actually used.
// .lazy = false,
//},
},
// Specifies the set of files and directories that are included in this package.
// Only files and directories listed here are included in the `hash` that
// is computed for this package. Only files listed here will remain on disk
// when using the zig package manager. As a rule of thumb, one should list
// files required for compilation plus any license(s).
// Paths are relative to the build root. Use the empty string (`""`) to refer to
// the build root itself.
// A directory listed here means that all files within, recursively, are included.
.paths = .{
"build.zig",
"build.zig.zon",
"src",
// For example...
//"LICENSE",
//"README.md",
},
}
+24
View File
@@ -0,0 +1,24 @@
//! zig test project
//! this project serves to learn zig and test the behaviour of specific features
const std = @import("std");
const fs = std.fs;
const vec = @import("vector.zig");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
const allocator = gpa.allocator();
var test_vector = try vec.vector(u8).new(allocator);
for (0..12) |n|
{
try test_vector.push(@truncate(n));
}
std.debug.print("{X}\n", .{test_vector.array[0..test_vector.length]});
const blargh: []u8 = try test_vector.drain(.{3, 6});
defer allocator.free(blargh);
std.debug.print("drained slice: {X}\n", .{blargh});
std.debug.print("vector after drain: {X}\n", .{test_vector.array[0..test_vector.length]});
}
+13
View File
@@ -0,0 +1,13 @@
//! By convention, root.zig is the root source file when making a library. If
//! you are making an executable, the convention is to delete this file and
//! start with main.zig instead.
const std = @import("std");
const testing = std.testing;
pub export fn add(a: i32, b: i32) i32 {
return a + b;
}
test "basic add functionality" {
try testing.expect(add(3, 7) == 10);
}
+150
View File
@@ -0,0 +1,150 @@
const std = @import("std");
/// return empty instance of `Vector`
/// use `new()` or `new_with_capacity()` to
/// get an initialised instance of `Vector`
pub fn vector(comptime T: type) type
{
return struct
{
const Vector: type = @This();
const VectorType: type = T;
const DEFAULT_SIZE: usize = 16;
const VectorError: type = error {
OutOfBounds,
FailedToAllocateMemory,
};
allocator: std.mem.Allocator,
array: []VectorType,
length: usize,
/// create new vector with the default capacity
///
/// returns initialised instance of `Vector`
pub fn new(allocator: std.mem.Allocator) !Vector
{
return Vector
{
.allocator = allocator,
.array = allocator.alloc(VectorType, DEFAULT_SIZE) catch return VectorError.FailedToAllocateMemory,
.length = 0,
};
}
/// create new vector with the given capacity
///
/// returns initialised instance of `Vector`
pub fn new_with_capacity(allocator: std.mem.Allocator, size: usize) VectorError!Vector
{
return Vector
{
.allocator = allocator,
.array = allocator.alloc(VectorType, size) catch return VectorError.FailedToAllocateMemory,
.length = 0,
};
}
/// get the vectors length
///
/// **note:** length != capacity
/// length = number of items in the vector
/// capacity = maximum number of items the vector can hold
pub fn len(self: *Vector) usize
{
return self.length;
}
/// get the vectors capacity
///
/// **note:** length != capacity
/// length = number of items in the vector
/// capacity = maximum number of items the vector can hold
pub fn capacity(self: *Vector) usize
{
return self.array.len;
}
/// add one item at the end of the vector
pub fn push(self: *Vector, item: VectorType) VectorError!void
{
if (self.length >= self.array.len) try self.double_capacity();
self.array[self.length] = item;
self.length += 1;
}
/// remove and return last item of the vector
pub fn pop(self: *Vector) VectorType
{
self.length -= 1;
return self.array[self.length];
}
/// remove and return a range of elements
///
/// range[0] has to be less than range[1]
/// the range bounds are **both** included
pub fn drain(self: *Vector, range: [2]usize) VectorError![]VectorType
{
if (2 != range.len
or range[1] <= range[0]
or range[0] > self.array.len
or range[1] > self.array.len)
{
return VectorError.OutOfBounds;
}
const slice_length: usize = range[1] - range[0] + 1;
const slice: []VectorType = self.allocator.alloc(VectorType, slice_length)
catch
{
return VectorError.FailedToAllocateMemory;
};
// TODO: return array instead of pointer
@memcpy(slice.ptr, self.array[range[0]..range[1] + 1]);
@memmove(self.array.ptr + range[0], self.array[range[1] + 1..self.length]);
self.length -= slice_length;
return slice;
}
/// add slice of `VectorType` to the end of the vector
pub fn extend(self: *Vector, slice: []VectorType) VectorError!void
{
if (slice.len == 0) return;
if (slice.len > self.capacity()) {
try self.increase_capacity(slice.len + self.capacity());
}
else if (slice.len > self.capacity() - self.length)
{
try self.double_capacity();
}
@memcpy(self.array.ptr + self.length, slice);
}
/// double the vectors capacity
fn double_capacity(self: *Vector) VectorError!void
{
try self.increase_capacity(2 * self.capacity());
}
/// increase the vectors capacity to given size
fn increase_capacity(self: *Vector, size: usize) VectorError!void
{
const new_buffer: []VectorType = self.allocator.alloc(VectorType, size)
catch
{
return VectorError.FailedToAllocateMemory;
};
@memcpy(new_buffer, self.array);
self.allocator.free(self.array);
self.array = new_buffer;
}
};
}