Browse Source

Previous experiments

master
Julio Biason 2 years ago
parent
commit
0c72993467
  1. 11
      bitcount.rs
  2. 9
      defaultoption.rs
  3. 1
      dieseltest/.env
  4. 102
      dieseltest/Cargo.lock
  5. 10
      dieseltest/Cargo.toml
  6. 3
      dieseltest/README.md
  7. 5
      dieseltest/diesel.toml
  8. 0
      dieseltest/migrations/.gitkeep
  9. 6
      dieseltest/migrations/00000000000000_diesel_initial_setup/down.sql
  10. 36
      dieseltest/migrations/00000000000000_diesel_initial_setup/up.sql
  11. 2
      dieseltest/migrations/2021-11-24-125522_assets/down.sql
  12. 9
      dieseltest/migrations/2021-11-24-125522_assets/up.sql
  13. 8
      dieseltest/src/main.rs
  14. 7
      dieseltest/src/models.rs
  15. 7
      dieseltest/src/schema.rs
  16. 13
      exename.rs
  17. 69
      nng/Cargo.lock
  18. 5
      nng/Cargo.toml
  19. 8
      nng/client/Cargo.toml
  20. 3
      nng/client/src/main.rs
  21. 9
      nng/server/Cargo.toml
  22. 8
      nng/server/src/main.rs
  23. 10
      specgen.rs
  24. 10
      spongebob.rs
  25. 9
      while.rs

11
bitcount.rs

@ -0,0 +1,11 @@
fn count(bits: usize) -> u32 {
let num_bits = usize::BITS;
num_bits as u32 - bits.leading_zeros() + 1
}
fn main() {
println!("{}", count(0b111));
println!("{}", count(0b1111_1111));
println!("{}", count(64)); // 1000000
println!("{}", 1 >> 1);
}

9
defaultoption.rs

@ -0,0 +1,9 @@
#[derive(Debug, Default)]
struct Example {
exists: Option<u8>,
}
fn main() {
let e = Example::default();
println!("Herro: {:?}", e);
}

1
dieseltest/.env

@ -0,0 +1 @@
DATABASE_URL=postgres://consig:config@localhost/candles

102
dieseltest/Cargo.lock generated

@ -0,0 +1,102 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "byteorder"
version = "1.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
[[package]]
name = "diesel"
version = "1.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b28135ecf6b7d446b43e27e225622a038cc4e2930a1022f51cdb97ada19b8e4d"
dependencies = [
"bitflags",
"byteorder",
"diesel_derives",
"pq-sys",
]
[[package]]
name = "diesel_derives"
version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "45f5098f628d02a7a0f68ddba586fb61e80edec3bdc1be3b921f4ceec60858d3"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "dieseltest"
version = "0.1.0"
dependencies = [
"diesel",
"dotenv",
]
[[package]]
name = "dotenv"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f"
[[package]]
name = "pq-sys"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ac25eee5a0582f45a67e837e350d784e7003bd29a5f460796772061ca49ffda"
dependencies = [
"vcpkg",
]
[[package]]
name = "proc-macro2"
version = "1.0.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba508cc11742c0dc5c1659771673afbab7a0efab23aa17e854cbab0837ed0b43"
dependencies = [
"unicode-xid",
]
[[package]]
name = "quote"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05"
dependencies = [
"proc-macro2",
]
[[package]]
name = "syn"
version = "1.0.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2afee18b8beb5a596ecb4a2dce128c719b4ba399d34126b9e4396e3f9860966"
dependencies = [
"proc-macro2",
"quote",
"unicode-xid",
]
[[package]]
name = "unicode-xid"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
[[package]]
name = "vcpkg"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"

10
dieseltest/Cargo.toml

@ -0,0 +1,10 @@
[package]
name = "dieseltest"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
diesel = { version = "1.4.8", features = ["postgres"] }
dotenv = "0.15.0"

3
dieseltest/README.md

@ -0,0 +1,3 @@
# DieselTest
Testing Diesel.

5
dieseltest/diesel.toml

@ -0,0 +1,5 @@
# For documentation on how to configure this file,
# see diesel.rs/guides/configuring-diesel-cli
[print_schema]
file = "src/schema.rs"

0
dieseltest/migrations/.gitkeep

6
dieseltest/migrations/00000000000000_diesel_initial_setup/down.sql

@ -0,0 +1,6 @@
-- This file was automatically created by Diesel to setup helper functions
-- and other internal bookkeeping. This file is safe to edit, any future
-- changes will be added to existing projects as new migrations.
DROP FUNCTION IF EXISTS diesel_manage_updated_at(_tbl regclass);
DROP FUNCTION IF EXISTS diesel_set_updated_at();

36
dieseltest/migrations/00000000000000_diesel_initial_setup/up.sql

