Skip to content

Instantly share code, notes, and snippets.

View ceoro9's full-sized avatar
:octocat:
wth'ma I doin'

Roman ceoro9

:octocat:
wth'ma I doin'
  • Minsk, Belarus
View GitHub Profile
reduce(lambda prev_el, el: ''.join(prev_el) + ' ' + ''.join(el), zip_longest(*[iter(str(a)[::-1])] * 3, fillvalue=''))[::-1]
@ceoro9
ceoro9 / currying.py
Created July 23, 2019 06:40
Python Currying
# Demonstrate Currying of composition of function
def change(b, c, d):
def a(x):
return b(c(d(x)))
return a
def kilometer2meter(dist):
""" Function that converts km to m. """
return dist * 1000
def map_many(iterable, *funcs):
if funcs:
return many_map(map(funcs[0], iterable), funcs[1:])
return iterable
stale_checkouts = filter(
lambda cr: not [
pt for pt in payment_transactions
if pt['ac_transaction_id'] == cr['transaction_id']
],
checkout_transactions,
)
@ceoro9
ceoro9 / chalice_traceback.log
Last active May 28, 2019 06:50
Error when cors is disabled on endpoint
Exception happened during processing of request from ('127.0.0.1', 34818)
Traceback (most recent call last):
File "/usr/lib/python3.6/socketserver.py", line 651, in process_request_thread
self.finish_request(request, client_address)
File "/usr/lib/python3.6/socketserver.py", line 361, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/home/dev/jo/refunite-tasks/venv/lib/python3.6/site-packages/chalice/local.py", line 532, in __init__
self, request, client_address, server) # type: ignore
File "/usr/lib/python3.6/socketserver.py", line 721, in __init__
self.handle()
mapped_images: Iterator[Tuple[TaskImage, UserUploadedImage]] = \
map_task_and_user_uploaded_images(task_images, user_uploaded_images)
overlayed_map_images: List[Tuple[TaskImage, OverlayedImage]] = [
(task_image, user_uploaded_images.convert_to_overlayed_image(task_image),)
for task_image, user_uploaded_images in mapped_images
]
# --------------------------------------------------------------------------------
# --------------------------------------------------------------------------------
package main
import (
"fmt"
"time"
)
var get_value chan int
func send_value(x int) {
@ceoro9
ceoro9 / retries.py
Last active May 10, 2019 08:15
Call method with retries
import time
class CustomException(Exception):
pass
def retry(max_attempts=1,
should_retry=lambda _e: True,
retryable_exceptions=tuple(),
@ceoro9
ceoro9 / bq.go
Created April 29, 2019 14:44
Insert data to big query
package main
import (
"fmt"
"context"
"cloud.google.com/go/bigquery"
)
type Item struct {
@ceoro9
ceoro9 / bg_insert.go
Last active April 29, 2019 14:31
Insert data to BigQuery
func insertRows(client *bigquery.Client, datasetID, tableID string) error {
ctx := context.Background()
// [START bigquery_table_insert_rows]
u := client.Dataset(datasetID).Table(tableID).Uploader()
items := []*Item{
// Item implements the ValueSaver interface.
{Name: "Phred Phlyntstone", Age: 32},
{Name: "Wylma Phlyntstone", Age: 29},
}
if err := u.Put(ctx, items); err != nil {