Skip to content

Instantly share code, notes, and snippets.

View StasDeep's full-sized avatar

Stanislau Hluboki StasDeep

View GitHub Profile
@StasDeep
StasDeep / complex_modification.json
Created February 27, 2023 10:15
Map mouse buttons 4 and 5 to switching desktops default shortcuts
[
{
"description": "MouseButton5 to Ctrl+LeftArrow",
"manipulators": [
{
"from": {
"pointing_button": "button5"
},
"to": [
{
@StasDeep
StasDeep / brilliant-2021-03-20-red-black-cards-cut.py
Created March 20, 2021 07:06
Solution to the "To Cut, or Not to Cut" Brilliant daily problem
import random
def get_deck(blacks, reds):
deck = ['B'] * blacks
red_position = random.randint(0, len(deck))
for _ in range(reds):
deck.insert(red_position, 'R')
return deck
@StasDeep
StasDeep / test.py
Created June 10, 2020 07:52
Missing storage.store call
from logging import getLogger
import scrapy
from scrapy.extensions.feedexport import BlockingFeedStorage
logger = getLogger(__name__)
class GsFeedStorage(BlockingFeedStorage):
@StasDeep
StasDeep / test.py
Created June 9, 2020 16:24
Duplicated feed logs with BlockingFeedStorage
from time import sleep
import scrapy
from scrapy.extensions.feedexport import BlockingFeedStorage
class GsFeedStorage(BlockingFeedStorage):
def __init__(self, uri):
self.uri = uri
@StasDeep
StasDeep / patreon_estimator.py
Created December 11, 2019 12:55
Estimate how donations are allocated on Patreon creator's page given total money and number of patrons
from time import time
SOLUTION_LIMIT = 100
def get_solutions(num, total_sum, possible_vals, most_likely_val=None):
possible_vals = sorted(possible_vals)
# Histogram mapping shows what index a value has in the histogram array
@StasDeep
StasDeep / script.py
Last active March 7, 2019 06:28
Download episodes from fanserials (Python 3.6 + Scrapy + ffmpeg)
import json
import os
import shutil
import subprocess
from sys import argv
import scrapy
from scrapy.crawler import CrawlerProcess
@StasDeep
StasDeep / download.py
Created February 22, 2019 03:56
Download a YouTube video with python
"""
Usage:
$ python download.py *video_url* itag
<Stream: itag="22" mime_type="video/mp4" res="720p" fps="30fps" vcodec="avc1.64001F" acodec="mp4a.40.2">
<Stream: itag="43" mime_type="video/webm" res="360p" fps="30fps" vcodec="vp8.0" acodec="vorbis">
<Stream: itag="18" mime_type="video/mp4" res="360p" fps="30fps" vcodec="avc1.42001E" acodec="mp4a.40.2">
<Stream: itag="36" mime_type="video/3gpp" res="240p" fps="30fps" vcodec="mp4v.20.3" acodec="mp4a.40.2">
<Stream: itag="17" mime_type="video/3gpp" res="144p" fps="30fps" vcodec="mp4v.20.3" acodec="mp4a.40.2">
$ python download.py *video_url* 22 video.mp4