Skip to content

Instantly share code, notes, and snippets.

Tiffany Brown webinista

Block or report user

Report or block webinista

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@webinista
webinista / mode.php
Created Jun 22, 2019
find the mode of an array using PHP
View mode.php
function array_mode($$arr) {
/*
Count the frequency of occurrence of values in the array.
This will make each duration value into a key, with its frequency as the
value
*/
$counts = array_count_values($$arr);
/*
Get all of the count values and find the unique values, then sort them,
@webinista
webinista / isNumeric.js
Created May 29, 2019
isNumeric function for JavaScript
View isNumeric.js
// Simple way to check whether a particular value is numeric. Saving it here so that I don't have to solve it twice.
const isNumeric = (value) => {
return !Number.isNaN(parseFloat(value,10));
}
@webinista
webinista / flatten2d.php
Created Apr 12, 2019
Flatten a two-dimensional PHP array
View flatten2d.php
<?php
function flatten2d($multi_dimensional_array) {
$flattened = [];
$flatten = function($value, $index) {
global $flattened;
array_push($flattened, $value);
};
array_walk_recursive($multi_dimensional_array, $flatten);
return $flattened;
@webinista
webinista / iso8601ToSeconds.php
Created Dec 13, 2018
PHP: Convert an ISO 8601 duration / date (Such as the one YouTube uses) interval to seconds
View iso8601ToSeconds.php
<?php
function iso8601ToSeconds($input) {
$duration = new DateInterval($input);
$hours_to_seconds = $duration->h * 60 * 60;
$minutes_to_seconds = $duration->i * 60;
$seconds = $duration->s;
return $hours_to_seconds + $minutes_to_seconds + $seconds;
}
@webinista
webinista / youtubeduration.php
Created Dec 7, 2018
Make YouTube API duration readable using PHP
View youtubeduration.php
/*
PHP function for converting an ISO8601 duration (the kind used by YouTube's API)
to something more readable.
*/
make_readable_duration($duration)
{
$duration = new DateInterval($duration);
return $duration->format('%H:%I:%S');
}
@webinista
webinista / HowToFixPycURLErrorMacOS.md
Last active Oct 17, 2019
PycURL error: ConfigurationError: Curl is configured to use SSL, but we have not been able to determine which SSL backend it is using. Please see PycURL documentation for how to specify the SSL backend manually.
View HowToFixPycURLErrorMacOS.md

Partly pulled from the comments here: https://github.com/pycurl/pycurl/issues/526

May also be a fix for this error:

ImportError: pycurl: libcurl link-time ssl backend (none/other) is different from compile-time ssl backend (openssl)

If you try to install PycURL and receive this error:

@webinista
webinista / DialogModal.jsx
Last active Oct 4, 2018
A work-in-progress React component for modals. Uses the <dialog> element.
View DialogModal.jsx
/*
DialogModal. Depends on the presence of dialog-polyfill.js
and dialog-polyfill.css with the page in non-Chrome browsers.
https://github.com/GoogleChrome/dialog-polyfill
MIT licensed.
*/
import React from 'react';
import PropTypes from 'prop-types';
View Using Python 3 on macOS
Writing this as a note to myself :-)
Install a Python 3 binary from python.org, then add the path to that Python binary
(e.g. /Library/Frameworks/Python.framework/Versions/3.6/bin) to your /etc/paths file.
@webinista
webinista / ucfirst.js
Created Jul 4, 2018
Uppercase the first letter of a word with JavaScript
View ucfirst.js
function ucfirst(word) {
const wordarray = word.split('');
wordarray[0] = wordarray[0].toUpperCase();
return wordarray.join('');
}
@webinista
webinista / range.js
Last active Apr 13, 2018
Get a range of numbers that includes the min and max values. Integers only.
View range.js
const range = (min, max) => {
const diff = max - min;
const spread = [...Array(diff).keys()].map(n => {return n + min});
spread.push(max);
return spread;
}
// Example usage
range(2,100);
You can’t perform that action at this time.