Skip to content

Instantly share code, notes, and snippets.

@jboesch
jboesch / wordpress_extra_security.php
Created November 15, 2011 18:03
An added layer to security for accessing /wp-admin on your WordPress site
<?
// See if we're trying to access the wp-admin area, prompt for 2nd layer of security
// Once this authenticates, you'll be able to login again at the main /wp-admin area.
// This is to prevent bots poking at the WordPress login area. You can do other things to help
// secure your WordPress site, this is just one of them. See http://codex.wordpress.org/Hardening_WordPress
// USAGE: Drop the code below in wp-config.php
if(stristr($_SERVER['PHP_SELF'], 'wp-login.php'))
{
$user = 'someuser';
@jboesch
jboesch / gist:1299783
Created October 19, 2011 21:44
Drag/drop for fullCalendar on iPad
/********************************
* UPDATE: I have crated a plugin to do this: https://github.com/jboesch/jQuery-fullCalendar-iPad-drag-drop/
*********************************/
/*These are the brief steps that it takes to get fullCalendar (http://arshaw.com/fullcalendar/) up and running with drag/drop support on the iPad. This assumes you already have fullCalendar setup.*/
//1. Include a copy of jQuery touch punch in your project, you can find it here: https://github.com/furf/jquery-ui-touch-punch
//2. Go into jquery-touch-punch.js and right after this line (around line 57 - mouseProto._mouseDown = function (event) {) add this: this._mouseDownEvent = event;
//3. Add this function somewhere in your global.js file or wherever you want:
@jboesch
jboesch / rm_txt_node.js
Created July 8, 2011 20:01
Remove a text node
// This will remove the text "Search:"
$('#thing').contents().each(function(){
if(this.nodeType == 3){
$(this).remove();
}
});
<div id="thing">
Search:
<input type="text" />
@jboesch
jboesch / php_loop_dates.php
Created June 30, 2011 16:35
Loop over dates in PHP 5.3+
<?
// Looping over date ranges, requires PHP 5.3+
$begin = new DateTime('2011-01-05');
$end = new DateTime('2011-01-10');
$interval = DateInterval::createFromDateString('1 day');
$period = new DatePeriod($begin, $interval, $end);
$dates = array();
foreach($period as $dt)
@jboesch
jboesch / fullcalendar_getdate_by_td_cell.js
Created May 20, 2011 17:09
Get the date by clicking a month td cell in $.fullCalendar (http://arshaw.com/fullcalendar/)
/**
* Get the date we just clicked on (td cell)
*
* @param {Object} $td The jQuery td element
*/
var getDateFromTdCell = function($td)
{
var self = this;
// Want to turn that string into a number.. BUT CANNOT FIND A jQUERY PLUGIN THAT'LL DO IT?!
// Boy are you in luck.
$.stringToNumber = function(num){
return parseInt(num);
};
// Usage $.stringToNumber('5') -> 5
@jboesch
jboesch / scrollbar_controller.js
Created May 10, 2011 14:59
One scrollbar to scroll them all
// Hide scrollbars on the calendar day instances (jQuery fullCalendar plugin: http://arshaw.com/fullcalendar/)
var $scrollbox = $('.cal-item .fc-view-agendaDay.fc-agenda > div > div')
// Hide the current scrollbars on a bunch of calendar divs (side-by-side)
.css('overflow-y', 'hidden')
// Since they're hidden and we're using another scrollbar to control
// them, we need to bind mousewheel to make sure that we can still
// mousewheel over the hidden boxes (jQuery mousewheel plugin)
.mousewheel(function(event, delta, deltaX, deltaY){
// #scrolly is my new scrollbar to control them
@jboesch
jboesch / ecmascript.next_modules.js
Created April 23, 2011 17:37
ECMAScript.Next Modules
// Current way of doing modules, you have to expose it via a return statement to make it public.
var Thing = (function(){
function getStuff(){ alert('Stuff retrieved!');
return {
getStuff: getStuff
}
})();
// ECMAScript.Next proposal... adding "export" will make functions public.
// I wonder why they didn't just call it "public function".. export sounds like I'm downloading or something. Meh.
@jboesch
jboesch / AjaxForm Jasmine Test.js
Created April 20, 2011 22:33
RequireJS, BackboneJS and testing with Jasmine. Whew.
describe("AjaxForm", function() {
// Local vars for manipulation
var $form = null,
_requirejs_loaded = false,
found_errors = false,
submitted_successfully = false,
AjaxFormInstance = null,
RequireJSViews = {
AjaxFormView: null
boxSizing = rinputbutton.test( elem.nodeName ) &&
( curCSS( elem, "-moz-box-sizing" ) === "border-box" ||
curCSS( elem, "box-sizing" ) === "border-box" )