Skip to content

Instantly share code, notes, and snippets.

View jeremychone's full-sized avatar

Jeremy Chone jeremychone

View GitHub Profile
@jeremychone
jeremychone / rust-let-else.rs
Last active August 28, 2023 19:55
Rust 1.65 - let-else statements - new language feature!!! For youtube video: https://www.youtube.com/watch?v=U-5_bumwH9w&list=PL7r-PXl6ZPcCIOFaL7nVHXZvBmHNhrh_Q)
//! For youtube video: https://www.youtube.com/watch?v=U-5_bumwH9w&list=PL7r-PXl6ZPcCIOFaL7nVHXZvBmHNhrh_Q
/// Guard pattern with let-else
/// e.g., "my_key: 123"
pub fn key_num_guard_1(item: &str) -> Result<(&str, i32), &'static str> {
let Some((key, val)) = item.split_once(':') else {
return Err("Invalid item");
};
let Ok(val) = val.trim().parse::<i32>() else {
return Err("Invalid item");
{
"pair_lgt": {
"prefix": "<",
"body": [
"<$1>"
],
"description": "<> pair"
},
"pair_bars": {
"prefix": "|",
// Place your settings in this file to overwrite the default settings
{
"http.proxySupport": "off", // by default we use tabs
"files.associations": {
"*.pcss": "scss",
"*.tmpl": "html",
"*.hmd": "markdown",
"*.sketchscript": "javascript",
"*.hmt": "markdown"
},
{
"editor.codeActionsOnSave": {
"source.organizeImports": true
},
"workbench.activityBar.visible": false,
// "editor.glyphMargin": false,
"editor.suggest.showIcons": false,
"editor.lightbulb.enabled": false,
// "editor.hover.enabled": false,
// "typescript.suggestionActions.enabled": false,
@jeremychone
jeremychone / rust-xp-03-redis.rs
Last active September 9, 2023 06:33
Rust Redis with Async/Await (single threaded concurrency) | RustLang by example
#![allow(unused)] // silence unused warnings while exploring (to comment out)
use std::{error::Error, time::Duration};
use tokio::time::sleep;
use redis::{
from_redis_value,
streams::{StreamRangeReply, StreamReadOptions, StreamReadReply},
AsyncCommands, Client,
};
@jeremychone
jeremychone / rust-xp-02-postgresql-sqlx.rs
Created May 11, 2021 05:48
Rust to PostgreSQL with SQLX | Rust By Example
#![allow(unused)] // silence unused warnings while exploring (to comment out)
use sqlx::postgres::{PgPoolOptions, PgRow};
use sqlx::{FromRow, Row};
// Youtube episode: https://youtu.be/VuVOyUbFSI0
// region: Section
// Start postgresql server docker image:
@jeremychone
jeremychone / rust-xp-01-s3.rs
Last active April 13, 2024 16:39
Rust Quick Example to connect to S3 and Minio bucket server
#![allow(unused)] // silence unused warnings while exploring (to comment out)
use std::{error::Error, str};
use s3::bucket::Bucket;
use s3::creds::Credentials;
use s3::region::Region;
use s3::BucketConfiguration;
// Youtube Walkthrough - https://youtu.be/uQKBW8ZgYB8
// test
var math = {
base: 0,
add: add
};
function add(a, b) {
return this.base + a + b;
}
// Place your key bindings in this file to overwrite the defaults
[
// ------ Terminal --------- //
{
"key": "ctrl+alt+l",
"command": "workbench.action.terminal.focusNext"
},
{
"key": "ctrl+alt+k",
"command": "workbench.action.terminal.focusPrevious"