Skip to content

Instantly share code, notes, and snippets.

View hgzimmerman's full-sized avatar

Henry Zimmerman hgzimmerman

View GitHub Profile
@hgzimmerman
hgzimmerman / from_sql_function.rs
Last active February 20, 2024 18:16
Diesel 2.x implementation of from_sql_function
//! # From SQL Function
//!
//! Probably 90% ready for general use, it should generate compatible output with the `diesel::table!()`
//! macro with the exception of the code commented out on the bottom of the main section.
//!
//! I ended up going in another direction and didn't end up using this in production, but for some time,
//! it replaced an ineffecient view with a marginally more performant function, and all of our tests passed,
//! so I think its usable.
//!
//!
pub(crate) fn extract_type_from_callback(ty: &syn::Type) -> Option<&syn::Type> {
use syn::{GenericArgument, Path, PathArguments, PathSegment};
fn extract_type_path(ty: &syn::Type) -> Option<&Path> {
match *ty {
syn::Type::Path(ref typepath) if typepath.qself.is_none() => Some(&typepath.path),
_ => None,
}
}
@hgzimmerman
hgzimmerman / debug_dbg.rs
Created January 18, 2019 00:20
debug debug
macro_rules! debug_dbg {
($($x: tt)*) => {{
if cfg!(debug_assertions) {
dbg!($($x)*)
} else {
$($x)*
}
}}
}
@hgzimmerman
hgzimmerman / playground.rs
Created November 10, 2018 23:16 — forked from rust-play/playground.rs
Code shared from the Rust Playground
use std::sync::Arc;
use std::sync::RwLock;
use std::hash::Hash;
use std::collections::HashMap;
fn main () {
let m: Memoizer<i64,i64> = Memoizer::default();
let yeet = m.memoize(5, simple_fn);
assert_eq!(*yeet, 100);
let yeet = m.memoize(5, simple_fn);
@hgzimmerman
hgzimmerman / default.nix
Created November 1, 2018 22:17
Run `nix-shell default.nix` to enable compilation to wasm.
# This works for me with cargo-web (Yew)
with import <nixpkgs> {
overlays = map (uri: import (fetchTarball uri)) [
https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz
];
};
stdenv.mkDerivation {
name = "rust-wasm";
buildInputs = [

Keybase proof

I hereby claim:

  • I am hgzimmerman on github.
  • I am hzimmerman (https://keybase.io/hzimmerman) on keybase.
  • I have a public key ASDOpYR6KUSgZSceq1Ui81OSaxn34pu7r_w_s8k7cslXBwo

To claim this, I am signing this object: