Skip to content

Instantly share code, notes, and snippets.

#Understanding MVC And MVP (For JavaScript & Backbone Developers)

Before exploring any JavaScript frameworks that assist in structuring applications, it can be useful to gain a basic understanding of architectural design patterns. Design patterns are proven solutions to common development problems and can suggest structural paradigms to help guide us in adding some organization to our application.

I think patterns are exciting as they're effectively a grass roots effort that build upon the collective experience of skilled developers who have previously faced similar problems as we do now. Although developers 10 or 20 years ago may not have been using the same programming languages for implementing patterns, there are many lessons we can learn from their efforts.

In this section, we're going to review two popular patterns - MVC and MVP. The context of our exploration will be how these patterns are related to the popular JavaScript framework Backbone.js, which will be explored in greater detail later on.

@kosinix
kosinix / custom-nav-walker-usage.php
Last active November 1, 2024 03:36
WordPress: Using a custom nav walker to create navigation menus in plain <a> tags. That is the <ul> and <li> tags are not present. Very useful if you want to create simple links that can be centered with a simple text-align:center on the containing element.
<?php
// In your template files like footer.php
// The items_wrap value ('%3$s') removes the wrapping <ul>, while the custom walker (Nav_Footer_Walker) removes the <li>'s.
wp_nav_menu(array('items_wrap'=> '%3$s', 'walker' => new Nav_Footer_Walker(), 'container'=>false, 'menu_class' => '', 'theme_location'=>'footer', 'fallback_cb'=>false ));
?>
@bradpotter
bradpotter / style.css
Last active November 3, 2016 16:58
Full Width Slider on Education Pro Theme
.education-pro-home #genesis-responsive-slider {
max-width: 100%;
}
.education-pro-home .flexslider {
max-width: 100%;
}
.education-pro-home .flexslider .slides img {
width: 100%;
@learncodeacademy
learncodeacademy / pubsub.js
Created July 29, 2015 02:54
Basic Javascript PubSub Pattern
//events - a super-basic Javascript (publish subscribe) pattern
var events = {
events: {},
on: function (eventName, fn) {
this.events[eventName] = this.events[eventName] || [];
this.events[eventName].push(fn);
},
off: function(eventName, fn) {
if (this.events[eventName]) {
@BFTrick
BFTrick / functions.php
Created June 1, 2016 16:46
Sort WooCommerce shipping methods by cost
<?php
// credit: ChromeOrange - https://gist.github.com/ChromeOrange/10013862
add_filter( 'woocommerce_package_rates' , 'patricks_sort_woocommerce_available_shipping_methods', 10, 2 );
function patricks_sort_woocommerce_available_shipping_methods( $rates, $package ) {
// if there are no rates don't do anything
if ( ! $rates ) {
return;
}
@hiyali
hiyali / php7-laravel-installation
Last active February 23, 2017 06:25
install php7 and laravel
### install php 7 ###
sudo apt-get install php7.0 php7.0-fpm php7.0-mysql -y
### install laravel ###
composer global require "laravel/installer"
### install requirements ###
sudo apt install php-gd php-zip phpunit php-mbstring
### new project ###
@ljharb
ljharb / array_iteration_thoughts.md
Last active October 24, 2024 07:30
Array iteration methods summarized

Array Iteration

https://gist.github.com/ljharb/58faf1cfcb4e6808f74aae4ef7944cff

While attempting to explain JavaScript's reduce method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

Intro

JavaScript Arrays have lots of built in methods on their prototype. Some of them mutate - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. (I'll also insist on referring to an array as a "list" - although in some languages, List is a native data type, in JS and this post, I'm referring to the concept. Everywhere I use the word "list" you can assume I'm talking about a JS Array) This means, to perform a single operation on the list as a whole ("atomically"), and to return a new list - thus making it mu

Status

This extension was developed as part of the jsonapi module for Drupal.

Introduction

The JSON API specification is agnostic about how a server implements filtering strategies. In fact, the spec says:

Note: JSON API is agnostic about the strategies supported by a server. The filter query parameter can be used as the basis for any number of filtering strategies.

@mattmc3
mattmc3 / modern_sql_style_guide.md
Last active November 18, 2024 04:31
Modern SQL Style Guide
layout author title revision version description
default
mattmc3
Modern SQL Style Guide
2019-01-17
1.0.1
A guide to writing clean, clear, and consistent SQL.

Modern SQL Style Guide