Skip to content

Instantly share code, notes, and snippets.

View sanjarcode's full-sized avatar

Sanjar Afaq sanjarcode

View GitHub Profile
@sanjarcode
sanjarcode / script.js
Last active March 22, 2024 03:50
Scaler topics site - generate timestamps, empty note files
/**
* Raw name to simpler name (for markdown file)
*/
function nameToHypenName(name) {
name = name
.replaceAll(",", "-")
.replaceAll(" ", "-")
.replaceAll("--", "-")
.replaceAll(":", "")
.replaceAll("(", "")
@sanjarcode
sanjarcode / video2Text-sorted.py
Last active November 20, 2023 17:43
Get transcripts of tree of .mp4 videos
## Get englisgh transcripts of a tree of .mp4 files
## Cost incurred: 200 videos of ~3 minutes each => around ~$5
## Other params: ~200 API calls; total ~40,000 seconds
## Cost estimate as per pricing chart: 683 min * 0.006 = ~4.098
## Ignores non mp4 files
## Adds .mp3 files for each file, and then calls Whisper API and stores the .txt
## Nothing is deleted
## Resumable
@sanjarcode
sanjarcode / README.md
Last active November 7, 2023 04:36
VLC Playlist (XSPF) generator from file tree

Why

I had some videos (actually a folder that one more level of folders and finally video files).

I wanted to generate .xspf files for the whole folder, where each subfolder became a playlist. i.e I wanted to generate multiple files (one corresponding to each folder) XSPF files are used by VLC to store a string of videos. You can open the file with VLC and it will play them as a playlist, allowing prev/next video.

How to use

  • tree.js is used for generating the tree structure of the root folder, as an object.
@sanjarcode
sanjarcode / commands.md
Last active May 27, 2023 16:23
Gnome Terminal (the default Ubuntu terminal) tips, quirks

Open a new terminal at given directory

gnome-terminal --working-directory some_path

Note:

  1. this option works only if used before other options, so keep it before.
  2. It doesn't work with relative paths, i.e. .. won't work. This could be solved - StackOverflow

Open a new terminal (as a tab)

@sanjarcode
sanjarcode / printPDF.js
Last active April 9, 2023 20:44
ChatGPT tips n tricks
/* Instructions
1. Setup print preferences: Press Ctrl + P on any website. Enable headers + footers, background graphics, and set margin to custom (set all to 0, except the top, set it to 0.5mm using the mouse)
2. Copy and paste this file into the console
*/
// copied from https://github.com/liady/ChatGPT-pdf
class Elements {
constructor() {
this.init();
}
@sanjarcode
sanjarcode / terminal.cjs
Last active January 1, 2024 08:19
Node.js stuff
const util = require("util");
const promisifiedExec = util.promisify(require("child_process").exec);
async function runCommand(command) {
let retVal;
try {
const { stdout, stderr } = await promisifiedExec(command);
retVal = [stderr || null, stdout];
} catch (e) {
retVal = [{ code: e.code, message: e.message }, e.stdout];
@sanjarcode
sanjarcode / rn.md
Last active July 13, 2023 22:14
📱React Native setup, ADB wirless

Steps (to set up an existing React Native app)

  1. Install react-native-cli globally, by running npm install -g react-native-cli.
  2. Clone the repo. Do npm install inside it.
  3. Connect phone (real) to the computer - by enabling USB debgugging/Wirelsss debugging through the "Developer Options" ((may need to enable them first, by clicking "Build number" repeatedly)). Accept permissions.
  4. Make sure the phone connected by running adb devices in the terminal. A device should be added, in the success case.
  5. Run react-native start, press "a" for Android.
  6. "r" when the procees seems to have stopped. Keep pressing this if something gets stuck.
  7. The app should now be installed and running on the phone.
  8. Editing files should update the app now, automatically
<!DOCTYPE html>
<html>
<head>
<title>Record Audio</title>
<style>
#audio-list {
list-style: none;
}
</style>
</head>
@sanjarcode
sanjarcode / app.js
Last active August 30, 2023 05:58
Download Udemy caption links, other Udemy setup
/*
Local server (assumes Node.js is installed)
Purpose - the console code sends data to this (local) server, so
the transcript files can be saved locally.
Add this file to a folder, then run the following command in the folder
`npm init -y && npm install express body-parser cors && node app.js`
*/
const express = require("express");
@sanjarcode
sanjarcode / requests.md
Last active September 3, 2023 14:14
HTTP requests in variouslanguages/runtimes

HTTP Requests and responses in various languages

JavaScript

1. fetch API

// GET request
fetch('https://example.com/data')
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error(error))