Skip to content

Instantly share code, notes, and snippets.

View tomash's full-sized avatar

Tomasz Stachewicz tomash

View GitHub Profile
@HashNuke
HashNuke / cloudflare-r2-download-worker.js
Last active March 13, 2025 10:16
Cloudflare worker that downloads files from R2 bucket
import jwt from '@tsndr/cloudflare-worker-jwt'
// Add following config to wrangler.toml
//
// r2_buckets = [
// { binding = "STORAGE_BUCKET", bucket_name = "your_bucket_name" }
// ]
//
// Also requires download_jwt_secret in the worker env
@florentroques
florentroques / vtt2text.py
Last active September 5, 2024 01:44 — forked from glasslion/vtt2text.py
This script converts youtube subtitle file(vtt) to plain text.
"""
Convert YouTube subtitles(vtt) to human readable text.
Download only subtitles from YouTube with youtube-dl:
youtube-dl --skip-download --convert-subs vtt <video_url>
Note that default subtitle format provided by YouTube is ass, which is hard
to process with simple regex. Luckily youtube-dl can convert ass to vtt, which
is easier to process.
@jeffchannell
jeffchannell / chapters.sh
Last active January 17, 2025 11:56
Create FFMETADATA for ffmpeg from multiple files.
#!/usr/bin/env bash
# FFMETADATA Chapter generator
# Pass multiple media files to this script to generate a generic FFMETADATA file
# Usage: ARTIST="My Artist" ALBUM="My Album" ./chapters.sh /path/to/*.wav > my.metadata
set -eo pipefail
ARTIST="${ARTIST:-ARTIST}"
ALBUM="${ALBUM:-ALBUM}"
end_stamp=0
begin_stamp=0
i=1
@tenderlove
tenderlove / ngpng.rb
Last active December 12, 2020 14:09
Simple PNG generation example that only depends on zlib in Ruby
# Not Great PNG class. This is a very simple example of writing a PNG. It
# only supports colors from the color palette stored in `@palette`. This is
# meant to be example code, but I am using it in a program for visualizing
# heap dumps from Ruby.
#
# This is free and unencumbered software released into the public domain.
#
# Anyone is free to copy, modify, publish, use, compile, sell, or
# distribute this software, either in source code form or as a compiled
# binary, for any purpose, commercial or non-commercial, and by any
@ali-sheiba
ali-sheiba / _form.html.erb
Last active July 24, 2024 07:49
Rails scaffold with Bootstrap 4
<%%= form_with(model: <%= model_resource_name %>, local: true) do |form| %>
<div class="card mb-4">
<div class="card-body">
<%% if <%= singular_table_name %>.errors.any? %>
<div id="error_explanation" class="alert alert-danger">
<h2 class="h4"><%%= pluralize(<%= singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:</h2>
<ul>
<%% <%= singular_table_name %>.errors.full_messages.each do |message| %>
<li><%%= message %></li>
@glasslion
glasslion / vtt2text.py
Last active March 9, 2025 02:54
This script convert youtube subtitle file(vtt) to plain text.
"""
Convert YouTube subtitles(vtt) to human readable text.
Download only subtitles from YouTube with youtube-dl:
youtube-dl --skip-download --convert-subs vtt <video_url>
Note that default subtitle format provided by YouTube is ass, which is hard
to process with simple regex. Luckily youtube-dl can convert ass to vtt, which
is easier to process.
@tclavier
tclavier / find-oldest-line
Created July 24, 2017 07:27
Find oldest line in git repo
#!/bin/bash
for file in $(find . -type f);
do
git blame --date=format:%Y%m%d $file
done | sed -e 's/.*\s\([0-9]\{8\}\)\s.*/\1/' | sort -r | tail
@bf4
bf4 / bin-squash_migrations
Created November 12, 2015 16:07
Squash Rails migrations in this one easy step
#!/usr/bin/env bash
git ls-files db/migrate/*.rb | sort | tail -1 | \
ruby -e "schema_version=STDIN.read[/\d+/]; init_schema=%(db/migrate/#{schema_version}_init_schema.rb);
%x(git rm -f db/migrate/*.rb;
mkdir db/migrate;
git mv db/schema.rb #{init_schema};
rake db:migrate;
git add db/schema.rb; git commit -m 'Squashed migrations')"
var mediaJSON = { "categories" : [ { "name" : "Movies",
"videos" : [
{ "description" : "Big Buck Bunny tells the story of a giant rabbit with a heart bigger than himself. When one sunny day three rodents rudely harass him, something snaps... and the rabbit ain't no bunny anymore! In the typical cartoon tradition he prepares the nasty rodents a comical revenge.\n\nLicensed under the Creative Commons Attribution license\nhttp://www.bigbuckbunny.org",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" ],
"subtitle" : "By Blender Foundation",
"thumb" : "images/BigBuckBunny.jpg",
"title" : "Big Buck Bunny"
},
{ "description" : "The first Blender Open Movie from 2006",
"sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4" ],
@emad-elsaid
emad-elsaid / download-facebook-messages.rb
Created March 22, 2014 12:48
Download all messages between you and a friend from facebook
require 'koala' # gem install koala --no-document
# create a facebook app and get access token from here
# https://developers.facebook.com/tools/explorer
# select "read_mailbox" when authenticating
oauth_access_token = 'xxxxxxxxxxxxxxxxxxxxxx'
graph = Koala::Facebook::API.new(oauth_access_token)
# get all latest messages
limit = 10