Skip to content

Instantly share code, notes, and snippets.

showBrowserSize () {
const size = {
width: window.innerWidth || document.body.clientWidth,
height: window.innerHeight || document.body.clientHeight
};
console.log('Width * Height', size);
}
function guid(len) {
var buf = [],
chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789',
charlen = chars.length,
length = len || 32;
for (var i = 0; i < length; i++) {
buf[i] = chars.charAt(Math.floor(Math.random() * charlen));
}
var checkedValues = $('input[name=checkedlist]:checked').map(function () {
return $(this).val();
}).get();
var fibonacci_series = (n) =>
{
if (n===1)
{
return [0, 1];
}
else
{
var s = fibonacci_series(n - 1);
s.push(s[s.length - 1] + s[s.length - 2]);
var addSix = createBase(6);
console.log(addSix(10)); // returns 16
console.log(addSix(21)); // returns 27
function createBase(i){
return (y) => {
return y + i;
};
}
@waimyokyaw
waimyokyaw / arrayreduce.js
Created March 17, 2018 08:23
Sum elements of array using javascript
const array1 = [1, 2, 3, 4];
const reducer = (accumulator, currentValue) => accumulator + currentValue;
// 1 + 2 + 3 + 4
console.log(array1.reduce(reducer));
// expected output: 10
// 5 + 1 + 2 + 3 + 4
console.log(array1.reduce(reducer, 5));
// expected output: 15
var sum = [1, 2, 3].reduce((a, b) => a + b, 0);
console.log(sum); // 6
@waimyokyaw
waimyokyaw / html5-video-streamer.js
Created December 28, 2015 11:59 — forked from paolorossi/html5-video-streamer.js
Node.js HTML5 video streamer
/*
* Inspired by: http://stackoverflow.com/questions/4360060/video-streaming-with-html-5-via-node-js
*/
var http = require('http'),
fs = require('fs'),
util = require('util');
http.createServer(function (req, res) {
var path = 'video.mp4';
@waimyokyaw
waimyokyaw / livestream
Created December 28, 2015 11:56 — forked from deandob/livestream
Node.JS function to remux mp4/h.264 video from an IP camera to a HTML5 video tag using FFMPEG
// Live video stream management for HTML5 video. Uses FFMPEG to connect to H.264 camera stream,
// Camera stream is remuxed to a MP4 stream for HTML5 video compatibility and segments are recorded for later playback
var liveStream = function (req, resp) { // handle each client request by instantiating a new FFMPEG instance
// For live streaming, create a fragmented MP4 file with empty moov (no seeking possible).
var reqUrl = url.parse(req.url, true)
var cameraName = typeof reqUrl.pathname === "string" ? reqUrl.pathname.substring(1) : undefined;
if (cameraName) {
try {
cameraName = decodeURIComponent(cameraName);