@ -0,0 +1,36 @@
-- This file was automatically created by Diesel to setup helper functions
-- and other internal bookkeeping. This file is safe to edit, any future
-- changes will be added to existing projects as new migrations.
-- Sets up a trigger for the given table to automatically set a column called
-- `updated_at` whenever the row is modified (unless `updated_at` was included
-- in the modified columns)
--
-- # Example
--
-- ```sql
-- CREATE TABLE users (id SERIAL PRIMARY KEY, updated_at TIMESTAMP NOT NULL DEFAULT NOW());
--
-- SELECT diesel_manage_updated_at('users');
-- ```
CREATE OR REPLACE FUNCTION diesel_manage_updated_at(_tbl regclass) RETURNS VOID AS $$
BEGIN
EXECUTE format('CREATE TRIGGER set_updated_at BEFORE UPDATE ON %s
FOR EACH ROW EXECUTE PROCEDURE diesel_set_updated_at()', _tbl);
END;
$$ LANGUAGE plpgsql;
CREATE OR REPLACE FUNCTION diesel_set_updated_at() RETURNS trigger AS $$
BEGIN
IF (
NEW IS DISTINCT FROM OLD AND
NEW.updated_at IS NOT DISTINCT FROM OLD.updated_at
) THEN
NEW.updated_at := current_timestamp;
END IF;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;

2
dieseltest/migrations/2021-11-24-125522_assets/down.sql

@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
DROP TABLE assets;

9
dieseltest/migrations/2021-11-24-125522_assets/up.sql

@ -0,0 +1,9 @@
CREATE TABLE assets (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL,
source TEXT NOT NULL
-- extras?
);
CREATE INDEX source_idx on assets (source);
SELECT diesel_manage_updated_at('assets');

8
dieseltest/src/main.rs

@ -0,0 +1,8 @@
use diesel::prelude::*;
mod models;
mod schema;
fn main() {
println!("Hello, world!");
}

7
dieseltest/src/models.rs

@ -0,0 +1,7 @@
use diesel::Queryable;
#[derive(Queryable)]
pub struct Asset {
pub name: String,
pub source: String,
}

7
dieseltest/src/schema.rs

@ -0,0 +1,7 @@
table! {
assets (id) {
id -> Int4,
name -> Text,
source -> Text,
}
}

13
exename.rs

@ -0,0 +1,13 @@
use std::env;
use std::path::Path;
fn main() {
let execution_name = env::args().nth(0).unwrap_or("???".to_string());
let parser = Path::new(&execution_name)
.file_name()
.map(|x| x.to_str())
.flatten()
.unwrap_or("???");
println!("I am {}", execution_name);
println!("And the name is {}", parser);
}

69
nng/Cargo.lock generated

@ -0,0 +1,69 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "cc"
version = "1.0.72"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee"
[[package]]
name = "client"
version = "0.1.0"
[[package]]
name = "cmake"
version = "0.1.48"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8ad8cef104ac57b68b89df3208164d228503abbdce70f6880ffa3d970e7443a"
dependencies = [
"cc",
]
[[package]]
name = "gcc"
version = "0.3.55"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2"
[[package]]
name = "libc"
version = "0.2.113"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eef78b64d87775463c549fbd80e19249ef436ea3bf1de2a1eb7e717ec7fab1e9"
[[package]]
name = "nanomsg"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "617e0160fba522f8667df7bc79f3b4a74a0e3968d08023ebb3ce717a5f3bd3ac"
dependencies = [
"libc",
"nanomsg-sys",
]
[[package]]
name = "nanomsg-sys"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "78aa3ccb6d007dfecb4f7070725c4b1670a87677babb6621cb0c8cce9cfdc004"
dependencies = [
"cmake",
"gcc",
"libc",
"pkg-config",
]
[[package]]
name = "pkg-config"
version = "0.3.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "58893f751c9b0412871a09abd62ecd2a00298c6c83befa223ef98c52aef40cbe"
[[package]]
name = "server"
version = "0.1.0"
dependencies = [
"nanomsg",
]

5
nng/Cargo.toml

@ -0,0 +1,5 @@
[workspace]
members = [
"server",
"client",
]

8
nng/client/Cargo.toml

@ -0,0 +1,8 @@
[package]
name = "client"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

3
nng/client/src/main.rs

@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}

9
nng/server/Cargo.toml

@ -0,0 +1,9 @@
[package]
name = "server"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
nanomsg = "0.7.2"

8
nng/server/src/main.rs

@ -0,0 +1,8 @@
use nanomsg::Protocol;
use nanomsg::Socket;
fn main() {
println!("Starting server...");
let mut socket = Socket::new(Protocol::Sub).unwrap();
}

10
specgen.rs

@ -0,0 +1,10 @@
//! Test if one can create a generic and a specific impl for the same trait.
trait SomeTrait {
fn say(&self) -> String;
}
struct SomeStruct<T> {}
impl<T> for SomeStruct<T>
where T: SomeTrait

10
spongebob.rs

@ -0,0 +1,10 @@
fn main() {
let phrase = std::env::args().skip(1).collect::<Vec<String>>().join(" ");
let mapper = [
Box::new(|x: char| x.to_uppercase()),
Box::new(|x: char| x.to_lowercase()),
]
.iter()
.cycle();
println!("{}", phrase.chars().map(mapper.next()).collect().join(""));
}

9
while.rs

@ -0,0 +1,9 @@
fn main() {
let data = [0b1000_0001u8, 0b0000_0010, 0b1000_0011];
let mut main_iter = data.iter();
let mut simple_iter = main_iter.take_while(|x| *x & 0b1000_000 != 0b1000_0000);
println!("{:?}", simple_iter);
let mut next_iter = main_iter.take_while(|x| *x & 0b1000_000 != 0b1000_0000);
println!("{:?}", next_iter);
}
Loading…
Cancel
Save