Skip to content

Instantly share code, notes, and snippets.

View get_youtube_video_url.php
<?php
function get_youtube_video_url( $youtube_id )
{
$data = trim(urldecode(file_get_contents('https://youtube.com/get_video_info?video_id=' . $youtube_id)));
$d = parse_str($data, $info);
$stream_map = trim($info['url_encoded_fmt_stream_map']);
if( !$stream_map ) return false;
@halgatewood
halgatewood / convert_sbv_to_srt.php
Last active Feb 22, 2020
PHP Function to Convert SBV to SRT
View convert_sbv_to_srt.php
function convert_sbv_to_srt( $lines )
{
if( !$lines ) return "";
// BREAK LINES ON RETURN
$lines = explode("\n", $lines);
// ADD A BLANK SPACE AT THE BEGINNING,
// I USE BLANK SPACES TO DETERMINE BETWEEN THE DIFFERENT TEXT BLOCKS
@halgatewood
halgatewood / sticky.swift
Last active Jan 15, 2020
[**Requires LBTATools**] A sticky function to stick stuff using Swift to other sticky stuff. Padding approached from a web developers perspective.
View sticky.swift
// USAGES:
// SQUARE WITH A TOP PADDING OF 20
icon.stick(top: view.topAnchor, padTop: 20, width: 80, height: 80)
// PADDING TOP AND RIGHT
label.stick(top: view.topAnchor, trailing: view.trailingAnchor, padding: [20,20,0,0] )
// PADDING TOP AND BOTTOM = 20, RIGHT AND LEFT = 0
label.stick(top: view.topAnchor, trailing: view.trailingAnchor, padding: [20,0] )
@halgatewood
halgatewood / awe_darksky_raw_data.php
Last active Oct 8, 2019
WordPress function to get Dark Sky Weather data
View awe_darksky_raw_data.php
<?php
/*
Parameters:
1. Latitude
2. Longitude
3. Format: all, currently, minutely, hourly, daily
4. Dark Sky Secret Key
5. Cache time in seconds (default: 15 minutes)
*/
@halgatewood
halgatewood / awesome_weather_spanish_days_of_week.php
Created Jul 18, 2019
Translating the Days of the Week through a WordPress filter.
View awesome_weather_spanish_days_of_week.php
function awesome_weather_spanish_days_of_week()
{
return array('Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa');
}
add_filter('awesome_weather_days_of_week', 'awesome_weather_spanish_days_of_week');
@halgatewood
halgatewood / ServiceProvider.swift
Last active Apr 18, 2019
Completely Dynamic Apple TV Top Shelf using a Remote JSON file, Alamofire, Semaphore and SwiftyJSON
View ServiceProvider.swift
//
// ServiceProvider.swift
// BT Top Shelf
//
// Created by HalBook on 9/28/15.
// Copyright © 2015 HalGatewood.com. All rights reserved.
//
import Foundation
import TVServices
@halgatewood
halgatewood / awe_ajax.php
Last active Jan 14, 2019
Calling the Awesome Weather Widget through AJAX.
View awe_ajax.php
<?php
function hg_plugins_loaded()
{
if( isset($_GET['weather_widget']) )
{
echo awesome_weather_logic( array('location' => 'Boston', 'owm_city_id' => 4930956, 'use_user_location' => true, 'background_by_weather' => true ));
die;
}
}
add_filter('plugins_loaded', 'hg_plugins_loaded', 100);
@halgatewood
halgatewood / vine-thumbnails.php
Created Mar 4, 2014
Get Vine Thumbnails through the open-graph meta tags
View vine-thumbnails.php
function get_vine_thumbnail( $id )
{
$vine = file_get_contents("http://vine.co/v/{$id}");
preg_match('/property="og:image" content="(.*?)"/', $vine, $matches);
return ($matches[1]) ? $matches[1] : false;
}
echo get_vine_thumbnail('bv5ZeQjY352');
@halgatewood
halgatewood / one_on_mobile.css
Created Jul 10, 2018
Testimonial Rotator Three Little Pigs Theme – Hide two of the three testimonials on mobile devices.
View one_on_mobile.css
@media screen and (max-width: 640px)
{
.testimonial_rotator.template-threepigs .slide .testimonial_rotator_slide_inner:nth-child(2) { display: none; }
.testimonial_rotator.template-threepigs .slide .testimonial_rotator_slide_inner:nth-child(3) { display: none; }
}
@halgatewood
halgatewood / pmpro-expire-at-end-of-year.php
Created Nov 20, 2013
Expire all membership levels at the end of the year. If the user registers after October (10 variable on line 8) then they'll expire in the next year.
View pmpro-expire-at-end-of-year.php
/// EXPIRATION DATE
function my_pmpro_checkout_level($level)
{
$expiration_year = date('Y');
$current_month = date('n');
// IF OCT, NOV, DEC, EXPIRE NEXT YEAR
if($current_month >= 10) { $expiration_year++; }
$expiration_date = $expiration_year . "-12-31";