Skip to content

Instantly share code, notes, and snippets.

View mka142's full-sized avatar

Michał Kulbacki mka142

View GitHub Profile
import PropTypes from "prop-types";
/**
* Find relative path from to to pathname
* @param {String} to
* @param {String} pathname
* @returns {String} rlative path
*/
export const relative = (to, pathname) => {
let to_list = to.split("/");
let to_obj = Object.fromEntries(to.split("/").entries());
#based on
# @immuntasir
#immuntasir/drive_script_gen.ipynb
# Script for generating sh file that will download ans save in tree all files under given parent folder id from Google drive.
#Executing
# python gdrive_download_folder.py -s <folder_id> -f output_file_name
# Import the Libraries
@mka142
mka142 / SetupDjangoTestApp.py
Last active July 19, 2022 19:57
Django test with custom models
#https://code.djangoproject.com/ticket/7835
# __init__.py
from django.apps import AppConfig, apps
def setup_test_app(package, label=None):
"""
Setup a Django test app for the provided package to allow test models
tables to be created if the containing app has migrations.
@mka142
mka142 / PortalToElement.jsx
Created July 7, 2022 21:56
React portal class component
import React from "react";
import ReactDOM from "react-dom";
export default class PortalToElement extends React.Component {
constructor(props) {
super(props);
this.el = document.createElement("div");
this.el.style.display = "contents";
// The <div> is a necessary container for our
// content, but it should not affect our layout.
@mka142
mka142 / numCode.py
Created April 5, 2022 15:04
encode and decode from decimal system to alphabet numeric system and reverse
class numCode:
characters = list('abcdefghijklmnopqrstuvwxyz')
def __init__(self,**kwargs):
self.characters = list('abcdefghijklmnopqrstuvwxyz')
if 'characters' in kwargs.keys():
self.characters = kwargs['characters']
@classmethod
@mka142
mka142 / password_generator.py
Created April 5, 2022 15:03
Generate password in python using letters, numbers and punctation
import random
def password_generator(length=50,table=[1,1,0]): # to refactor
IS_CHOOSEEN = lambda x,y: x if y==1 else ''
LETTERS = IS_CHOOSEEN(string.ascii_letters,table[0])
NUMBERS = IS_CHOOSEEN(string.digits,table[1])
PUNCTUATION = IS_CHOOSEEN(string.punctuation,table[2])
# create alphanumerical by fetching string constant
printable = NUMBERS + LETTERS + PUNCTUATION
@mka142
mka142 / in_range.py
Created April 5, 2022 14:59
Check if date,number in in range of other two
def in_range(start, end, x):
"""Return true if x is in the range [start, end]"""
if start <= end:
return start <= x <= end
else:
return start <= x or x <= end