Skip to content

Instantly share code, notes, and snippets.

View dbernar1's full-sized avatar

Dan Bernardic dbernar1

View GitHub Profile
@dbernar1
dbernar1 / homepage.js
Last active February 19, 2018 08:20
That's righchyall
when_the_user_indicates_which_classes_they_wanna_see_homework_for(
send_user_choice_for_which_classes_they_wanna_see_homework
);
when_the_user_indicates_which_calendars_they_want_to_see(
send_user_choice_of_which_calendars_they_want_to_see
);
//-----------------Calendar Details-------------------//
@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 / 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>
@dbernar1
dbernar1 / 1-template.php
Last active December 23, 2015 08:59
get_template_part() vs. require - variable scope
<?php
$hello = 'world';
get_template_part( 'hello' );
require 'hello.php';
function get_template_part( $filename ) {
require $filename . '.php';
}
<?php
add_action( 'wp_enqueue_scripts', 'scripts_and_styles__of_me_theme');
function scripts_and_styles__of_me_theme() {
if ( is_page( 'forecasts' ) || is_front_page() || is_page( 'radar' ) || is_page( 'historical-data' ) ) {
wp_enqueue_script( 'jquery-ui-autocomplete' );
}
}
@dbernar1
dbernar1 / gist:6425549
Last active December 22, 2015 05:39
Naming function parameters. Also, code is text.
<?php
wp_enqueue_script( $module_slug . '-js', dirname(__FILE__) . '/js/' . $module_slug . '.js', array( 'jquery' ), self::version, true );
wp_enqueue_script(
$script_name = $module_slug . '-js',
$location = dirname(__FILE__) . '/js/' . $module_slug . '.js',
$load_after = array( 'jquery' ),
$version_number = self::version,
$load_in_footer = true
);
@dbernar1
dbernar1 / gist:6368069
Created August 28, 2013 16:31
Resetting capabilities for admin role in WordPress to the defaults, programmatically. I ran this through functions.php of the theme. List of caps copied from http://codex.wordpress.org/Roles_and_Capabilities#Administrator
<?php
$administrator = get_role( 'administrator' );
foreach (
array( 'activate_plugins', 'delete_others_pages', 'delete_others_posts', 'delete_pages', 'delete_plugins', 'delete_posts', 'delete_private_pages', 'delete_private_posts', 'delete_published_pages', 'delete_published_posts', 'edit_dashboard', 'edit_files', 'edit_others_pages', 'edit_others_posts', 'edit_pages', 'edit_posts', 'edit_private_pages', 'edit_private_posts', 'edit_published_pages', 'edit_published_posts', 'edit_theme_options', 'export', 'import', 'list_users', 'manage_categories', 'manage_links', 'manage_options', 'moderate_comments', 'promote_users', 'publish_pages', 'publish_posts', 'read_private_pages', 'read_private_posts', 'read', 'remove_users', 'switch_themes', 'upload_files', 'create_product', )
as $cap
) {
$administrator->add_cap( $cap );
}
add_action( 'wp_enqueue_scripts', 'my_pjn_scripts_and_styles');
function my_pjn_scripts_and_styles() {
if ( is_page( 'some-page-slug' ) ) {
wp_enqueue_script(
$handle = 'googlemap',
$src = "http://maps.googleapis.com/maps/api/js?sensor=true",
$deps = array(),
$ver = 'V3',
$in_footer = true