Skip to content

Instantly share code, notes, and snippets.

View lzakharov's full-sized avatar
🦁

Lev Zakharov lzakharov

🦁
View GitHub Profile
@lzakharov
lzakharov / GOLAND_TEST_LIVE_TEMPLATE.go
Created March 31, 2021 08:58
GoLand live template for the test functions.
func Test$NAME$(t *testing.T) {
type args struct {
$ARGS$
}
type want struct {
$WANT$
}
test := func(args args, want want) func(t *testing.T) {
return func(t *testing.T) {
@lzakharov
lzakharov / quicksort.go
Last active January 6, 2020 06:17
Quicksort in Go
package quicksort
import (
"math/rand"
"sync"
)
func Sort(xs []int) []int {
if len(xs) < 2 {
return xs
@lzakharov
lzakharov / wordNumber.hs
Created November 10, 2019 23:49
wordNumber returns the English word version of the Int value
module Main where
import Data.List (intercalate)
digitToWord :: Int -> String
digitToWord 0 = "zero"
digitToWord 1 = "one"
digitToWord 2 = "two"
digitToWord 3 = "three"
digitToWord 4 = "four"
@lzakharov
lzakharov / wait_for_http_success.sh
Created March 14, 2019 11:32
Wait for an HTTP endpoint to return 2xx Success with Bash and curl.
echo 'Waiting for an HTTP endpoint to return 2xx'
until $(curl --output /dev/null --silent --fail $1); do
printf '.'
sleep 5
done
echo 'Success!'
import numpy as np
import cv2
args = {
'prototxt': 'deploy.prototxt.txt',
'model': 'res10_300x300_ssd_iter_140000.caffemodel',
'confidence': 0.5
}
net = cv2.dnn.readNetFromCaffe(args["prototxt"], args["model"])
@lzakharov
lzakharov / linkedlist.c
Created May 28, 2018 22:39
Linked list implementation in pure C.
#include <stdio.h>
#include <stdlib.h>
#include "linkedlist.h"
void display(node *head) {
node *it;
for (it = head; it != NULL; it = it->next)
printf(it->next != NULL ? "%d " : "%d\n", it->data);
}
@lzakharov
lzakharov / jwttokenauth.py
Created April 18, 2018 12:42
JWT token authorization middleware for Django Channels 2.
from rest_framework_jwt.serializers import VerifyJSONWebTokenSerializer
class JwtTokenAuthMiddleware:
"""
JWT token authorization middleware for Django Channels 2
"""
def __init__(self, inner):
self.inner = inner
@lzakharov
lzakharov / arithmetic_coding.py
Last active December 6, 2017 21:11
Алгоритм арифметического кодирования.
def float2bin(x, eps=1e-9):
res = ''
while x > eps:
x *= 2
res += str(int(x))
x -= int(x)
return res