Skip to content

Instantly share code, notes, and snippets.

View Granitosaurus's full-sized avatar
🍯
🐝

Bernardas Ališauskas Granitosaurus

🍯
🐝
View GitHub Profile
@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 / 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 / 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 / python.py
Created April 23, 2018 03:50
Test python
import requests
from minds import Minds
api = Minds()
print(api)
# instead of
with open('./data/avail_urls.txt', 'w') as f:
for item in items:
if 'archived_snapshots' in item:
if 'closest' in item['archived_snapshots']:
f.write(item['archived_snapshots']['closest']['url'] + '\n')
# write
with open('./data/avail_urls.txt', 'w') as f:
for item in items:
if 'closest' not in item.get('archived_snapshots', []):
@Granitosaurus
Granitosaurus / check_proxies.py
Created March 6, 2018 05:53
Check proxies with async python
import os
from requests.exceptions import ProxyError, ReadTimeout
from requests_futures.sessions import FuturesSession
def check_proxies(proxies, max_workers=5, timeout=5):
"""
Check whether proxies are functional and whether authentication matches.
This function will filter out any proxies that:
* return 407 credential missmatch
@Granitosaurus
Granitosaurus / vr_check
Created May 5, 2017 11:33
Python script for checking whether a video game on steam supports VR devices.
#!/usr/bin/env python3
from urllib.parse import quote, unquote
# requires click, parsel, requests_futures from pip
# requires python3.6
import click
from requests_futures.sessions import FuturesSession
from parsel import Selector
@Granitosaurus
Granitosaurus / bundlestars.py
Last active April 21, 2017 06:45
Scraper for bundlestars bundles, ouputs links and steam reviews in reddit comment format.
import json
import re
import requests
from parsel import Selector
def scrape():
data = requests.get('https://www.bundlestars.com/api/promotions/mega-pick-mix-bundle-2')
products = json.loads(data.text)[0]['products']
# -*- coding: utf-8 -*-
import scrapy
class MyipSpider(scrapy.Spider):
name = "myip"
allowed_domains = ["http://httpbin.org/ip"]
start_urls = (
'http://httpbin.org/ip',
)
@Granitosaurus
Granitosaurus / steam_game_linkinator
Last active September 29, 2017 22:26
converts a list of games into linked items with reviews.
import requests
from parsel import Selector
def scrape():
data = """
7 Grand Steps: What Ancients Begat (DRM Free + Steam)
2064: Read Only Memories (DRM Free + Steam)
A Virues Named TOM (DRM Free + Steam)
AI War: Fleet Command (DRM Free + Steam)