Skip to content

Instantly share code, notes, and snippets.

View dbernar1's full-sized avatar

Dan Bernardic dbernar1

View GitHub Profile
@dbernar1
dbernar1 / plugin.php
Created December 7, 2014 23:07
Enqueueing scripts from within a plugin file
<?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 August 29, 2015 14:09
Adding a custom matcher for Jasmine
jasmine.Matchers.prototype.toReturnAPromise = function() {
if ( 'function' !== typeof this.actual.then ) {
throw 'Did not return a promise';
}
};
@dbernar1
dbernar1 / gulpfile.js
Created November 11, 2014 14:22
Gulpfile which converts CoffeeScript into JavaScript before running unit tests through Karma
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 () {
@dbernar1
dbernar1 / coffeelint.json
Created November 7, 2014 21:02
coffeelint.json
{
"arrow_spacing": {
"level": "ignore"
},
"camel_case_classes": {
"level": "error"
},
"coffeescript_error": {
"level": "error"
},
@dbernar1
dbernar1 / switch-theme.php
Created August 7, 2014 16:49
Switch theme based on whether the user is logged in or not. One theme for guests, other theme for logged in users.
<?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 August 29, 2015 14:04
Content from another site
<?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' );
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
" 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 August 29, 2015 14:03
If internal details of a commonJS module were to be unit tested...
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 August 29, 2015 14:02
Disabling autocomplete for WP post editor
<?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" ';