Skip to content

Instantly share code, notes, and snippets.

View kodie's full-sized avatar
💻
#doworkson

Kodie Grantham kodie

💻
#doworkson
View GitHub Profile
@kodie
kodie / responsiveYoutube.js
Created April 12, 2016 15:10
Make YouTube video embeds responsive
var responsiveVideos = $('iframe[src*="//www.youtube.com"]');
responsiveVideos.each(function(){
$(this)
.data('aspectRatio', $(this).height() / $(this).width())
.width('100%')
.removeAttr('height');
});
$(window).resize(function(){
@kodie
kodie / getVideoMeta.js
Last active August 5, 2016 21:30
Fetches metadata for HTML5 videos.
function getVideoMeta(videoUrl, metaType, callback) {
var video = document.createElement('video');
video.preload = 'metadata';
video.src = videoUrl;
video.addEventListener('loadedmetadata', function() {
callback(null, video[metaType]);
});
video.addEventListener('error', function(error) {
callback(error, video);
});
@kodie
kodie / 38835949-sample.js
Created August 10, 2016 16:50 — forked from akanix42/38835949-sample.js
There are a variety of ways to do that; I'd recommend using "classes" (prototypal inheritance) as I think it enhances readability. This sample assumes you are using a version of Meteor new enough to use the ecmascript package (you can do it without ecmascript, it's just not as readable). I'm going to write the example for Meteor 1.3+.
/**
* First, add `api.use('ecmascript');` to your package.js files.
* packages/project:modules-core/package.js:
**/
Package.describe({
name: 'project:modules-core',
summary: 'Core package for Modules.',
version: '1.0.0'
});
@kodie
kodie / arraySearch.sh
Created August 25, 2016 16:18
Searches array for a string and returns it's position/key if found.
function arraySearch {
local i
local output
local a=("$@")
local last_idx=$((${#a[@]} - 1))
local b=${a[last_idx]}
unset a[last_idx]
for i in "${!a[@]}" ; do
if [ "${a[$i]}" == "$b" ]; then
@kodie
kodie / txtStyle.sh
Created August 25, 2016 16:51
Functions to display styled text
function txtStyle {
local color
local background
local style
local output
case "$1" in
"black") color="30" ;;
"red") color="31" ;;
"green") color="32" ;;
@kodie
kodie / csv_to_array.php
Last active September 16, 2016 14:51
Pulls .CSV file contents into an associative array.
<?php
function csv_to_array($file, $line_length="0", $delimiter=",", $enclosure="\"", $escape="\\") {
$csv = array();
$keys = array();
$row = 0;
if (($handle = fopen($file, "r")) !== FALSE) {
while (($data = fgetcsv($handle, $line_length, $delimiter, $enclosure, $escape)) !== FALSE) {
$num = count($data);
for ($c=0; $c < $num; $c++) {
if ($row == 0) {
@kodie
kodie / meteorSettings.js
Created February 8, 2017 17:47
Meteor template helper to access public settings
Template.registerHelper('meteorSettings', function(settings) {
var setting = Meteor.settings.public;
if (settings) {
var eachSetting = settings.split('.');
for (i = 0; i < eachSetting.length; i++) {
setting = setting[eachSetting[i]];
}
}
return setting;
});
@kodie
kodie / change_url_param.php
Last active June 20, 2017 19:14
Add, change or remove a parameter from a URL.
<?php
function change_url_param($params = null, $url = null) {
if (!$url) { $url = '//' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; }
$p = parse_url($url);
if (isset($p['scheme'])) { $s = $p['scheme'] . '://'; } else { $s = '//'; }
if (substr($url, 0, 2) == '//') { $s = '//'; }
if (isset($p['host'])) { $h = $p['host']; } else { $h = ''; }
if (isset($p['path'])) { $t = $p['path']; } else { $t = '/'; }
if (isset($p['query'])) { parse_str($p['query'], $q); } else { $q = array(); }
if (isset($p['fragment'])) { $f = '#' . $p['fragment']; } else { $f = ''; }
@kodie
kodie / matches.js
Created July 24, 2017 17:20
A recursive, case-insensitive, keyword matcher.
function matches(str, kw) {
var m = [];
if (kw.constructor !== Array) { kw = [kw]; }
for (var i = 0; i < kw.length; i++) {
var f = str.match(new RegExp(kw[i], 'gi'));
if (f) { m = m.concat(f); }
}
return m;
@kodie
kodie / convertHebrewDate.js
Last active July 27, 2017 22:07
Convert hebrew dates
/*!
Original code found here: http://www.dafaweek.com/HebCal/HebCalSampleSource.php
Simplifed by Kodie Grantham - http://kodieg.com
Hebrew Months:
1 - Tishrei
2 - Cheshvan
3 - Kislev
4 - Teves
5 - Shevat