Skip to content

Instantly share code, notes, and snippets.

View tabvn's full-sized avatar

Toan tabvn

  • Danang, Vietnam
View GitHub Profile
@tabvn
tabvn / email-validation.js
Created December 3, 2017 05:03
ES6 Email Regex Validation
const isEmail = (email = null) => {
const regex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return regex.test(email);
}
const { exec } = require('child_process');
const youtube_stream_key = '';
const frame_rate = 30;
const streamCommand = `/usr/local/bin/ffmpeg -f avfoundation -i "0:0" -deinterlace -vcodec libx264 -pix_fmt yuv420p -preset medium -r 30 -g 60 -b:v 2500k -acodec libmp3lame -ar 44100 -threads 6 -qscale 3 -b:a 712000 -bufsize 512k -f flv rtmp://a.rtmp.youtube.com/live2/${youtube_stream_key}`
const ls = exec(streamCommand);
ls.stderr.on('data', (data) => {
console.log(`Streaming data: ${data}`);
});
ls.on('close', (code) => {
conf nginx with rtmp module
#### Command
brew tap homebrew/nginx
brew options nginx-full
brew info nginx-full
brew install nginx-full --with-rtmp-module --with-debug
/usr/local/bin/ffmpeg -f avfoundation -r 30 -i "0:0" -deinterlace -vcodec libx264 -pix_fmt yuv420p -preset medium -g 60 -b:v 2500k -acodec libmp3lame -ar 44100 -threads 6 -qscale 3 -b:a 712000 -bufsize 512k -f flv rtmp://localhost/show/stream
Nginx.conf
worker_processes auto;
events {
worker_connections 1024;
}
## HLS server streaming
rtmp {
from twisted.internet.protocol import ReconnectingClientFactory
from autobahn.twisted.websocket import WebSocketClientProtocol, WebSocketClientFactory
import json
import subprocess
server = "127.0.0.1" # Server IP Address or domain eg: tabvn.com
port = 3001 # Server Port
streaming_process = None
@tabvn
tabvn / websocket.js
Created June 10, 2018 03:43
uWs websocket as Client for server (Node.js)
import WebSocket from 'uws'
import { config } from './config'
import _ from 'lodash'
export default class WebSocketClient {
constructor (options) {
this.connect = this.connect.bind(this)
this.reconnect = this.reconnect.bind(this)
@tabvn
tabvn / hinh_hop.cpp
Last active September 16, 2018 12:49
bai tap c++ can ban, hinh hop
//
// main.cpp
// homework
//
// Created by Toan on 9/16/18.
// Copyright © 2018 Toan. All rights reserved.
//
#include <iostream>
#include "math.h"
@tabvn
tabvn / tim_ma_tran_nghich_dao_cap3.cpp
Last active September 18, 2018 05:31
tim_ma_tran_nghich_dao_cap3.cpp
//
// main.cpp
// homework
//
// Created by Toan on 9/18/18.
// Copyright © 2018 Toan. All rights reserved.
//
#include <iostream>
using namespace std;
//
// main.cpp
// homework
//
// Created by Toan on 9/18/18.
// Copyright © 2018 Toan. All rights reserved.
//
#include <iostream>
using namespace std;