Skip to content

Instantly share code, notes, and snippets.

😴
AlwayZzz...

Denis Lavrov diolavr

😴
AlwayZzz...
Block or report user

Report or block diolavr

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@diolavr
diolavr / install_golang_man.md
Last active Jun 4, 2019
Install the Golang without package manager on Linux
View install_golang_man.md

Установка Golang на Linux без использования пакетного менеджера

  1. Создать каталоги где будет размещаться golang. В примере, golang размещается в домашнем каталоге пользователя. Для создания сразу нескольких каталогов можно использовать команду mkdir. Ключ -p автоматически создаст недостающие директории.
$ mkdir -p $HOME/golang/libs
  1. Скачать последнюю версию golang с сайта https://golang.org/dl/ и распакуйте его в ранее созданную папку. Также можно воспользоваться командами ниже
$ wget https://dl.google.com/go/go1.12.1.linux-amd64.tar.gz
$ tar -C $HOME/golang -xzf go1.12.1.linux-amd64.tar.gz
@diolavr
diolavr / go_test_coverage.sh
Created Feb 27, 2019
Golang test coverage
View go_test_coverage.sh
go test -v -coverprofile cover.out
go tool cover -html=cover.out -o coverage.html
@diolavr
diolavr / doFetch.js
Last active Feb 10, 2019
Useful fetch
View doFetch.js
const doError = (errorText, response) => {
const error = new Error(errorText);
error.response = response;
return error;
};
const doFetch = (url, options) => new Promise((resolve, reject) => {
fetch(url, options)
.then((response) => {
if (response.status >= 200 && response.status < 300) {
@diolavr
diolavr / main.go
Created Jan 5, 2019
Golang expectation and reality
View main.go
package main
import (
"bytes"
"fmt"
)
func main() {
line := []byte("GET http://127.0.0.1/listen?timeout=1 HTTP/1.1")
var idx int
View Number of days in the month of the year
sub days_inmonth_inyear {
my ( $x, $y ) = @_;
return 28 + ( ( $x + int( $x / 8 ) ) % 2 ) + 2 % $x + int(
( 1
+ ( 1 - ( $y % 4 + 2 ) % ( $y % 4 + 1 ) )
* ( ( $y % 100 + 2 ) % ( $y % 100 + 1 ) )
+ ( 1 - ( $y % 400 + 2 ) % ( $y % 400 + 1 ) )
) / $x
) + int( 1 / $x ) - int(
( ( 1 - ( $y % 4 + 2 ) % ( $y % 4 + 1 ) )
View Mojolicious all routes
#!/usr/bin/perl
sub startup {
$app->helper(all_routes => \&_all_routes);
}
sub _all_routes {
my $self = shift;
my $route = shift || $self->app->routes;
$route = $self->app->routes->find($route) unless ( (ref $route) =~ m/Mojolicious::Routes/ );
@diolavr
diolavr / javascript.translit.js
Last active Oct 17, 2019
JavaScript translater russian to translit
View javascript.translit.js
function rus_to_latin ( str ) {
var ru = {
'а': 'a', 'б': 'b', 'в': 'v', 'г': 'g', 'д': 'd',
'е': 'e', 'ё': 'e', 'ж': 'j', 'з': 'z', 'и': 'i',
'к': 'k', 'л': 'l', 'м': 'm', 'н': 'n', 'о': 'o',
'п': 'p', 'р': 'r', 'с': 's', 'т': 't', 'у': 'u',
'ф': 'f', 'х': 'h', 'ц': 'c', 'ч': 'ch', 'ш': 'sh',
'щ': 'shch', 'ы': 'y', 'э': 'e', 'ю': 'u', 'я': 'ya'
}, n_str = [];
View Mojolicious hook. Clear whitespace
#!/usr/bin/perl
$self->hook(after_render => sub {
my ($c, $output, $format) = @_;
my $out = $$output;
if ( $c->stash->{'compress'} ) {
$out =~ s/>\s+</></smg;
}
if ( $c->stash->{'compress'} == 2 ) {
View Replaced if-then-else. Just for fun...js
// Before
if ( self.data('branches') ) {
checked_stack.push( this );
} else {
var len = checked_stack.length;
if ( this.checked === true ) {
checked_stack.push( this );
You can’t perform that action at this time.