Skip to content

Instantly share code, notes, and snippets.

View Trafitto's full-sized avatar
💢

Marco Borchi Trafitto

💢
View GitHub Profile

Oh my zsh.

Install with curl

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

Enabling Plugins (zsh-autosuggestions & zsh-syntax-highlighting)

  • Download zsh-autosuggestions by
@Trafitto
Trafitto / skip_yt_ads.js
Created March 21, 2024 11:29
Copied from the internet I don't remember where, skip the YouTube ads
javascript:(function(){ad = [...document.querySelectorAll('.ad-showing')][0]; if(ad != null) { video = document.querySelector('video'); video.currentTime = video.duration; }})();
@Trafitto
Trafitto / clean_deezer_flows_bookmarks.js
Created March 21, 2024 11:25
Remove some Deezer Flow (You can save this script as a bookmark and clik it when needed)
javascript:(()=>{
var shitFlowIds = ['flow-config-empowerment', 'flow-config-genre-kpop', 'flow-config-genre-pop'];
shitFlowIds.forEach(flow => (document.querySelector(`[data-testid="${flow}"]`).parentElement.remove()));
})();
@Trafitto
Trafitto / time_limited_paginator.py
Created October 12, 2023 13:43 — forked from hakib/time_limited_paginator.py
CountTimeoutLimitPaginator - Paginator that enforced a timeout on the count operation.
class TimeLimitedPaginator(Paginator):
"""
Paginator that enforced a timeout on the count operation.
When the timeout is reached a "fake" large value is returned instead,
Why does this hack exist? On every admin list view, Django issues a
COUNT on the full queryset. There is no simple workaround. On big tables,
this COUNT is extremely slow and makes things unbearable. This solution
is what we came up with.
"""
import random
def simulate(num_tokens_to_pick, black_tokens, white_tokens):
picked_tokens = []
for _ in range(min(num_tokens_to_pick, black_tokens)):
picked_tokens.append("black")
black_tokens -= 1
num_tokens_to_pick -= 1
@Trafitto
Trafitto / urls.py
Last active October 27, 2022 08:17
Django-Rest-Framework custom router that accept urls with or without slash at the end
from rest_framework.routers import DefaultRouter
class OptionalTraillingSlashRouter(DefaultRouter):
def __init__(self, trailing_slash=True):
super().__init__(trailing_slash)
self.trailing_slash = "/?"
def get_lookup_regex(self, viewset):
base_regex = '(?P<{lookup_field}>[^/.]+)'
lookup_field = getattr(viewset, 'lookup_field', 'pk')
'''
Response example:
{
"bestemmia": "DIO CANE",
"count": 2
}
'''
response = requests.get(BASE_URL.format(endpoint="random"))
response.raise_for_status()
import requests
BASE_URL = "http://bestemmie.org/api/{endpoint}"
params = {
"bestemmia": "Dio cane"
}
response = requests.post(BASE_URL.format(endpoint="bestemmie/"), params)
response.raise_for_status()
'''
Return 204 no content
import requests
BASE_URL = "http://bestemmie.org/api/{endpoint}"
'''
Optional params:
offset (default 50)
limit (default 50)
Response field:
count: total distinct count of bestemmie
import requests
BASE_URL = "http://bestemmie.org/api/{endpoint}"
# GET ALL BESTEMMIE
# ENDPOINT: /bestemmie
'''
Method: GET
Optional params: