Skip to content

Instantly share code, notes, and snippets.

View nirlanka's full-sized avatar

Nir Lanka nirlanka

  • SGX
  • Singapore
View GitHub Profile
@nirlanka
nirlanka / yt-download.sh
Created August 21, 2024 06:20
Download from YouTube (as channel member)
pipenv shell # should have yt-dlp installed
yt-dlp --write-subs --sub-lang en --convert-subs srt --sub-format txt --cookies-from-browser chrome <VIDEO-OR-PLAYLIST-URL>
# https://apple.stackexchange.com/questions/434686/how-to-get-cookies-txt-for-youtube-from-safari
@nirlanka
nirlanka / download.sh
Last active August 21, 2024 03:26
Download stream from m3u8 playlist
ffmpeg -i https://<SITE>/playlist/<ID>=.m3u8 -codec copy "<FILENAME>.mkv"
// Source: https://superuser.com/questions/1705706/how-can-m3u8-and-ts-streams-or-videos-properly-be-saved-without-any-pixelated
@nirlanka
nirlanka / youtube-all-videos-to-playlist.js
Last active July 15, 2024 03:55
(YouTube) Create a playlist from a channel with all its videos
// 1. Create a new playlist
// 2. Load all video thumbnails in channel in required order (scroll down until the end)
// 3. Run script:
{
const ll=document.querySelectorAll('yt-icon-button.dropdown-trigger.style-scope.ytd-menu-renderer #button'); // all videos' menu buttons
let i=0;
function loop() {
ll[i].click(); // open menu
document.querySelectorAll('tp-yt-paper-listbox ytd-menu-service-item-renderer')[2].click(); // click Add to Playlist
setTimeout(() => {
@nirlanka
nirlanka / replace-static-page-content.js
Last active May 30, 2020 14:48
Replace body of current static page with another page (without reload) (Note: In this page, <header> isn't considered to change except the <title>. Also, this will mess up the back button, unless you handle window 'popstate' yourself.)
(function() {
if (fetch && Promise && document.querySelector && history) { // <-- Dependencies. Otherwise normal links will remain.
function loadPage(url) {
fetch(url).then(function (res) {
return res.text();
}).then(function(html) {
var dom = new DOMParser().parseFromString(html, 'text/html');
var title = dom.querySelector('title').innerText;
history.pushState({}, title, url);
document.title = title;
@nirlanka
nirlanka / simple-html-tokeniser.js
Last active April 24, 2020 03:31
Simple tokenizer examples
`<div>
Some text here
<div>
<h3>Lorem <a href="./abc/def.html">ipsum</a></h3>
<p>Dolor sit</p>
<p>amet</p>
</div>`
.split(/([<>\s="\/]{1})/g)
.map(s=>s.trim())
.filter(Boolean)
@nirlanka
nirlanka / index.html
Last active March 29, 2020 08:38
Simple & clean web component inner-element handling
<!DOCTYPE html>
<html>
<body>
<x-one></x-one>
<script src="./x-one.js"></script>
</body>
</html>
@nirlanka
nirlanka / index.html
Created January 2, 2020 08:32
Web component experiment
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<x-one>
<p>Lorem ipsum</p>
Dolor sit amet
</x-one>
@nirlanka
nirlanka / README.md
Last active December 23, 2019 12:49
Nim on Windows (e.g.)

This is just how Nim compilation to C looks like in Windows.

nim-eg

@nirlanka
nirlanka / simple-csharp-parser.py
Last active December 9, 2019 13:42
A quick & simple high-level parser for C# code (C# code that's standard-formatted)
lines = '''
using Abc.Def;
namespace Abc.Hijk
{
public class Haha: ILaugh
{
public Haha()
{
// Constructor
@nirlanka
nirlanka / TestOne.cs
Last active April 10, 2022 21:35
A simple set of macros for C# codebases
using Abc;
public class One
{
public void Foo()
{
// macro: set ClassName // Changes the assigned default or any value in the line below
string className = default;
Console.WriteLine(className + " Foo");