Skip to content

Instantly share code, notes, and snippets.

View farnscosnippet's full-sized avatar

FarnsCo Snippets farnscosnippet

View GitHub Profile
@farnscosnippet
farnscosnippet / UIViewExtensions.swift
Last active January 8, 2018 21:21 — forked from anonymous/UIViewExtensions.swift
SWIFT: Extend UIView to add fadeIn() and fadeOut() functions
import Foundation
import UIKit
extension UIView {
func fadeIn(_ duration: TimeInterval = 1.0, delay: TimeInterval = 0.0, completion: @escaping ((Bool) -> Void) = {(finished: Bool) -> Void in}) {
UIView.animate(withDuration: duration, delay: delay, options: UIViewAnimationOptions.curveEaseIn, animations: {
self.alpha = 1.0
}, completion: completion) }
func fadeOut(_ duration: TimeInterval = 1.0, delay: TimeInterval = 0.0, completion: @escaping (Bool) -> Void = {(finished: Bool) -> Void in}) {
@farnscosnippet
farnscosnippet / SWIFT - Generic Alert.swift
Last active January 8, 2018 21:12
SWIFT - Generic Alert
// Error Alert - Usage Example: showAlert(withTitle: "Oops", message: "Please fill in both gravity fields.", viewController: self)
func showAlert(withTitle title: String, message: String, viewController: UIViewController) {
if viewController.presentedViewController == nil { // Prevent multiple alerts at the same time
let localizedTitle = NSLocalizedString(title, comment: "")
let localizedMessage = NSLocalizedString(message, comment: "")
let alert = UIAlertController(title: localizedTitle, message: localizedMessage, preferredStyle: .alert)
let action = UIAlertAction(title: "OK", style: .default, handler: nil)
alert.addAction(action)
viewController.present(alert, animated: true, completion: nil)
@farnscosnippet
farnscosnippet / WORDPRESS - Add Excerpt Functionality to Pages.php
Last active January 8, 2018 21:13
WORDPRESS - Add Excerpt Functionality to Pages
add_action( 'init', 'my_add_excerpts_to_pages' );
function my_add_excerpts_to_pages() {
add_post_type_support( 'page', 'excerpt' );
}
@farnscosnippet
farnscosnippet / WORDPRESS - Edit Wordpress's Built-in Gallery.php
Last active January 8, 2018 21:13
WORDPRESS - Edit Wordpress's Built-in Gallery
@farnscosnippet
farnscosnippet / WORDPRESS - Remove Width and Height from Inserted Images.php
Last active January 8, 2018 21:15
WORDPRESS - Remove Width and Height from Inserted Images
add_filter( 'post_thumbnail_html', 'remove_width_attribute', 10 );
add_filter( 'image_send_to_editor', 'remove_width_attribute', 10 );
function remove_width_attribute( $html ) {
$html = preg_replace( '/(width|height)="\d*"\s/', "", $html );
return $html;
}
@farnscosnippet
farnscosnippet / WORDPRESS - Remove Width and Height from Inserted Images.js
Last active January 8, 2018 21:15
JQUERY - Horizontal and Vertical Centering
$(window).resize(function(){
$('.className').css({
position:'absolute',
left: ($(window).width() - $('.className').outerWidth())/2,
top: ($(window).height() - $('.className').outerHeight())/2
});
});
@farnscosnippet
farnscosnippet / JQUERY - Switch Content.js
Last active January 8, 2018 21:16
JQUERY - Switch Content
$(function(){
function contentSwitcher(settings){
var settings = {
contentClass : '.content',
navigationId : '#navigation'
};
//Hide all of the content except the first one on the nav
$(settings.contentClass).not(':first').hide();
$(settings.navigationId).find('li:first').addClass('active');
@farnscosnippet
farnscosnippet / WORDPRESS - Register Custom Post Type.php
Last active January 8, 2018 21:16 — forked from farnsco/gist:5125500
WORDPRESS - Register Custom Post Type
// Registering Custom Post Type for Replace_names
function custom_type_Replace_names() {
$labels = array(
'name' => 'Replace_names',
'singular_name' => 'Replace_name',
'add_new' => 'Add Replace_name',
'add_new_item' => 'Add New',
'edit_item' => 'Edit Replace_name',
'new_item' => 'New Replace_name',
'all_items' => 'All Replace_names',
@farnscosnippet
farnscosnippet / gist:7328120
Last active June 8, 2016 17:29
WORDPRESS: Use Tags as Meta Tags
<meta name="keywords" content="<?php if(is_single()) {
$metatags = get_the_tags($post->ID);
foreach ($metatags as $tagpost) {
$mymetatag = apply_filters('the_tags',$tagpost->name);
$keyword = utf8_decode($mymetatag); // Your filters...
echo $keyword.",";
}
}
?>" />
@farnscosnippet
farnscosnippet / gist:6067717
Last active June 8, 2016 17:29
CSS: Input Fields at 100%
.form-input input, .form-input textarea { display: block; width: 100%; padding: 0; border-width: 0; }
.form-input { border: 0; padding: 1vw; margin: 1vw; -moz-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px; }
.form-button { margin: 1vw; }
.form-input input { }
.form-input textarea { }
.form-box button { display: block; border: 0; padding: 1vw; width: 100%; -moz-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px; }