Skip to content

Instantly share code, notes, and snippets.

View dbernar1's full-sized avatar

Dan Bernardic dbernar1

View GitHub Profile
@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 / 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 / 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-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 / 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 / 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( ' ' );
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 / gist:8192810
Created December 31, 2013 04:57
A couple of hours of implementing Conway's Game of Life with Processing
int cell_size = 4;
int canvas_size = cell_size * 200;
StringList coordinates_of_alive_cells;
void setup () {
size( canvas_size, canvas_size );
// Initial pattern
coordinates_of_alive_cells = new StringList();
@dbernar1
dbernar1 / gist:7893522
Last active December 30, 2015 22:19
A cute little cachable class method implementation
<?php
// Example:
$data_from_api = LibraryOfCachableFunctions::get_some_data_from_api( $args );
// LibraryOfCachableFunctions does not have a get_some_data_from_api() function.
// This causes __callStatic() to be called. __callStatic() takes care of caching.
// if the results are not available in the cache, it calls a function by adding an underscore to the name of the called function.
// the _get_some_data_from_api() function is used to obtain the results and store them in the cache.
<?php
/**
* Plugin Name: Custom CSS for wp-impress-js
*/
add_action( 'impress_head', 'mask_custom_css_for_wp_impress_js' );
function mask_custom_css_for_wp_impress_js() {
?>
<style>