Skip to content

Instantly share code, notes, and snippets.

View Granitosaurus's full-sized avatar
🍯
🐝

Bernardas Ališauskas Granitosaurus

🍯
🐝
View GitHub Profile
@Granitosaurus
Granitosaurus / python.py
Created April 23, 2018 03:50
Test python
import requests
from minds import Minds
api = Minds()
print(api)
@Granitosaurus
Granitosaurus / gitter_matrix.md
Last active February 21, 2019 09:56
Joining channel gitter on matrix

How to join gitter server on matrix

You can bridge gitter in matrix. For that you need to conver gitter url to valid matrix address.

Bridge template #gitter_<server>=2F<channel>:matrix.org

e.g.

  https://gitter.im/xonsh/xonsh
 server/channel
@Granitosaurus
Granitosaurus / lazy_dict_merge.py
Created May 1, 2019 14:21
this function merges two dictionaries lazily and recursively (supports nested dicts)
# LICENSE GPLv3
def lazy_dict_merge(root, update):
"""
this function merges two dictionaries lazily and recursively (supports nested dicts)
Lazy means only missing keys will be updated,
i.e. update['foo'] will only be copied to root if it doesn't have 'foo' already
>>> lazy_dict_merge({'foo': '1'}, {'bar': '2'})
@Granitosaurus
Granitosaurus / delete-history.py
Created December 10, 2019 08:25
Delete xonsh shell history by matching patterns i.e. `python delete-history.py "^ping"` will delete every history command that starts with "ping"
"""
Delete xonsh shell history by matching patterns
i.e. `python delete-history.py "^ping"` will delete every history command that starts with "ping"
"""
import json
from json import JSONDecodeError
from pathlib import Path
import click
import os
@Granitosaurus
Granitosaurus / infer_dtf.py
Created February 24, 2020 07:48
Infer date format from date string in python
somedate = '2020-02-24 07:22'
somedates = ['2020-02-24 07:22', '1995-12-01 22:00', '2001-01-01 11:54']
import dateinfer
print(dateinfer.infer(somedate)
#'%H' incorrect
print(dateinfer.infer(somedates)
#'%Y-%m-%d %H:%M' correct!
@Granitosaurus
Granitosaurus / object_hook.py
Created September 18, 2020 10:14
python object hook
def object_hook(dict_, func: Callable, types: Union[Tuple[Type], Type] = dict):
"""
object hook for python dictionary - applies function to every object of type recursively
note: dictionary keys are not considered to be objects and will be type matched,
for processing dictionary keys you should process whole dict type.
example:
>>> object_hook({'foo': 'bar'}, str.upper, str)
{'foo': 'BAR'}
import requests
headers = {
# when web scraping we always want to appear as
# a web browser to prevent being blocked
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36"
}
data = {
# our recipe search term
"searchTerm": "Toast",
{
"contexts": [
"{\"name\":\"toast\",\"paths\":[\"/~asset/bread\"],\"type\":\"PRIMARY\",\"searchType\":\"NORMAL\",\"degreesSeparation\":0,\"cleanedName\":\"toast\",\"popularityFactor\":0,\"taggedContentCount\":2054,\"userToken\":true,\"searchGuess\":false,\"essenceContext\":false,\"matchingCandidate\":false}"
],
"searchTerm": "toast",
"pn": 14
}
@Granitosaurus
Granitosaurus / avbuyer.com_scraper.py
Created November 17, 2021 07:20
aircraft scraper for avbuyer.com website.
import asyncio
from aiohttp.client import ClientSession
from parsel import Selector
async def get_page(page: int, session: ClientSession):
"""This is a little shortcut function that requests specific page of our pagination"""
url = f"https://www.avbuyer.com/aircraft/private-jets/page-{page}"
print(f"requesting {url}")
return await session.get(url)
@Granitosaurus
Granitosaurus / ultimate-gaming-glossary.txt
Created May 15, 2022 08:05
Ultimate list of popular, gaming-related terms
Aggro - Refers to attention from in-game enemies, often relating to the distance at which an enemy will notice the player character and engage in combat, or - in a multiplayer setting - the player being targeted by an enemy. See also: 'Tanking'
ARPG - An acronym for 'action role-playing game', ARPG is a sub-genre of RPG that focuses primarily on combat, exploration and character development. Typically involving lengthy dungeons and tough boss fights, ARPGs are popular with min-max playstyles.
ADS - Short for 'Aim Down Sights', ADS is the action of raising a ranged weapon to eye-level and aiming along the sights.
AoE - Short for 'Area of Effect', AoE refers to attacks which cover a certain area with a damaging effect.
Bots - A bot is a computer-controlled character playing alongside regular players in a multiplayer setting. It may also refer to an inexperienced or poor player, whose ability is no greater than an AI bot.
Backwards compatibilty - The ability of a games console to run software created for prior c