Skip to content

Instantly share code, notes, and snippets.

View phongphan's full-sized avatar

Phongphan Phuttha phongphan

View GitHub Profile
@phongphan
phongphan / main.rs
Last active April 9, 2023 14:47
axum mTLS using openssl
use axum::{extract::ConnectInfo, response::Html, routing::get, Router};
use axum_server::tls_openssl::OpenSSLConfig;
use openssl::ssl::{SslAcceptor, SslFiletype, SslMethod, SslVerifyMode};
use openssl::x509::{
store::{X509Store, X509StoreBuilder},
X509,
};
use std::{net::SocketAddr, path::PathBuf};
#[tokio::main]
After setting up the project.
Adding:
{
"javascript.validate.enable": false,
"flow.useNPMPackagedFlow": true
}
to the .vscode/settings.json
@phongphan
phongphan / rangemerge.rkt
Last active August 15, 2017 10:10
Racket version
#lang typed/racket
;; (normalize-range (list (range 1 2) (range 3 4) (range 4 83) (range 0 0) (range 1 6)))
(struct range ([from : Integer] [to : Integer]) #:transparent)
(: to-integer (-> String Integer))
(define (to-integer str)
(assert (string->number str) exact-integer?))
@phongphan
phongphan / rangemerge.ml
Created August 11, 2017 06:41
OCaml version
(*
* ocamlfind ocamlc -package containers -linkpkg rangemerge.ml
*)
open Containers
open Printf
let normalize_range ranges =
List.sort (fun x y -> compare (fst x) (fst y)) ranges
|> List.fold_left (fun acc x ->
let src = List.hd acc in
@phongphan
phongphan / RangeMerge.cs
Last active August 15, 2017 09:55
An inefficient version of range-merge exam
/*
* Input example: 1,2,8-20,15-200
* Output: 1,2,8-200
*/
using System;
using System.Collections.Generic;
using System.Linq;
namespace Fold
@phongphan
phongphan / proxy.cpp
Created August 5, 2016 09:57
Windows automatic proxy settings resolver
/* Windows automatic proxy settings resolver
* Jiri Hruska <jirka@fud.cz>, 2012-2013
* Released under the WTFPL license. */
#define UNICODE
#define _UNICODE
#include <string>
#include <Windows.h>
#include <winhttp.h>
#pragma comment(lib, "winhttp.lib")
@echo off
setlocal
set OPEN_DYLAN_USER_ROOT=%CD%\_build
dylan-compiler-with-tools -build %1.lid
@phongphan
phongphan / tuareg-toplevel-core
Last active August 29, 2015 14:12
Use Std.Core in merlin and tuareg's toplevel within emacs
Using Core.Std in Emacs
=======================
merlin
------
When you want to use external libraries installed with opam (findlib?).
You could do it by using `merlin-use` command, it will prompt you for a package name.
For example, we need to use Std.Core:
M-x merlin-use
location ~* ^/who/.*\.(js|jpg|jpeg|css ... others ...)$ {
root /var/www/who/public;
rewrite ^/who/?(.*)$ /$1 break;
try_files $uri =404;
expires max;
access_log off;
}
location ^~ /who {