Skip to content

Instantly share code, notes, and snippets.

View dbernar1's full-sized avatar

Dan Bernardic dbernar1

View GitHub Profile
function countAdjacentPairs(search_string) {
var words_that_appeared_in_adjacent_pairs = [];
sets_of_two_adjacent_words_in( search_string ).forEach( function( two_adjacent_words ) {
var first_of_the_two_words = two_adjacent_words[ 0 ];
if (
two_adjacent_words.are_a_pair()
&& first_of_the_two_words.is_not_one_of( words_that_appeared_in_adjacent_pairs )
) {
// which one reads more naturally?
@dbernar1
dbernar1 / title-case.js
Created March 11, 2014 18:42
titleCase
function break_into_words( text ) {
return text.split( ' ' ).filter( function(word) { return word !== ''; } );
}
function add( element, to_array ) {
to_array.push( element );
}
function space_separated( array ) {
return array.join( ' ' );
@dbernar1
dbernar1 / plugin.php
Created March 30, 2014 02:40
Custom Gravity form submission processing
<?php
/**
* Plugin Name: My custom Gravity form submission processing plugin
*/
// We will use photo contest entry submissions as the example
when_a_gravity_form_is_submitted( 'check_whether_it_is_a_contest_entry_submission' );
when_a_contest_entry_is_submitted( 'do_some_custom_processing' );
@dbernar1
dbernar1 / 1-weather-analysis.coffee
Last active August 29, 2015 13:58
Some "literate CoffeeScript"
when_the 'page_loads', ->
display_weather_analysis_map()
enable_changing_display_option_by_clicking_display_options()
enable_navigating_map_by_using_search()
display_weather_analysis_map = ->
when_the 'current_station_info_is_available', ->
show_map "analysis-map", false
show_what_station_is_being_shown()
@dbernar1
dbernar1 / index.php
Last active August 29, 2015 13:59 — forked from stungeye/index.php
<?php
/*
* This code implements a simple higher/lower guessing game.
*
* The computer picks a random number and the user guesses by way of an HTML form.
*
* The user is given hints if they guess incorrectly with the ability to try again.
*
* Upon winning the game the user can add their name to a session-based leaderboard.
*/
@dbernar1
dbernar1 / 1-index.php.slim
Last active August 29, 2015 14:00
Valid slim ( slim-lang.com )
<?php if ( Yii::app()->user->hasFlash( 'changePassword' ) ): ?>
.flash-success
p style="color:red;"
<?php echo Yii::app()->user->getFlash( 'changePassword' );?>
<?php endif ?>
@dbernar1
dbernar1 / test_html_escaping.rb
Created April 29, 2014 12:18
Inline PHP tags test for core/test_html_escaping.rb
def test_html_unescaped_php_tags
source = %q{
a href="<?php echo $url ?>"
}
assert_html '<a href="<?php echo $url ?>"></a>', source
end
@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" ';
@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/
" 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