Skip to content

Instantly share code, notes, and snippets.

View filinvadim's full-sized avatar
🏠
Working from home

Vadim Filin filinvadim

🏠
Working from home
View GitHub Profile
@filinvadim
filinvadim / elastic.go
Created July 29, 2018 11:12
golang elastic channel
// Copyright (c) 2014, Nick Patavalis ([email protected]).
// All rights reserved.
// Use of this source code is governed by a BSD-style license that can
// be found in the LICENSE file.
// Package elastic demonstrates a simple implementation of elastic
// (growable) buffers for channels. See:
// https://github.com/npat-efault/musings/wiki/Elastic-channels
const (
@filinvadim
filinvadim / gethIPCsocket.go
Last active April 5, 2018 13:41
Acces to Go-Ethereum IPC socket
var defaultPaths = []string {
"/.ethereum/geth.ipc", //unix
"/Library/Ethereum/geth.ipc", //macos
"\\\\.\\pipe\\geth.ipc", //win
}
type SocketResolver interface {
GetSocket() string
Connect()
@filinvadim
filinvadim / socket.go
Created March 13, 2018 15:13
Reading very long data from socket
func (c *IPCSocket) Listen() {
buffer := bytes.Buffer{}
for {
reader := bufio.NewReader(c.Connect)
line, prefix, err := reader.ReadLine()
if err != nil {
fmt.Printf("error: can't read form socket:", err)
log.Fatal(err)
}
buffer.Write(line)
@filinvadim
filinvadim / decorator.py
Last active November 9, 2017 15:17
Python decorators simple explanation
def decor(func):
def wrapped(a, b):
a = 'deco'
b = 'rated'
return func(a, b)
return wrapped # not calling yet
@decor # init decor here
@filinvadim
filinvadim / async_object.py
Created November 9, 2017 15:10
Make python object fully async
import asyncio
class _AsyncObject(object):
"""Inheriting this class allows you to define an async __init__.
So you can create objects by doing something like `await MyClass(params)`
"""
@asyncio.coroutine
def __new__(cls, *a, **kw):
@filinvadim
filinvadim / JSONparse.py
Created November 9, 2017 15:08
Recursive JSON parsing
def contains(self, element, list_wrap=False):
"""
Recursively seeks for requested keyword or list of keywords
:param data: json-type dict
:param element: str or list
:return: list or None
"""
collected_elements = []
def _recursively_seek(data):
@filinvadim
filinvadim / regroup.py
Created November 9, 2017 15:07
Group Travelport xml
def regroup_response(self):
"""
Groups elements of request by keys and references on keys.
NOTE that those keys and references actually have meaning of primary and foreign key
in the terms of SQL.
:param data: json like request (actually dicts with lists and strings)
:return: None
"""
keys = {}
@filinvadim
filinvadim / testsuite.py
Created June 19, 2017 10:08
TestSuite Example
testmodules = [
'cogapp.test_makefiles',
'cogapp.test_whiteutils',
'cogapp.test_cogapp',
]
suite = unittest.TestSuite()
for t in testmodules:
try:
func multiparseText() string {
collectedTexts := ""
ch := make(chan string, parseThreadsNum)
defer close(ch)
for i := 0; i < parseThreadsNum; i++ {
go parseText(&ch)
}
for {
unreadData := len(ch)
if unreadData == parseThreadsNum {
@filinvadim
filinvadim / gist:520b07e98a8a458c18a2cd5ed91044c6
Created May 22, 2017 16:44
Автоматическое обновление резюме на HH.ru
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import datetime
import time
while True:
# opening_browser