Skip to content

Instantly share code, notes, and snippets.

@bcls
bcls / convert_milliseconds_to_formatted_time.php
Last active August 10, 2023 12:10
convert milliseconds to formatted time #php
/**
* Converts milliseconds to formatted time or seconds.
* @param int [$ms] The length of the media asset in milliseconds
* @param bool [$seconds] Whether to return only seconds
* @return mixed The formatted length or total seconds of the media asset
*/
function convertTime($ms, $seconds = false)
{
$total_seconds = ($ms / 1000);
@bcls
bcls / PHP_PUT_file.php
Last active May 28, 2023 20:10
PHP PUT file #php
$file = fopen($file_on_dir_not_url, "rb");
$curl = curl_init();
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_BINARYTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_PUT, true);
@bcls
bcls / getCheckedBoxValues.js
Created December 23, 2017 18:58
Get Array of Checked checkbox Values #javascript
// collection of checkboxes obtained by getElementsByName()
/**
* get array of values for checked boxes in a collection
* @param {htmlElementCollection} checkBoxCollection collection of checkbox elements
* @return {Array} array of the values of the checked boxes
*/
function getCheckedBoxValues(checkBoxCollection) {
var checkedValues = [],
i,
@bcls
bcls / cms-search.html
Last active November 21, 2017 17:55
CMS search by date (html part) #html #javascript
<!-- HTML part -->
<!-- date picker styles -->
<link rel="stylesheet" href="https://learning-services-media.brightcove.com/doc-assets/js/rome/rome.min.css" />
<table class="bcls-table">
<caption>Limit search by dates:</caption>
<tbody>
<tr>
<td>Date type</td>
@bcls
bcls / cms-search.js
Created November 21, 2017 17:54
CMS API search (javascript part) #html #javascript
// JavaScript part
var BCLS = ( function (window, document, rome) {
var dateRangeType = document.getElementById('dateRangeType'),
fromDate = document.getElementById('fromDate'),
toDate = document.getElementById('toDate'),
dateTypeValue,
fromDateValue,
toDateValue,
searchString;
@bcls
bcls / combineArrays.js
Created November 16, 2017 21:24
Append array to another array #javascript
/**
* Add one array to another
* @param {Array} a The array to add another array to
* @param {Array} b The array to add to array a
* @return {Array} Array a with b appended to it
*/
function combineArrays(a, b) {
a.push.apply(a, b);
return a;
}
@bcls
bcls / restapi.js
Last active November 13, 2017 16:19
REST API app stem #javascript #codesamples
/**
* createRequest sets up requests, send them to makeRequest(), and handles responses
* @param {string} type the request type
*/
function createRequest(type) {
var options = {},
requestBody = {},
proxyURL = 'https:/solutions.brightcove.com/bcls/bcls-proxy/bcls-proxy.php'
ipBaseURL = 'https://ingestion.api.brightcove.com/v1/accounts/' + account.value,
diBaseURL = 'https://ingest.api.brightcove.com/v1/accounts/' + account.value,
@bcls
bcls / seconds2time.js
Created November 4, 2017 15:25
seconds to hh:mm:ss
/**
* utility to extract h/m/s from seconds
* @param {number} secs - seconds to convert to hh:mm:ss
* @returns {object} object with members h (hours), m (minutes), s (seconds)
*/
function secondsToTime(secs) {
var hours = Math.floor(secs / (60 * 60)),
divisor_for_minutes = secs % (60 * 60),
minutes = Math.floor(divisor_for_minutes / 60),
divisor_for_seconds = divisor_for_minutes % 60,
@bcls
bcls / getURLParam.js
Created November 3, 2017 19:01
get value for URL param #javascript
/**
* gets value of a URL param on current page URL if exists
* @param {string} name the param you want the value of
* @return {string} result value of param if exists or ""
*/
function getURLparam(name) {
var regex,
results;
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
regex = new RegExp("[\\?&]" + name + "=([^&#]*)");
@bcls
bcls / in-array.js
Created November 2, 2017 20:46
is item in array #javascript
/**
* determines whether specified item is in an array
*
* @param {array} array to check
* @param {string} item to check for
* @return {boolean} true if item is in the array, else false
*/
function arrayContains(arr, item) {
var i,
iMax = arr.length;