Skip to content

Instantly share code, notes, and snippets.

View tyohan's full-sized avatar

Yohan Totting tyohan

View GitHub Profile
@tyohan
tyohan / gist:e6996a8f0bf9bc6a5868af7ab10a0343
Created September 29, 2021 02:36
ffmpeg dash low latency experiment
ffmpeg -f flv -listen 1 -i rtmp://127.0.0.1:19350/live/app \
-c:v libx264 -b:v:0 5000k -b:v:1 2000k -crf 23 -g 120 -format_options "movflags=cmaf" -adaptation_sets "id=0,streams=v id=1,streams=a" \
-frag_type duration -keyint_min 120 -maxrate 1M -bufsize 2M -force_key_frames "expr:gte(t,n_forced*4)" \
-pix_fmt yuv420p -profile:v baseline -an -s 1280x720 \
-ldash 1 -streaming 1 -use_template 1 -use_timeline 0 -seg_duration 4 -frag_duration 1 -frag_type duration \
-utc_timing_url "http://time.akamai.com/?iso%26ms" -window_size 15 -extra_window_size 15 -remove_at_exit 1 -f dash ./ldash/1.mpd
@tyohan
tyohan / firestore-module.js
Last active May 13, 2021 16:42
How to load the Firebase Firestore with ES6 module without using the bundler tool. I use it to lazy load the Firebase Firebase in my vanilla web component. To use it you just need to import and construct an instance, then call load() and handle the promise resolve.
export default class FirestoreModule{
constructor(apiKey,authDomain,databaseURL,projectId){
this.promise=false;
this.db=null;
this.apiKey=apiKey;
this.authDomain=authDomain;
this.databaseURL=databaseURL;
this.projectId=projectId;
}
<?php
function lazyloadImages($html) {
$matches = array();
preg_match_all( '/<img[\s\r\n]+.*?>/is', $html, $matches );
$search = array();
$replace = array();
foreach ( $matches[0] as $imgHTML ) {
@tyohan
tyohan / lazyload.js
Created November 14, 2017 10:23
Lazy load the images with interaction observer API
const config = {
// If the image gets within 50px in the Y axis, start the download.
rootMargin: '50px 0px',
threshold: 0.01
};
const observer = new IntersectionObserver(onIntersection, config);
function loadImage(el){
el.className = el.className.replace( /(?:^|\s)lazy-hidden(?!\S)/g , '' );
@tyohan
tyohan / functions.php
Created November 14, 2017 07:57
Functions to make scripts async and defer on WordPress Seventeen Theme
function add_defer_attribute($tag, $handle) {
// add script handles to the array below
$scripts_to_defer = array(
'html5',
'jquery',
'jquery-migrate',
'wp-embed',
'twentyseventeen-skip-link-focus-fix',
'jquery-scrollto',
'twentyseventeen-global',
@tyohan
tyohan / removeduplicatevertice.js
Last active April 16, 2023 23:01
Remove duplicate vertice on mongodb geojson collection
#!/usr/bin/env node
var path=require('path');
var fs = require('fs');
if(process.argv.length<3)
throw new Error('You\'re not passing the geojson file');
var file=process.argv[2];
var gjFile=fs.statSync(file);
if(!gjFile.isFile())
throw new Error('File not found');