Skip to content

Instantly share code, notes, and snippets.

View MadFaill's full-sized avatar

Nikolay MadFaill

View GitHub Profile
@MadFaill
MadFaill / least_squares.go
Created April 21, 2024 06:54 — forked from sukamenev/least_squares.go
Golang least squares method: traditional and minimizing sum of squares of perpendicular lengths approach.
/*
Код взят отсюда и доработан
https://gist.github.com/ota42y/db4ff0298d9c945cd261
Код применим только для y = ax + b
Для вертикальных прямых неприменим.
Least Squares Fitting: Perpendicular Offsets
Мы используем продвинутую версию метода наименьших квадратов, где меряется расстояние перпендикуляра до прямой
https://mathworld.wolfram.com/LeastSquaresFittingPerpendicularOffsets.html
@MadFaill
MadFaill / state-example.rs
Last active February 23, 2023 21:51
An example of using state in Rust
#![allow(unused)]
use std::collections::HashMap;
struct Locked;
struct Unlocked;
// PasswordManager<Locked> != PasswordManager<Unlocked>
struct PasswordManager<State = Locked> {
@MadFaill
MadFaill / askama-rocket-template-response-responder.rs
Created January 24, 2023 22:30
Askama::Template Rocket response responder implement macro
#[macro_use]
use askama_rocket::{Template};
use rocket::futures::executor::block_on;
use rocket::http::{ContentType, Status, Header};
use rocket::local::asynchronous::Client;
use std::io::Cursor;
pub use askama::*;
pub use rocket::request::Request;
@MadFaill
MadFaill / rocket-json-response.rs
Last active January 24, 2023 13:41
Custom JSON Responder for Rocket.io
/// # Custom JSON Responder for Rocket.io
///
/// Allow to modify JSON response:
/// - Add custom headers
/// - send cookies
/// - etc...
///
/// # Examples:
///
/// ``` Cargo.toml
@MadFaill
MadFaill / index.html
Created March 11, 2021 09:27 — forked from rpaul-stripe/index.html
Stripe Checkout Go Example
<html>
<head>
<title>Checkout Example</title>
</head>
<body>
<form action="/charge" method="post" class="payment">
<article>
<label class="amount">
<span>Amount: $5.00</span>
//
// Companion code to https://medium.com/statuscode/pipeline-patterns-in-go-a37bb3a7e61d
//
// To run:
// go get github.com/pkg/errors
// go run -race pipeline_demo.go
//
package main
@MadFaill
MadFaill / bitbucket-pipelines.yml
Created August 5, 2019 07:32 — forked from pyldin601/bitbucket-pipelines.yml
Bitbucket pipelines for docker swarm service with deploy via SSH.
image: node
pipelines:
branches:
staging:
- step:
script:
- docker login -u $DOCKER_LOGIN -p $DOCKER_PASSWORD
- make TAG=staging docker-build docker-push
- step:
@MadFaill
MadFaill / ttfb.sh
Created January 28, 2019 13:00 — forked from sandeepraju/ttfb.sh
curl command to check the time to first byte
#!/bin/bash
# file: ttfb.sh
# curl command to check the time to first byte
# ** usage **
# 1. ./ttfb.sh "https://google.com"
# 2. seq 10 | xargs -Iz ./ttfb.sh "https://google.com"
curl -o /dev/null \
-H 'Cache-Control: no-cache' \
-s \
@MadFaill
MadFaill / Explanation.txt
Created January 25, 2019 14:53 — forked from melo/Explanation.txt
strange nginx behaviour with error_page + proxy_pass
I expected the first configuration below, simple.conf, to work just fine.
But it doesn't. My app server receives the second hit with the same URI as the first hit.
On the second config, wtf.conf, I keep the original URL on a variable to use in the error redirect.
My question is this: why doesn't the first simple.conf configuration works?