Skip to content

Instantly share code, notes, and snippets.

Dan Bernardic dbernar1

Block or report user

Report or block dbernar1

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@dbernar1
dbernar1 / plugin.php
Created Dec 7, 2014
Enqueueing scripts from within a plugin file
View plugin.php
<?php
/**
* Plugin Name: Plugin name
*/
add_action( 'wp_enqueue_scripts', 'enqueue_scripts__pluginname' );
function enqueue_scripts__pluginname() {
$jquery_location = WP_PLUGIN_URL . "/panomanager/js/jquery.js";
wp_register_script('jquery', $jquery_location, true);
@dbernar1
dbernar1 / some-unit-test.js
Last active Aug 29, 2015
Adding a custom matcher for Jasmine
View some-unit-test.js
jasmine.Matchers.prototype.toReturnAPromise = function() {
if ( 'function' !== typeof this.actual.then ) {
throw 'Did not return a promise';
}
};
@dbernar1
dbernar1 / gulpfile.js
Created Nov 11, 2014
Gulpfile which converts CoffeeScript into JavaScript before running unit tests through Karma
View gulpfile.js
var coffee = require('gulp-coffee'),
karma = require('karma').server;
gulp.task('compile-tests-coffee', functoin() {
return gulp.src('./test/unit/**/*.coffee')
.pipe(coffee({bare: true}))
.pipe(gulp.dest('test/unit'));
});
gulp.task('unit-test', ['compile-tests-coffee'], function () {
View coffeelint.json
{
"arrow_spacing": {
"level": "ignore"
},
"camel_case_classes": {
"level": "error"
},
"coffeescript_error": {
"level": "error"
},
@dbernar1
dbernar1 / switch-theme.php
Created Aug 7, 2014
Switch theme based on whether the user is logged in or not. One theme for guests, other theme for logged in users.
View switch-theme.php
<?php
/**
* Plugin name: Different theme for guest than logged in user
*/
// You can also put this file in mu-plugins dir.
add_filter( 'template', 'switch_theme__db' );
add_filter( 'stylesheet', 'switch_theme__db' );
@dbernar1
dbernar1 / plugin.php
Last active Aug 29, 2015
Content from another site
View plugin.php
<?php
define( 'PRODUCT_QUERY_VAR', 'product__dbernar1' );
define( 'PRODUCT_URL_PREFIX', 'products' );
function get_permalink__dbernar1( $post = null ) {
if ( is_null( $post ) ) global $post;
return site_url( PRODUCT_URL_PREFIX . '/' . $post->post_name );
}
add_action( 'init', 'create_post_type_rewrite_rules__dbernar1' );
View lifeTest.coffee
assert = require 'assert'
Life = require '../src/life'
whenCurrentGenerationIs = Life.nextGenerationOf
any = it
nextGenerationContains = ( cell, nextGeneration ) -> assert cell in nextGeneration
nextGenerationDoesNotContain = ( cell, nextGeneration ) -> assert cell not in nextGeneration
View gist:7bc106968fde46050889
" a particular style of auto-indentation
set si
" I like these colors
syntax enable
set background=dark
colorscheme fruit "https://github.com/flazz/vim-colorschemes/blob/master/colors/fruit.vim
" create .swp temp files in my home dir instead of in the current directory
set directory=~/.vimtmp
@dbernar1
dbernar1 / life.coffee
Last active Aug 29, 2015
If internal details of a commonJS module were to be unit tested...
View life.coffee
thereAreNo = ( items_in_array ) ->
items_in_array.length == 0
module.tests.thereAreNo: () ->
assert thereAreNo []
assert.fail thereAreNo [ 1 ]
assert.throws ->
thereAreNo 1
, /is not an array/
@dbernar1
dbernar1 / disable-autocomplete-for-editor.php
Last active Aug 29, 2015
Disabling autocomplete for WP post editor
View disable-autocomplete-for-editor.php
<?php
/*
* Plugin Name: Disabling autocomplete for editor
* Description: See https://core.trac.wordpress.org/ticket/28037
*/
add_action( 'post_edit_form_tag' , 'disable_autocomplete_for_editor__gfm_ac' );
function disable_autocomplete_for_editor__gfm_ac( ) {
echo ' autocomplete="off" ';
You can’t perform that action at this time.