Skip to content

Instantly share code, notes, and snippets.

View ethanclevenger91's full-sized avatar

Ethan Clevenger ethanclevenger91

View GitHub Profile
@ethanclevenger91
ethanclevenger91 / gist:8746991
Created February 1, 2014 02:09
Dirty gist for getting Ouya input
OuyaController c = OuyaController.getControllerByPlayer(i);
if(c != null) {
if(c.getButton(OuyaController.BUTTON_A)) {
//Do whatever it is you need to do.
//This can be repeated for each button on the controller
}
float axisY = c.getAxisValue(OuyaController.AXIS_LS_Y);
if(axisY > OuyaController.STICK_DEADZONE) {
switch(i) { //'i' being the player number if you're looping through the number of players
case 0:
@ethanclevenger91
ethanclevenger91 / secure.php
Created February 27, 2014 16:58
Get secure thumbnail from Wordpress
function the_secure_post_thumbnail($size, $options) {
ob_start();
the_post_thumbnail($size, $options);
$thumbnail = ob_get_clean();
$secure_thumbnail = make_secure($thumbnail);
echo $secure_thumbnail;
}
function make_secure($url) {
$secure_url = $url;
@ethanclevenger91
ethanclevenger91 / tokens.py
Created March 2, 2014 03:22
Get tokens separated by whitespace (Python)
def readInts(file):
for line in file:
for element in line.split():
yield element
elements = readInts(file)
for element in elements
#some code here
#next(elements) advanced iterator
@ethanclevenger91
ethanclevenger91 / custom_palette.php
Created April 24, 2014 14:29
Add custom colors to Wordpress (3.9) TinyMCE color palette
function os_overwrite_color_swatch($init) {
$default_colours = '
"000000", "Black", "993300", "Burnt orange", "333300", "Dark olive", "003300", "Dark green", "003366", "Dark azure", "000080", "Navy Blue", "333399", "Indigo", "333333", "Very dark gray",
"800000", "Maroon", "FF6600", "Orange", "808000", "Olive", "008000", "Green", "008080", "Teal", "0000FF", "Blue", "666699", "Grayish blue", "808080", "Gray",
"FF0000", "Red", "FF9900", "Amber", "99CC00", "Yellow green", "339966", "Sea green", "33CCCC", "Turquoise", "3366FF", "Royal blue", "800080", "Purple", "999999", "Medium gray",
"FF00FF", "Magenta", "FFCC00", "Gold", "FFFF00", "Yellow", "00FF00", "Lime", "00FFFF", "Aqua", "00CCFF", "Sky blue", "993366", "Brown", "C0C0C0", "Silver",
"FF99CC", "Pink", "FFCC99", "Peach", "FFFF99", "Light yellow", "CCFFCC", "Pale green",
@ethanclevenger91
ethanclevenger91 / wp_custom_title_placeholder_text.php
Created July 9, 2014 15:22 — forked from isGabe/wp_custom_title_placeholder_text.php
Change placeholder text for "Enter title here" on a custom post type
<?php
/*
replacing the default "Enter title here" placeholder text in the title input box
with something more descriptive can be helpful for custom post types
place this code in your theme's functions.php or relevant file
source: http://flashingcursor.com/wordpress/change-the-enter-title-here-text-in-wordpress-963
*/
@ethanclevenger91
ethanclevenger91 / restrict_images_by_user.php
Last active August 29, 2015 14:03
Restrict media by user
function only_own_attachments($query) {
global $current_user;
if(is_admin() && !current_user_can('manage_options') && $query->query['post_type']=='attachment') {
$query->set('author', $current_user->id);
}
return;
}
add_action('pre_get_posts', 'only_own_attachments');
@ethanclevenger91
ethanclevenger91 / flexslider.js
Created July 15, 2014 13:55
Flexslider setOpts and getOpts - useful in particular for updating min and maxItems for responsive sites
slider.setOpts = function(opts) {
for (var opt in opts) {
slider.vars[opt] = opts[opt];
}
slider.setup();
}
slider.getOpts = function() {
return slider.vars;
}
@ethanclevenger91
ethanclevenger91 / wordpress_get_image_url.php
Created September 19, 2014 16:37
Never write two lines of php for an image again
function ws_get_attachment_image_url($id, $size) {
$img = wp_get_attachment_image_src($id, $size);
return $img[0];
}
@ethanclevenger91
ethanclevenger91 / functions.php
Last active November 30, 2016 19:09
All in One Event Calendar - Adding filters + functions to Twig themes For more reading on uses of functions vs. filters in Twig: http://twig.sensiolabs.org/doc/advanced.html
function add_twig_functions_and_filters() {
global $ai1ec_front_controller;
$loader = $ai1ec_front_controller->return_registry(true)->get('theme.loader');
$twig = $loader->get_twig_instance(false, true);
function foo($date) {
if(mktime() > strtotime($date->__toString)) {
return true;
}
else return false;
}
@ethanclevenger91
ethanclevenger91 / webfont.js
Last active August 29, 2015 14:09
Load webfonts asynchronously. A must if you're doing any kind of slabText. See https://github.com/typekit/webfontloader for all supported libraries
jQuery(document).ready(function($) {
//set up google fonts to load asynchronously with a callback on load
WebFontConfig = {
google: {
families:['Lato:400,700,900,400italic,900italic', 'Oswald'] //the fonts you need
},
typekit: {
id: 'xxxxxx' //supports typekit as well as others
},
active: function(familyName, fvd) { //callback when finished