Skip to content

Instantly share code, notes, and snippets.

View halgatewood's full-sized avatar

Hal Gatewood halgatewood

View GitHub Profile
@halgatewood
halgatewood / rotate_buttons.swift
Last active July 24, 2022 15:28
Swift: Rotate Buttons Based On Device Orientation
override func viewDidLoad()
{
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(rotate), name: NSNotification.Name.UIDeviceOrientationDidChange, object: nil)
}
@objc func rotate()
{
var rotation_angle: CGFloat = 0
<?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 February 22, 2020 15:39
PHP Function to Convert SBV to SRT
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 January 15, 2020 16:54
[**Requires LBTATools**] A sticky function to stick stuff using Swift to other sticky stuff. Padding approached from a web developers perspective.
// 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 October 8, 2019 01:43
WordPress function to get Dark Sky Weather data
<?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 July 18, 2019 05:41
Translating the Days of the Week through a WordPress filter.
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 April 18, 2019 12:07
Completely Dynamic Apple TV Top Shelf using a Remote JSON file, Alamofire, Semaphore and SwiftyJSON
//
// 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 January 14, 2019 21:38
Calling the Awesome Weather Widget through AJAX.
<?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 March 4, 2014 17:38
Get Vine Thumbnails through the open-graph meta tags
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 July 10, 2018 21:22
Testimonial Rotator Three Little Pigs Theme – Hide two of the three testimonials on mobile devices.
@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; }
}