Skip to content

Instantly share code, notes, and snippets.

View RadoslawB's full-sized avatar
🎯
Focusing

Radosław Białowąs RadoslawB

🎯
Focusing
View GitHub Profile
/*
Imagine this is table named EmployeeTable in relational database
Role Name Building Years_employed
Engineer Becky A. 1e 4
Engineer Dan B. 1e 2
Engineer Sharon F. 1e 6
Engineer Dan M. 1e 4
NULL Malcom S. 1e 1
Artist Tylar S. 2w 2
@RadoslawB
RadoslawB / predict_output_interview_questions.py
Last active September 22, 2023 13:23
Python native code reading exercise as developers recruitment interview task
def predict_output_1(list_):
result = [x * 2 for x in list_ if x % 2 == 0]
return result
numbers = [1, 2, 3, 4, 5]
output_5 = predict_output_1(numbers)
@RadoslawB
RadoslawB / middleware.py
Created December 13, 2022 15:37
FastAPI logging middleware
import datetime
import json
import logging
import time
import traceback
from json import JSONDecodeError
from starlette.requests import Request
from starlette.responses import Response, StreamingResponse
@RadoslawB
RadoslawB / ipynb
Created July 8, 2021 09:14
nb_widgets_viewer_render_test
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "nominated-kidney",
"metadata": {
"ExecuteTime": {
"end_time": "2021-07-08T08:59:12.838149Z",
"start_time": "2021-07-08T08:59:12.789863Z"
@RadoslawB
RadoslawB / clean_code.md
Created May 25, 2020 20:43 — forked from wojteklu/clean_code.md
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

@RadoslawB
RadoslawB / nosleep.sh
Created April 15, 2020 09:01
Completely disable sleep on any Mac
# Useful to prevent Macbooks to go to sleep when closing the lid instead of running tools that requires a Kernel Extension (e.g. InsomniaX) and more
# Before doing anything, save your current configuration using
pmset -g
# To disable sleep
sudo pmset -a sleep 0; sudo pmset -a hibernatemode 0; sudo pmset -a disablesleep 1;
# And to go back to normal
sudo pmset -a sleep 1; sudo pmset -a hibernatemode [original hibernatemode value]; sudo pmset -a disablesleep 0;
const fs = require('fs');
const { promisify } = require('util');
const uploadFiles = (directoryPath, s3client) => promisify(fs.readdir)(directoryPath)
.then(files => files.map(fileName => getUploadFileOptions(fileName, directoryPath, AWS_S3_BUCKET_NAME)))
.then(uploadOptions => Promise.all(uploadOptions.map(option => uploadFile(option, s3client))))
.catch(e => {
console.log('Failed to upload files');
throw e;
piped = pipe(
str.strip,
str.capitalize,
)(' PIPED ') # -> 'Piped'
print(piped)
add_one = lambda x: x + 1
double = lambda x: x * 2
@RadoslawB
RadoslawB / pipe_compose.py
Last active March 24, 2020 01:06
Python pipe higher-order function
from functools import reduce
def pipe(*functions):
return lambda x: reduce(lambda previous, next_: next_(previous), functions, x)
def compose(*functions):
return lambda x: reduce(lambda previous, next_: next_(previous), reversed(functions), x)
@RadoslawB
RadoslawB / rx-animations-component.ts
Created March 20, 2020 13:39
Rxjs animations draft
import {Component} from '@angular/core';
import {defer, interval, Observable, of, range, Subscription, timer} from 'rxjs';
import {buffer, map, mapTo, share, takeWhile, tap} from 'rxjs/operators';
import {animationFrame} from 'rxjs/internal/scheduler/animationFrame';
/**
* Without scheduler -> browser gets locked.
*/
const endlessStreamOfFramesByRange: Observable<number> = range(0, Number.POSITIVE_INFINITY, animationFrame);