Skip to content

Instantly share code, notes, and snippets.

@ThunderWiring
ThunderWiring / lstm_impl1.py
Created December 26, 2021 06:43
lstm network implementation
import math
import torch
import torch.nn as nn
import torch.nn.functional as F
from data.dataset_loader import device
use_cuda = torch.cuda.is_available()
device = torch.device("cuda" if use_cuda else "cpu")
torch.backends.cudnn.benchmark = True
@ThunderWiring
ThunderWiring / jsfile.js
Created September 6, 2021 10:36
call python from js
const onLoadClick = () => {
console.log('Load click')
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", '/serve_load', false); // false for synchronous request
xmlHttp.send(null);
}
const Ytdl = require('ytdl-core');
const fs = require('fs');
const ffmpeg = require('fluent-ffmpeg');
const binaries = require('ffmpeg-binaries'); //<-- didn't use in the code, but you need to npm install it
const sanitize = require('sanitize-filename');
const path = require('path');
const express = require('express');
const bodyParser = require("body-parser");
const querystring = require('querystring');
const http = require('http');
const YoutubeVideoManager = require('./src/management/youtube_video_manager.js');
const PORT = 3000;
const app = express();
const server = app.listen(PORT, '10.0.0.3');
/**
* Controller and event handler for home.html
*/
const axios = require('axios');
window.linkTextInputClicked = () => {
document.getElementById('linkTextInput').setAttribute('placeholder', '');
}
@ThunderWiring
ThunderWiring / home.html
Last active September 14, 2018 22:02
ui for converting youtube links to mp3
<!DOCTYPE html>
<html>
<head>
<base href="/">
<title> ConvertLinks </title>
<link rel="stylesheet" type="text/css" href="/styles/home.css" />
<link rel="stylesheet" type="text/css" href="/styles/linksTable.css" />
<link rel="stylesheet" type="text/css" href="/styles/progress.css" />
<script type="text/javascript" src="/home.js"></script>
</head>
@ThunderWiring
ThunderWiring / extractAudioFromMP4.js
Created September 14, 2018 21:54
extract audio in MP3 format from an MP4 file.
/**
* @private
*/
extractAudioFromMP4_(paths) {
return new Promise((resolve, reject) => {
/*
for some reason, this did not work:
const binaries = require('ffmpeg-binaries');
const ffmpegPath = binaries.ffmpegPath(); <-- throws an exception
so i had to assign the path explicitly..
@ThunderWiring
ThunderWiring / downloadVideoAsMp4.js
Last active September 14, 2018 21:51
how to donload a video form Youtube using ytdl-core in MP4 format
/**
* Checks if the title is valid for being a file name, otherwise, removes the
* characters that invalidates it.
* A valid file name, is a string that does not contain any of the following:
* / \ : * ? " < > |
* @param {string} title
* @return {string}
* @private
*/
validateFileName_(title) {
@ThunderWiring
ThunderWiring / doInBackground.java
Last active July 14, 2018 12:16
connecting to an HTTP server and sending a POST request
HttpURLConnection urlConnection = null;
StringBuffer response = new StringBuffer();
try {
URL url = new URL(params[0]);
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestProperty("User-Agent", "Mozilla/5.0");
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);
urlConnection.setRequestProperty("Content-Type", "application/json");
urlConnection.setRequestMethod("POST");
{
"name": "httpserver",
"description": "",
"main": "server.js",
"scripts": {
"test": "start",
"start": "node server.js"
},
"author": "",
"license": "ISC",