Skip to content

Instantly share code, notes, and snippets.

View th3hamburgler's full-sized avatar

Jim Wardlaw th3hamburgler

View GitHub Profile
@th3hamburgler
th3hamburgler / gist:4605395
Created January 23, 2013 13:10
Wordpress: Save data from post meta box. Ignore pesky revisions.
/**
* Save custom post data meta box
*
* @access function
* @param int
* @return void
*/
function save_post($post_id) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
if (!wp_verify_nonce( $_POST['my_noncename'], MY_PLUGIN_DIRECTORY)) return;
@th3hamburgler
th3hamburgler / Flexible fixed nav
Last active December 14, 2015 01:19
jQuery function to allow for nav menu's with flexible withs and dropdowns that can 'outgrow' their parent. Usage flexible_fixed_nav('#nav > ul > li');
function flexible_fixed_nav(selector) {
var $items = $(selector);
if (!$items.length) return;
$items
.each(
function (index, parent) {
var parentWidth = $(parent).width();
var childWidth = 0;
var $childList = $(parent).find('> ul');
$childList.show();
@th3hamburgler
th3hamburgler / Useful Terminal Commands
Last active December 14, 2015 04:29
List of useful terminal commands
# list files in directory including hidden
ls -f
# Remove all files and directories (recursive removal)
rm -rf /tmp/foo
# copy the contents of file to clipboard (location: ~/.ssh/id_rsa.pub)
cat ~/.ssh/id_rsa.pub | pbcopy
# add public key to fortrabbit server (remove all new lines)
@th3hamburgler
th3hamburgler / Useful PHP code
Created April 4, 2013 23:09
List of useful php code snippits
// Convert an array into an object
$object = json_decode(json_encode($array), FALSE);
@th3hamburgler
th3hamburgler / auth-route.js
Created September 21, 2017 16:29
Ember Auth Route
import Ember from 'ember';
const {
Mixin
} = Ember;
/*
* This mixin will prevent an authorised user from
* accessing any route that does not allow their role
*
* Usage:
import Ember from 'ember';
export default Ember.Component.extend({
tagName:'form',
});
import Route from '@ember/routing/route';
import { action } from '@ember/object';
export default class FormRoute extends Route {
@action
willTransition(transition) {
if (this.controller.userHasEnteredData &&
!confirm('Are you sure you want to abandon progress?')) {
transition.abort();
} else {
@th3hamburgler
th3hamburgler / controller.js
Created June 23, 2021 17:22
will-transition-custom
import Controller from '@ember/controller';
import {action} from '@ember/object';
import {tracked} from '@glimmer/tracking';
export default class FormController extends Controller {
// Tracking
@tracked showExitModal = false;
@th3hamburgler
th3hamburgler / app.css
Created July 26, 2021 15:51
Tailwind safe area inset utilities
@layer utilities {
/* extra helper classes to account for mobile safe areas */
.p-safe {
padding: env(safe-area-inset-top) env(safe-area-inset-right)
env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.px-safe {
padding-left: env(safe-area-inset-left);
padding-right: env(safe-area-inset-right);