Skip to content

Instantly share code, notes, and snippets.

@soggybag
soggybag / Utilities.swift
Created December 6, 2015 03:20
Convert Kelvin to F and C with a computed property
var tempC: Double {
get {
return temp - 273.15
}
}
var tempF: Double {
get {
return tempC * 9/5 + 32
}
}
@soggybag
soggybag / ViewController.swift
Last active August 10, 2016 22:11
Swift, post to FaceBook and Twitter
import UIKit
import Social
import MessageUI
class ViewController: UIViewController, MFMessageComposeViewControllerDelegate {
// MARK: Social
func postToFaceBook() {
let vc = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
@soggybag
soggybag / datepickerexample.swift
Created November 29, 2015 22:50
UITextField inputView with UIDatePicker. Opens a datepicker view with a done button
// Make a view with date picker and done button
func makeDatePickerWithDoneButton() {
let inputView = UIView(frame: CGRectMake(0,0, self.view.frame.width, 240))
var datePicker = UIDatePicker(frame: CGRect(x: 0, y: 40, width: 0, height: 0))
datePicker.datePickerMode = .Date
inputView.addSubview(datePicker)
datePicker.addTarget(self, action: Selector("handleDatePicker:"), forControlEvents: .ValueChanged)
let doneButton = UIButton(frame: CGRect(x: (self.view.frame.size.width/2) - (100/2), y: 0, width: 100, height: 50))
@soggybag
soggybag / style.css
Created November 28, 2015 07:06
Wordpress CSS for wrapping text around images in the content of posts and pages
img.alignright {
float: right; margin: 0 0 1em 1em;
}
img.alignleft {
float: left; margin: 0 1em 1em 0;
}
img.aligncenter {
display: block;
margin-left: auto;
margin-right: auto;
@soggybag
soggybag / functions.php
Created November 28, 2015 06:07
WordPress - get images in current post with short code
// Use this in the content of a post or page.
// [get_images size="thumbnail" num=3]
// The code below is added to your functions.php
function get_images_func( $atts ) {
global $post;
$num = $atts["num"];
$size = $atts["size"];
$image_html = ""; // Hello World $size";
@soggybag
soggybag / functions.php
Created November 28, 2015 05:10
WordPress, simple function fetches all images uploaded to the current post.
/*
This function fetches all of the images uloaded to the current post.
Pass in the image size, and the number of images to return.
Use this function in the loop.
*/
function get_images_in_current_post( $size="thumbnail", $num=-1 ) {
global $post;
$attachments = get_posts( array("numberposts" => $num,
"post_type" => "attachment",
"post_parent" => $post->ID,
@soggybag
soggybag / functions.php
Last active November 28, 2015 00:21
Wordpress register sidebar/widget
// Register a dynamic sidebar
// https://codex.wordpress.org/Function_Reference/register_sidebar
// The code below goes into functions.php
register_sidebar( array(
"name"=>"Footer Column 1",
"id"=>"footer-col-1",
"description"=>"Footer Column 1"
));
// Add this code to your theme to display this widget:
@soggybag
soggybag / functions.php
Created November 28, 2015 00:08
Wordpress, add jQuery to theme
// If your site plans to make use of JQuery you can have WP load JQuery with:
// Add JQuery to WP
function theme_init() {
if (!is_admin()) {
wp_enqueue_script('jquery');
}
}
theme_init();
@soggybag
soggybag / function.php
Created November 28, 2015 00:08
Wordpress register post thumbnails/Featured Image
// Activate Post thumbnails
// http://codex.wordpress.org/Post_Thumbnails
add_theme_support( "post-thumbnails" );
// To set up images sizes for use with post-thumbnails use the Simple Images Sizes Plugin:
// http://wordpress.org/extend/plugins/simple-image-sizes/
@soggybag
soggybag / functions.php
Created November 28, 2015 00:07
Wordpress Register Nav Menu.
// Register a custom menu named Main Menu
// http://codex.wordpress.org/Function_Reference/register_nav_menu
// register_nav_menu( $location, $description );
register_nav_menu( "main-menu", "Main Menu" );