Skip to content

Instantly share code, notes, and snippets.

@vardius
vardius / main.go
Created Jun 19, 2020
How to rate limit HTTP requests
View main.go
package main
import (
"expvar"
"fmt"
"net"
"net/http"
"net/http/httptest"
"sync"
"testing"
@vardius
vardius / main.go
Last active Jun 12, 2020
Profiling Go HTTP service with pprof and expvar
View main.go
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 Jun 11, 2020
Basic HTTP authentication with Go
View main.go
package main
import (
"crypto/subtle"
"fmt"
"log"
"net/http"
)
var (
@vardius
vardius / main.go
Last active Jun 2, 2020
Go errors with stack trace
View main.go
package main
import (
"bytes"
"errors"
"fmt"
"runtime"
)
type AppError struct {
@vardius
vardius / main.go
Created May 27, 2020
Go download stream response
View main.go
// 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 Jun 28, 2019
Applies the callback to the keys of the given array
View array_map_keys.php
<?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 Jan 31, 2018
Display all table/column names where value is a specific string
View displayNullColumns.sql
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 Feb 19, 2016
ES6 Angular OO Aproach
View checkmark.js
/**
* (c) Rafał Lorenz <vardius@gmail.com>
*
* 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.
You can’t perform that action at this time.