Skip to content

Instantly share code, notes, and snippets.

View H2NCH2COOH's full-sized avatar

H2NCH2COOH H2NCH2COOH

  • Beijing
  • 05:20 (UTC +08:00)
View GitHub Profile
@H2NCH2COOH
H2NCH2COOH / heap.lua
Created August 1, 2017 06:34
Lua min heap
---
-- Lua min heap
-- Based on http://lua-users.org/lists/lua-l/2007-07/msg00482.html
-- @author Luis Carvalho <carvalho@dam.brown.edu>
local assert, setmetatable = assert, setmetatable
local M = {}
local function push (h, k, v)
@H2NCH2COOH
H2NCH2COOH / srt_time_move.lua
Created February 20, 2018 14:53
srt Subtitle file time move
#!/usr/bin/lua
local MOVEMS = 1500
local line = io.read('*l')
while line do
--local m = {string.match(line, '^([0-9][0-9]):([0-9][0-9]):([0-9][0-9]),([0-9]+) %-%-> ([0-9][0-9]):([0-9][0-9]):([0-9][0-9]),([0-9]+)$')}
local mat = {string.match(line, "^(%d%d):(%d%d):(%d%d),(%d+) %-%-> (%d%d):(%d%d):(%d%d),(%d+)\r$")}
if mat[1] then
local d = {}
@H2NCH2COOH
H2NCH2COOH / markdown_in_nginx.md
Last active June 14, 2022 03:08
Markdown in Nginx

Markdown in Nginx

Nginx config

location ~ /.*\.md {
    root /www/;
    default_type text/html;
    charset UTF-8;
    add_before_body /strapdown/prepend;

add_after_body /strapdown/postpend;

@H2NCH2COOH
H2NCH2COOH / net_addr.c
Last active February 26, 2019 09:21
Network Address Parsing in C
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include "net_addr.h"
static int ipv4_aton(const char* str, uint8_t addr[4])
{
const char* DIGIT = "0123456789";
@H2NCH2COOH
H2NCH2COOH / cpp_ctor_example.c
Created May 16, 2019 10:48
C++ constructor example
#if 0
g++ -std=c++17 -o a.out -Wall -Wextra $@ $0 || exit
./a.out
rm -f a.out
exit
#endif
#include <stdio.h>
#include <vector>
#!/bin/sh
while [ $# -gt 0 ]; do
case $1 in
-u|--user)
SSH_USER=$2
shift
;;
-s|--ssh)
SSH_ADDR=$2