Skip to content

Instantly share code, notes, and snippets.

@rekby
rekby / main.go
Created October 19, 2022 21:27
limit max request size example
package main
import (
"io"
"net/http"
)
const maxLen = 10
func handler(w http.ResponseWriter, r *http.Request) {
@rekby
rekby / main.go
Created September 7, 2022 22:57
Use header.Values for check header instead of header.Get
package main
import (
"fmt"
"net/http"
"net/http/httptest"
"strings"
)
const encodingHeader = "Accept-Encoding"
package ctxcancel
import "context"
// CtxCancel run f in background and return result
// onCancel called if ctx cancelled before f return result
// it called after f finish
// return f result of ctx.Err() (if ctx cancelled)
func CtxCancel(ctx context.Context, f func() error, onCancel func()) error {
fResult := make(chan error, 1)
@rekby
rekby / int_mock_test.go
Last active May 1, 2019 22:58
generated code for minimock return without expected bug https://github.com/gojuno/minimock/issues/31
package asd
// DO NOT EDIT!
// The code below was generated with http://github.com/gojuno/minimock (dev)
//go:generate minimock -i tmp.Int -o ./int_mock_test.go
import (
"sync/atomic"
"time"
@rekby
rekby / summer_mock_test.go
Last active April 27, 2019 15:39
minimock example
package main
// DO NOT EDIT!
// The code below was generated with http://github.com/gojuno/minimock (dev)
//go:generate minimock -i tmp.Summer -o ./summer_mock_test.go
import (
"sync/atomic"
"time"
@rekby
rekby / osx-openssh-portable.md
Created January 28, 2019 07:30 — forked from surjikal/macos-openssh-portable.sh
Compile OpenSSH Portable on OSX
brew install openssl

git clone git://anongit.mindrot.org/openssh.git
cd openssh

# ./configure script does not exist, so we have to build it
autoreconf

mkdir dist
#!/bin/bash
# Workaround for https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1784152
# Copy the script to /lib/systemd/system-sleep/reload-dell-touchpad.sh
SUSPEND_MODULES="i2c_hid"
case $1 in
pre)
for mod in $SUSPEND_MODULES; do
rmmod $mod
@rekby
rekby / log.php
Created January 17, 2018 19:00
php log requests
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$REKBY_DUMP_ARR = array();
$REKBY_DUMP_ARR['URI'] = $_SERVER['REQUEST_URI'];
$REKBY_DUMP_ARR['REQUEST'] = $_REQUEST;
$REKBY_DUMP_ARR['GET'] = $_GET;
$REKBY_DUMP_ARR['POST'] = $_POST;
$REKBY_DUMP_ARR['COOKIE'] = $_COOKIE;
$REKBY_DUMP_ARR['REMOTE_ADDR'] = $_SERVER['REMOTE_ADDR'];
file_put_contents("../php-log/".date('Y-m-d--H-i-s--').rand(100000,999999), print_r($REKBY_DUMP_ARR, true));
package main
import (
"crypto/x509"
"crypto/tls"
"fmt"
)
const rootCert = `-----BEGIN CERTIFICATE-----
MIIEMzCCAxugAwIBAgIBATANBgkqhkiG9w0BAQUFADA5MQswCQYDVQQGEwJSVTEM
MAoGA1UECBMDdG1wMQwwCgYDVQQKEwN0bXAxDjAMBgNVBAMTBXRtcENBMCAXDTE1
MDgwNzExMzMwMFoYDzIzODAwODA3MTEzMzAwWjA5MQswCQYDVQQGEwJSVTEMMAoG
package main
import (
"crypto/tls"
"fmt"
"time"
"crypto/x509"
)
const rootCert = `-----BEGIN CERTIFICATE-----
MIIEMzCCAxugAwIBAgIBATANBgkqhkiG9w0BAQUFADA5MQswCQYDVQQGEwJSVTEM