Skip to content

Instantly share code, notes, and snippets.

View IvanProdaiko94's full-sized avatar
🇺🇦
#StandWithUkraine

Ivan Prodaiko IvanProdaiko94

🇺🇦
#StandWithUkraine
  • Kyiv, Ukraine
  • 09:01 (UTC +03:00)
View GitHub Profile
@IvanProdaiko94
IvanProdaiko94 / tips.md
Last active December 1, 2019 10:33
Tips for new machine set up
curl -u username:token -s https://api.github.com/users/fgimian/repos?per_page=200 | python -c $'import json, sys, os\nfor repo in json.load(sys.stdin): os.system("git clone " + repo["ssh_url"])'
$ git config --global url.git@github.com:.insteadOf https://github.com/
$ cat ~/.gitconfig
// Ex: Complete the Rational class with an add(r:Rational):Rational
// function.
// Ex: Redefine the toString method of the Rational class.
// Ex: Redefine equals method of the Rational class.
// Ex: Add sub, div, mul methods
// Ex: Make sure that rational numbers that are created are optimized e.g. 6/12 is optimized into 1/2.
@IvanProdaiko94
IvanProdaiko94 / appengine_firestore_transaction_delta.go
Last active June 9, 2019 21:15
Convenient way to avoid `read-after-write` errors in datastore transactions. Having delta one can store every change inside it and in the end of transaction call `td.Apply()`.
package firestore
import (
"cloud.google.com/go/firestore"
)
type TransactionDelta struct {
tx *firestore.Transaction
delta []func() error
}
@IvanProdaiko94
IvanProdaiko94 / logger.go
Created March 25, 2018 14:09
Logger for consistency in appengine and local testing
package env
import (
"context"
"fmt"
appengineLog "google.golang.org/appengine/log"
"log"
)
var Logger logger
@IvanProdaiko94
IvanProdaiko94 / appengine_pipe.go
Created March 25, 2018 13:27
Useful pipe to handle request via chain of functions
import (
"net/http"
"context"
"google.golang.org/appengine"
)
type routerRequestHandler func(w http.ResponseWriter, r *http.Request, ctx context.Context) (int, error)
func CreateRequestPipe(fns ...routerRequestHandler) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
@IvanProdaiko94
IvanProdaiko94 / appengine_http_socket.go
Last active January 10, 2018 12:17
Appengine socket usage with http
func GetRequestViaSocket(basicURL string, qs map[string]string, ctx context.Context) ([]byte, error) {
query := queryString(qs)
url := basicURL + query
// create castom transport with appengine socket inside and tls included
transport := &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
Dial: func(network, addr string) (net.Conn, error) {
return socket.Dial(ctx, network, addr)
@IvanProdaiko94
IvanProdaiko94 / read_write_http_requests_over_tcp.go
Created December 30, 2017 21:11
This code sample shows the way how to write raw http request string over tcp connection (could be useful for example in appengine outbound requests)
package main
import (
"bytes"
"io"
"bufio"
"net/http"
"net"
//"crypto/tls" // in order to use https
)
def binary_search(arr, el):
upper_bound = len(arr)
lower_bound = 0
x = -1
while x == -1:
mid = lower_bound + (upper_bound - lower_bound) / 2
if upper_bound < lower_bound:
return x
if arr[mid] < el:
lower_bound = mid + 1
class Node:
def __init__(self, element):
self.element = element
self.prev = None
self.next = None
class SimpleQueue:
def __init__(self):
self.__head = None
@IvanProdaiko94
IvanProdaiko94 / linked_list.py
Created November 13, 2017 13:08
Linked List
class Node:
def __init__(self, element):
self.element = element
self.next = None
class LinkedList:
def __init__(self):
self.size = 0
self.head = None