Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View milosb793's full-sized avatar

milosb793

  • At the Cloud
View GitHub Profile
@milosb793
milosb793 / safe_getter.py
Last active September 19, 2023 13:28
Safe attribute accessor for (almost) all types - Python
def get(obj, key: str | int, default=None):
"""
Try to get index, key or a property
for a given list, dict or object,
returns default on error
Params:
- obj: mixed - dict, list, object
- key: str - either any key or dot accessor like: foo.bar.0
@milosb793
milosb793 / recreate_database.py
Last active March 23, 2022 14:54
Interactive Python script used to automate (re)creation of database using MySQL (MariaDB)
#!/usr/bin/env python
# - * -coding: utf - 8 - * -
"""
This very simple CLI application is used to automate process of recreating existing database or creating new one.
It's written in Python 3.6. and it uses MySQLdb library for connection with database.
On start, it asks for credentials. You can just skip inputs (by pressing enter) for default values.
If you don't have MySQLdb package, install it with:
`sudo apt-get install python-pip python-dev libmysqlclient-dev python3-mysqldb`
"""
@milosb793
milosb793 / fontawesome_fetcher.js
Last active February 11, 2021 11:31
A JS class that downloads all icons and pack it in proper format for further usage
/**
* 1. Load a page: https://fontawesome.com/icons?d=gallery
* 2. Press F12 and paste the code in the console
* 3. Wait until all data is fetched and packed
* 4. Use downloader.dump() to get JSON
**/
class FontAwesomeDownloader {
static proIconsClass = 'gray4'; /* parent */
static visibleIconsSelector = '#results-icons i';
@milosb793
milosb793 / DatabaseCreateCommand.php
Last active December 21, 2019 08:16
Laravel Command used for creating database.
<?php
namespace App\Console\Commands;
use PDO;
use PDOException;
use Illuminate\Console\Command;
@milosb793
milosb793 / indexes_table_max_1000.sql
Last active December 9, 2019 09:34
Create table with just indexes used for example for converting JSON array elements to rows: https://stackoverflow.com/a/51656467/6118794
CREATE TABLE IF NOT EXISTS `t_list_row` (
`_row` int(10) unsigned NOT NULL,
PRIMARY KEY (`_row`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
INSERT t_list_row VALUES (0), (1), (2), (3), (4), (5), (6), (7), (8), (9), (10), (11), (12), (13), (14), (15), (16), (17), (18), (19), (20), (21), (22), (23), (24), (25), (26), (27), (28), (29), (30), (31), (32), (33), (34), (35), (36), (37), (38), (39), (40), (41), (42), (43), (44), (45), (46), (47), (48), (49), (50), (51), (52), (53), (54), (55), (56), (57), (58), (59), (60), (61), (62), (63), (64), (65), (66), (67), (68), (69), (70), (71), (72), (73), (74), (75), (76), (77), (78), (79), (80), (81), (82), (83), (84), (85), (86), (87), (88), (89), (90), (91), (92), (93), (94), (95), (96), (97), (98), (99), (100), (101), (102), (103), (104), (105), (106), (107), (108), (109), (110), (111), (112), (113), (114), (115), (116), (117), (118), (119), (120), (121), (122), (123), (124), (125), (126), (127), (128), (129), (130), (131), (132), (133), (134), (135), (136), (137), (13
@milosb793
milosb793 / factorial.py
Last active July 31, 2019 09:09
Recursive & Iterative solution of Factorial algorythm
"""
About:
Script for playing with recursion in python, by calculating factorial of number n
Supported versions:
>= 2.7
Examples:
factorial.py 100
factorial.py 100 -jt (display just seconds, without results)