Skip to content

Instantly share code, notes, and snippets.

View dbernar1's full-sized avatar

Dan Bernardic dbernar1

View GitHub Profile
@dbernar1
dbernar1 / application.html.haml_spec.rb
Created November 7, 2011 03:45
specs for testing content of the account menu on a website
it "displays create account and sign in links, and doesn't display sing out link to non-logged in users" do
render
rendered.should have_selector( '.sign-in' ) do |account_menu|
account_menu.should contain 'Create Account'
account_menu.should contain 'Sign In'
account_menu.should_not contain 'Sign Out'
end
end
it "displays sign out link, and doesn't display create account and sign in links to logged in users" do
@dbernar1
dbernar1 / gist:1356342
Created November 10, 2011 21:46
Why I like the opening brace to be on the next line
function do_something() {
do_it();
do_something_else();
}
function do_something_else()
{
do_it();
}
@dbernar1
dbernar1 / gist:1371129
Created November 16, 2011 19:48
Checking out WordPress 3.2.1 as a git submodule
git submodule add git://github.com/markjaquith/WordPress.git core
cd core
git checkout 3.2.1
cd ..
git add . -A
git commit -m 'Checked out core at 3.2.1'
@dbernar1
dbernar1 / gist:1569735
Created January 6, 2012 08:38
My Best Gist Yet (a php-rspec proof of concept)
it should blah blah
$someshit = new Shit();
$someshit.shit.should be_new
end
@dbernar1
dbernar1 / gist:1645467
Created January 20, 2012 05:16
Refactoring of get_pages()
/**
* Retrieve a list of pages.
*
* The defaults that can be overridden are the following: 'child_of',
* 'sort_order', 'sort_column', 'post_title', 'hierarchical', 'exclude',
* 'include', 'meta_key', 'meta_value','authors', 'number', and 'offset'.
*
* @since 1.5.0
* @uses $wpdb
@dbernar1
dbernar1 / gist:4133966
Created November 23, 2012 04:09
Setting some options through enabling a theme. In this case, comments and pingbacks are disabled by default in posts/pages, and timezone is Winnipeg.
add_action( 'after_switch_theme', 'dbfds_disable_comments' );
function dbfds_disable_comments( $theme_name ) {
update_option( 'default_comment_status', 'closed' );
update_option( 'default_ping_status', 'closed' );
update_option( 'timezone_string', 'America/Winnipeg' );
}
@dbernar1
dbernar1 / frontend
Last active December 11, 2015 00:19 — forked from deadlyhifi/frontend
// button to load the content
<a class="button showloadme"><span class="finger">☞</span> Who&rsquo;s this guy?</a>
// css to momentarily display loader image
.ajaxloader { width: 32px; height: 32px; background: url(ajax-loader.gif) no-repeat; margin: auto; }
@dbernar1
dbernar1 / frontend.html
Last active December 11, 2015 00:28 — forked from asuh/frontend.php
// .content contains content
<div class="content"></div>
<script>
$(document).ready(function() {
// ajax to fetch the slider data.
$.ajax({
type: 'POST',
url: '<?php echo admin_url("admin-ajax.php"); ?>',
data: { action: "front_page_slider" },
@dbernar1
dbernar1 / gist:5119400
Last active December 14, 2015 16:59
A way to provide a test double for WordPress globals, like $wpdb, in order to unit test functions that use the global.
<?php
class TestDouble {
private $stubs;
public function stub( $method_name, $return_value ) {
$this->stubs[ $method_name ] = $return_value;
}
public function __call( $method_name, $args ) {
@dbernar1
dbernar1 / gist:5330413
Last active December 15, 2015 22:10
Some options in terms of making code self-documenting
<?php
// SHORTEST VERSION
if ( in_array( $_SERVER[ 'REMOTE_ADDR' ], array( '127.0.0.1', ) ) ) {
toughp_backup_site( $_GET[ 'home_url' ], $_GET[ 'key' ] );
}