This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func populate(v reflect.Value, value string) error { | |
switch v.Kind() { | |
case reflect.String: | |
v.SetString(value) | |
case reflect.Int: | |
i, err := strconv.ParseInt(value, 10, 64) | |
if err != nil { | |
return err | |
} | |
v.SetInt(i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ( | |
"errors" | |
"io" | |
) | |
type FileSizeReader struct { | |
reader io.Reader | |
currentSize int64 | |
limit int64 | |
exceededErr bool |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef _DEFER_FN | |
#define _DEFER_FN | |
#include <functional> | |
#include <utility> | |
#define CONCAT_(a, b) a##b | |
#define CONCAT(a, b) CONCAT_(a, b) | |
#define DEFER(fn) ScopeGuard CONCAT(__defer__, __LINE__) = [&] ( ) { fn ; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <unordered_map> | |
#include <limits> | |
void counting_sort(vector<int> &v) | |
{ | |
int n = v.size(); | |
unordered_map<int, int> map; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from random import randint | |
def counting_sort(nums): | |
pair = {} | |
# set the min num | |
min_num = sys.maxsize | |
# set the max number | |
max_num = -sys.maxsize - 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mat = [ | |
[1, 0, 0, 1], | |
[0, 1, 0, 0], | |
[1, 0, 1, 0], | |
[0, 1, 0, 1], | |
] | |
def dfs(mat, x: int, y: int) -> int: | |
if ((x < 0) or |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func BulkInsert(unsavedRows []*ExampleRowStruct) error { | |
valueStrings := make([]string, 0, len(unsavedRows)) | |
valueArgs := make([]interface{}, 0, len(unsavedRows) * 3) | |
i := 0 | |
for _, post := range unsavedRows { | |
valueStrings = append(valueStrings, fmt.Sprintf("($%d, $%d, $%d)", i*3+1, i*3+2, i*3+3)) | |
valueArgs = append(valueArgs, post.Column1) | |
valueArgs = append(valueArgs, post.Column2) | |
valueArgs = append(valueArgs, post.Column3) | |
i++ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const merge = (...streams) => { | |
let pass = new PassThrough(); | |
let waiting = streams.length; | |
for (let stream of streams) { | |
pass = stream.pipe(pass, {end: false}) | |
stream.once("end", () => --waiting === 0 && pass.emit("end")); | |
} | |
return pass | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func concat(s ...string) string { | |
var sum int | |
for _, i := range s { | |
sum += len(i) | |
} | |
res := make([]byte, sum) | |
var counter int | |
for _, y := range s { | |
for i := 0; i < len(y); i++ { | |
res[counter] = y[i] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"crypto/cipher" | |
"crypto/rand" | |
"encoding/binary" | |
"io" | |
"io/ioutil" | |
"net/http" | |
"os" |
NewerOlder