Skip to content

Instantly share code, notes, and snippets.

Avatar

Sven-Hendrik Haase svenstaro

View GitHub Profile
View nice.rs
use std::net::{SocketAddr, AddrParseError};
use anyhow::{Context, Result};
use structopt::StructOpt;
use http::uri::{PathAndQuery, InvalidUri};
use simplelog::{LevelFilter, TermLogger};
#[derive(StructOpt, Clone, Debug)]
#[structopt(
name = "site24x7_exporter",
author,
View gist:43ba3384cfd72bc266194ba5350e56ea
https://github.com/svenstaro/dotfiles
https://github.com/lurst/setup
https://github.com/cutwater/dotfiles
https://github.com/brtmr/dotfiles
https://github.com/AntoineDupre/dotfiles
@svenstaro
svenstaro / _hcloud.zsh
Last active Jun 16, 2018
hcloud changes
View _hcloud.zsh
#compdef hcloud
source <(hcloud completion zsh)
View terrible.rs
pub fn register(user: Result<UserSerializer, Vec<Value>>, db: DB) -> Result<APIResponse, APIResponse> {
if user.is_err() {
let error = user.err().unwrap();
return Ok(unprocessable_entity(error));
}
let user_data = user.unwrap();
}
View db.rs
impl<'a, 'r> FromRequest<'a, 'r> for DB {
type Error = ();
fn from_request(request: &'a Request<'r>) -> request::Outcome<DB, ()> {
let pool = match <State<r2d2::Pool> as FromRequest>::from_request(request) {
Outcome::Success(pool) => pool,
Outcome::Failure(e) => return Outcome::Failure(e),
Outcome::Forward(_) => return Outcome::Forward(()),
};
View hybrid-tests.py
import datetime
from sqlalchemy.ext.hybrid import hybrid_property
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://localhost'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
View tavianator AABB test
struct Ray {
Ray(const glm::vec3 &origin, const glm::vec3 &direction)
: m_origin(origin), m_dir(direction), m_invdir(1.f / direction) {
}
glm::vec3 m_origin;
glm::vec3 m_dir;
glm::vec3 m_invdir;
};
View intersections.hpp
inline bool intersect_ray_aabb(const glm::vec3 &origin, const glm::vec3 &dir, const AABB &aabb) {
float tmin, tmax, tymin, tymax, tzmin, tzmax;
glm::vec3 bounds[2];
bounds[0] = aabb.min();
bounds[1] = aabb.max();
glm::vec3 invdir = 1.f / dir;
glm::i8vec3 sign;
View timer.hpp
#ifndef TIMER_HPP
#define TIMER_HPP
#include <chrono>
class Timer {
public:
Timer() {
m_start = std::chrono::steady_clock::now();
}
You can’t perform that action at this time.