Skip to content

Instantly share code, notes, and snippets.

@jboesch
jboesch / gravatar_import.php
Created March 17, 2012 06:42
Import gravatar images to store on your local server
<?php
set_time_limit(120);
$domains = ClassRegistry::init('Domain')->find('all', array(
'conditions' => array(
'url' => $_GET['domain']
//'paid_recurring' => 1
),
'recursive' => -1
));
@jboesch
jboesch / gist:1821407
Created February 13, 2012 23:24
cakephp 2.0 plugin re-routing problems
<?
// routes.php
Router::connect('/animals/:action/*', array(
'plugin' => 'big',
'controller' => 'BigAnimalsController'
));
/*
* Now I navigate to /animals and I look at my action attribute on my <form> tag
* How come my $form->create(array('controller' => 'animals')); call still outputs:
@jboesch
jboesch / gist:1586341
Created January 10, 2012 01:57
Auth problems with CakePHP 2.0 - migrating from 1.3 - 2.0
/****************************************************************
* AppController.php
*****************************************************************/
<?
/**
* Most application-wide logic should be handled here
*
*/
class AppController extends Controller
{
@jboesch
jboesch / gist:1585571
Created January 9, 2012 23:18
cakephp 2.0 auth problems
<?
// i login successfully with if($this->Auth->login()) but as soon as I call $this->redirect($this->Auth->redirect());
// it boots me back to the login screen.
public function beforeFilter()
{
//Deny access to everything by default, let isAuthorized decide to let them in
$this->Auth->deny("*");
// Set up auth error messages here, where they can actually be translated
@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 / 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)
// 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.