Skip to content

Instantly share code, notes, and snippets.

View kilroyjones's full-sized avatar

kilroy kilroyjones

View GitHub Profile
// Example in posts on Rust borrow system
#include <stdio.h>
typedef struct {
int age;
int is_oldest;
} Person;
int main() {
Person people[] = {
use actix_web::{App, post, get, HttpServer, HttpResponse, Error, web, Responder};
use actix_cors::Cors;
use backend::models::Albums;
use dotenv::dotenv;
use std::env;
use sqlx::sqlite::SqlitePool;
use serde_derive::Deserialize;
#[derive(Deserialize, Debug)]
add_action( 'login_head', 'wpse_121687_hide_login' );
function wpse_121687_hide_login() {
$style = '';
$style .= '<style type="text/css">';
$style .= '.login form{ display: none }';
$style .= '.login #nav a, .login #backtoblog a { display: none }';
$style .= '</style>';
echo $style;
@kilroyjones
kilroyjones / working.rs
Created September 28, 2020 12:21
Working
use crate::models::links::{Link, LinkJson, LinkNew, LinkUpdate};
use crate::Pool;
use actix_web::{web, Error, HttpResponse};
use diesel::dsl::insert_into;
use diesel::prelude::*;
use regex::Regex;
use reqwest::Url;
pub async fn add_link(
use crate::models::images::{Image, ImageJson, ImageNew, ImageUpdate};
use crate::Pool;
use actix_web::{web, Error, HttpResponse};
use diesel::dsl::insert_into;
use std::path::Path;
use anyhow::{Result};
use tokio::fs::File;
use tokio::io::{AsyncWriteExt};
use diesel::prelude::*;
@kilroyjones
kilroyjones / issue_with_errors.rs
Last active August 1, 2020 16:33
Issue with errors and async
//In using the automate library which is an async library that talks to rust I had two
//different errors I needed to deal with. One was automate::Error and the other was
//Box<dyn std::error::Error> from a call to an API in a module I'd created.
//Automate: https://crates.io/crates/automate
//mycode.rs
async fn weather(ctx: &mut Context, data: &MessageCreateDispatch) -> Result<(), Error> {
...
@kilroyjones
kilroyjones / async-openweather.rs
Created July 31, 2020 07:02
Async openweather example
async fn get_response(location: &str) -> Result<String, reqwest::Error> {
let base_http = "https://api.openweathermap.org/data/2.5/weather?q=".to_string();
let units = "metric";
let addr = base_http + &location + "&appid=" + API_KEY + "&units=" + &units;
let json = reqwest::get(&addr)
.await?
.text()
.await?;
Ok(json)
}
@kilroyjones
kilroyjones / add.rs
Last active July 30, 2020 00:15
Rust add function using any parameter type.
extern crate num;
use num::{ToPrimitive, Float};
fn add<T, R, U>(a: T, b: R) -> U
where
T: ToPrimitive,
R: ToPrimitive,
U: Float,
{