Skip to content

Instantly share code, notes, and snippets.

@vardius
vardius / main.go
Created June 19, 2020 07:59
How to rate limit HTTP requests
package main
import (
"expvar"
"fmt"
"net"
"net/http"
"net/http/httptest"
"sync"
"testing"
@vardius
vardius / main.go
Last active June 12, 2020 23:18
Profiling Go HTTP service with pprof and expvar
package main
import (
"context"
"expvar" // Register the expvar handlers
"fmt"
"log"
"net/http"
_ "net/http/pprof" // Register the pprof handlers
"os"
@vardius
vardius / main.go
Last active June 11, 2020 05:12
Basic HTTP authentication with Go
package main
import (
"crypto/subtle"
"fmt"
"log"
"net/http"
)
var (
@vardius
vardius / main.go
Last active May 2, 2022 23:03
Go errors with stack trace
package main
import (
"bytes"
"errors"
"fmt"
"runtime"
)
type AppError struct {
@vardius
vardius / main.go
Created May 27, 2020 07:21
Go download stream response
// https://rafallorenz.com/go/go-http-stream-download/
package main
import (
"errors"
"io"
"io/ioutil"
"net/http"
"time"
)
@vardius
vardius / array_map_keys.php
Created June 28, 2019 02:54
Applies the callback to the keys of the given array
<?php
function array_map_keys(callable $callback, array $array) {
return array_merge([], ...array_map(
function ($key, $value) use ($callback) { return [$callback($key) => $value]; },
array_keys($array),
$array
));
}
@vardius
vardius / displayNullColumns.sql
Last active January 31, 2018 00:47
Display all table/column names where value is a specific string
DELIMITER $$
DROP PROCEDURE IF EXISTS `displayNullColumns`$$
CREATE PROCEDURE `displayNullColumns`()
BEGIN
SET @expression = (
SELECT GROUP_CONCAT(CONCAT('SELECT ', s._column, ' AS _value, \'', s._column, '\' AS _column, \'', s._table, '\' AS _table FROM ', s._table, ' WHERE ', s._column, ' = \'null\'')
SEPARATOR ' UNION ')
FROM (
SELECT DISTINCT
COLUMN_NAME AS `_column`,
@vardius
vardius / checkmark.js
Last active February 19, 2016 14:29
ES6 Angular OO Aproach
/**
* (c) Rafał Lorenz <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
'use strict';
//Location in the `filters` directory
//This way `Loader class will find it.