Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Learning Rust

=Bill.Barnhill BillBarnhill

💭
Learning Rust
View GitHub Profile
@BillBarnhill
BillBarnhill / Returning a module name
Last active Apr 19, 2021 — forked from rust-play/playground.rs
Code shared from the Rust Playground
View Returning a module name
mod foo {
pub fn name() -> &'static str {
module_path!()
}
}
fn main() {
println!("Hello, {}", foo::name());
}
@BillBarnhill
BillBarnhill / main.rs
Last active Mar 19, 2021
Main.rs with problem with signature of on_ws_request
View main.rs
// This version compiles, and works
#[macro_use]
extern crate serde_derive;
use serde_json::{Map, Value};
use tide_websockets::{
WebSocket,
Message
};
use async_std::stream::StreamExt;
@BillBarnhill
BillBarnhill / app.js
Last active Mar 16, 2021
A main.rs for tide-websocket use.Unfortunately it closes the WebSocket immediately
View app.js
// This is at present within a script tag in html page
app = function(){
function onLoad()
{
console.log("[page] loaded");
this.websocket = new WebSocket(this.wsUri);
this.websocket.onopen = this.onWsOpen;
this.websocket.onclose = this.onWsClose;
@BillBarnhill
BillBarnhill / Cargo.toml
Created Mar 6, 2021
Cargo.toml producing mio error
View Cargo.toml
[package]
name = "xdaytime"
version = "0.1.0"
edition = "2018"
[features]
default = ["os-poll", "os-ext", "net"]
os-poll = []
os-ext = ["os-poll"]
View gist:b0b3f20e5fe4485e4e15b6dcabdec810
#nop This file is read on startup by WinTin++ by default.
#event {SESSION CONNECTED} {
#showme {CONNECTED: '%0'};
#regex {%0} {^alonzo$} {
CONNECT Alonzo password;
#format {logfile} {C:/Users/wabar/WinTin++/logs/alonzo_%t.html} {%Y-%m-%d};
#log append $logfile;
} {0};
}
View problem1
def f(sz):
assert sz, "Input cannot be empty/falsy"
assert "__getitem__" in dir(sz), "Input must be subscribtable"
result = []
current = sz[0]
count = 0;
for c in sz:
if c == current:
count += 1
@BillBarnhill
BillBarnhill / day2_tide.rs
Created Sep 12, 2020
Rust snippet showing how to use state with Tide
View day2_tide.rs
#[derive(Clone)]
pub struct AppState {
name : String
}
pub struct App {
server : tide::Server<AppState>
}
@BillBarnhill
BillBarnhill / tide_test.rs
Created Sep 10, 2020
An example Tide unit test in Rust, with a Request and checked Response
View tide_test.rs
#[cfg(test)]
mod tests {
#[async_std::test]
async fn index_page() -> tide::Result<()> {
use tide::http::{Url, Method, Request, Response};
let mut app = tide::new();
app.at("/").get(|_| async { Ok("Hello, world!") });
let url = Url::parse("https://example.com").unwrap();
@BillBarnhill
BillBarnhill / Cargo.toml
Created Jan 18, 2020 — forked from jcdyer/Cargo.toml
Updated for v 0.12.0
View Cargo.toml
[package]
name = "edge"
version = "0.1.0"
authors = ["J. Cliff Dyer <jcd@sdf.org>"]
[dependencies]
indradb = "0.12.0"
indradb-lib = "0.12.0"
serde_json = "*"
uuid = "*"
View Effective_Engineer.md

FWIW: I didn't produce the content presented here (the outline from Edmond Lau's book). I've just copy-pasted it from somewhere over the Internet, but I cannot remember what exactly the original source is. I was also not able to find the author's name, so I cannot give him/her the proper credits.


Effective Engineer - Notes

What's an Effective Engineer?