Skip to content

Instantly share code, notes, and snippets.

View jmsdnns's full-sized avatar

Jms Dnns jmsdnns

View GitHub Profile
@jmsdnns
jmsdnns / mac_gpu.rs
Created August 17, 2024 05:01
Simple demo of how to use Candle with Apple's GPU
use candle_core::{Device, Tensor};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let device = Device::new_metal(0)?;
let a = Tensor::randn(0f32, 1., (2, 3), &device)?;
let b = Tensor::randn(0f32, 1., (3, 4), &device)?;
let c = a.matmul(&b)?;
println!("{c}");
@jmsdnns
jmsdnns / trying_ndarrays.rs
Created August 17, 2024 04:50
Exploring Rust's ndarrays to compare with numpy arrays
use ndarray::prelude::*;
use ndarray::Array;
use ndarray::{concatenate, stack, Axis};
use std::f64::INFINITY as inf;
fn main() {
let a = array![[10.,20.,30.,40.,]];
// [[10., 20., 30., 40.]]
println!("a {:?}", &a);
// [1, 4]
@jmsdnns
jmsdnns / unique_colors.rs
Last active August 11, 2024 22:41
Loads 10000 images, converts them to tensors, and finds the total number of unique colors
use candle_core::{Device, Result, Tensor};
//use candle_nn;
use image;
use std::collections::HashSet;
const CPUNKS_PATH: &str = "../cpunks-10k/cpunks/images/training/";
const CPUNKS_TOTAL: u16 = 10000;
pub fn get_punk_tensor(p_id: u16) -> Result<(Tensor, usize, usize)> {
let path = format!("{}punk{:0>4}.png", CPUNKS_PATH, p_id);
@jmsdnns
jmsdnns / musodon_toots.rs
Last active August 11, 2024 16:46
Some simple code to fetch toots from the Mastodon API
use tokio;
use reqwest;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug)]
struct Account {
username: String
}
#[derive(Serialize, Deserialize, Debug)]
@jmsdnns
jmsdnns / image_tensor.rs
Created August 9, 2024 22:01
first attempt at loading an image as a candle tensor
use candle_core::{Device, Result, Tensor};
use image;
pub fn hongry<P: AsRef<std::path::Path>>(
p: P,
) -> Result<(Tensor, usize, usize)> {
let img = image::open(p).unwrap();
let (height, width) = (img.height() as usize, img.width() as usize);
let img = img.to_rgba8();
let data = img.into_raw();
@jmsdnns
jmsdnns / nopilot.py
Last active May 24, 2024 01:08
dont need copilot when you can use this instead
# Only two requirements
# - openai
# - python-dotenv
#
# Assumes you have $OPENAI_API_KEY in your environment or it is defined
# in a .env file
#
# Usage:
#
# $ nopilot hello world in erlang
@jmsdnns
jmsdnns / diffgit.py
Last active January 15, 2024 22:36
A tool that will compare the code in a notebook against the last code checked into the repo. Helpful for when you aren't quite sure what functionality you changed and the diff is full of noise!
#!/usr/bin/env python
# $ python ./scripts/diffgit.py nb/AddLabelsToVAE.ipynb
# 8a9
# > print('hey')
import sys
import shlex
import subprocess
import tempfile

Tips for using Python with VSCode

Open VSCode from Terminal

In VSCode, open the command palette with: Command + Shift + P

Then type: shell command and choose install 'code' command in PATH

Open VSCode in venv

@jmsdnns
jmsdnns / main.rs
Created November 8, 2023 16:47
More elaborate SSH pools
use async_ssh2_tokio::{
Error,
client::AuthMethod
};
mod pools;
#[tokio::main]
async fn main() -> Result<(), Error> {
@jmsdnns
jmsdnns / sshpools.rs
Last active November 8, 2023 14:20
Parallel SSH pools
// Here is the output for this gist
//
// Ok(Client { username: "beez", address: 192.168.122.89:22, connection_handle: "Handle<ClientHandler>" })
// Ok(Client { username: "beez", address: 192.168.122.204:22, connection_handle: "Handle<ClientHandler>" })
// killa-a2
// killa-a1
// killa-a2
// killa-a1
// killa-a1
// killa-a2