Skip to content

Instantly share code, notes, and snippets.

@ohld
ohld / update_metabase_docker.sh
Last active February 19, 2022 17:43
How to safely update Metabase if you use docker deployments WITHOUT ANY DATA LOSS
# check the name of metabase container
docker ps
# make a backup
docker cp metabase:/metabase.db /root/
# get updated version
docker pull metabase/metabase
# remove old running container
@ohld
ohld / yt_radio_with_current_track.sh
Created April 9, 2020 20:41
How to create 24/7 radio on Youtube (like lo fi radio for study / chill / relax)
#! /bin/bash
VBR="1500k"
FPS="24"
QUAL="superfast"
YOUTUBE_URL="rtmp://a.rtmp.youtube.com/live2"
KEY="z5k3-8888-69qu-9999"
VIDEO_SOURCE="/home/root/cover.gif"
@ohld
ohld / yt_radio.sh
Created April 9, 2020 20:39
Script to create a youtube 24/7 radio (like lofi radio for study/relax/sleep)
#! /bin/bash
VBR="1500k"
FPS="24"
QUAL="superfast"
YOUTUBE_URL="rtmp://a.rtmp.youtube.com/live2"
KEY="z5k3-8888-69qu-9999"
VIDEO_SOURCE="/home/root/cover.gif"
@ohld
ohld / webhook.py
Last active February 28, 2022 02:44
Create 24/7 Youtube online radio (like lo-fi music for study/relax/sleep)
import os, json
from flask import Flask, request
app = Flask(__name__)
FNAME = "song.txt"
@app.route('/', methods=['POST','GET'])
def index():
with open(FNAME, "w") as f:
@ohld
ohld / dokku_install_metabase.sh
Created March 25, 2020 17:14
Run Metabase on Dokku
# Create Dokku app
dokku apps:create metabase
# Pull Metabase instance from Docker
docker pull metabase/metabase
# Retag Dokker to allow Dokku to understand everything
docker tag metabase/metabase:latest dokku/metabase:latest
# Deploy Metabase Instance
@ohld
ohld / code_to_media_id.py
Created February 19, 2020 20:14
Convert Instagram media URL to media_id
# This is Python port of this Javascript method:
# https://github.com/notslang/instagram-id-to-url-segment/blob/master/lib/index.coffee
url = "https://www.instagram.com/p/B8iwlG9pXHI/"
# ----> use regexp to extract code from url
code = "B8iwlG9pXHI"
charmap = {
'A': '0',
'B': '1',
@ohld
ohld / broadcast_message.html
Created October 30, 2019 10:31
Django Admin action Intermediate page code template
<!-- my_django_app/templates/admin/broadcast_message.html -->
<!-- This block will be included to django admin basic template -->
{% extends "admin/base_site.html" %}
{% block content %}
<form action="" method="post">{% csrf_token %}
<!-- The code of the form with all input fields will be automatically generated by Django -->
{{ form }}
<!-- Show the list of selected objects on the previous step -->
@ohld
ohld / admin.py
Last active November 9, 2020 20:57
Django Admin action with intermediate page example
# your_app/admin.py
# ... imports
@admin.register(User)
class UserAdmin(admin.ModelAdmin):
actions = ['broadcast'] # register method as action
def broadcast(self, request, queryset):
if 'apply' in request.POST: # if user pressed 'apply' on intermediate page
@ohld
ohld / now.json
Created October 15, 2019 16:54
Ziet co config to use secret environment variables in python projects
{
"builds": [{
"src": "index.py", "use": "@now/python"
}],
"routes": [
{ "src": "/(.*)", "dest": "index.py" }
],
"env": {
"TELEGRAM_TOKEN": "@telegram-token"
}
@ohld
ohld / index.py
Created October 15, 2019 16:44
Now sh (Zeit co) simple Serverless Telegram echo bot (in Python)
import os
import logging
import telegram
from flask import Flask, jsonify, request
app = Flask(__name__)
@app.route('/api', methods=['POST'])
def api():
bot = telegram.Bot(token=os.getenv("TELEGRAM_TOKEN"))