Skip to content

Instantly share code, notes, and snippets.

View bfillmer's full-sized avatar

Bryan Fillmer bfillmer

View GitHub Profile
@bfillmer
bfillmer / admin-options.php
Created May 14, 2014 18:47
Generic WP Option Page Functions
<?php
/**
* Generic WordPress Options Panel
*
* A good starting point for a simple options panel, just
* loops through defined options and creates input[type=text]
* for each with the value and lets you update.
*
* Replace namespace- and namespace_ with either your plugin
@bfillmer
bfillmer / tiny-pubsub-listener.js
Last active August 29, 2015 14:01
Generic Page Listener for Tiny PubSub
/**
* Quick and simple wrapper for Tiny PubSub (https://github.com/cowboy/jquery-tiny-pubsub).
* Wanted to be able to simply update an array with various events/classes/ids to watch for
* and have a single function fired. Also leverages Underscore.js (http://underscorejs.org/).
*/
// What we want to watch for: key = event to listen for, value array = class/ids to watch for.
var eventsAndElementsToWatch = {
click: ['.btn','.link'],
change: ['.input'],
@bfillmer
bfillmer / toolbox.less
Created June 16, 2014 15:45
Generic LESS Mixins
// Liked what Chris Coyier showed off in this blog post:
// http://codepen.io/chriscoyier/blog/some-mini-sass-mixins-i-like
// Decided to make LESS versions really quickly.
.coverer() {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
@bfillmer
bfillmer / meta-data.php
Created August 15, 2014 17:31
Quick way to hide protected meta data via a plugin. More robust than the _ prefix.
<?php
add_filter( 'is_protected_meta', 'hide_meta_data', 10, 2 );
/**
* Set our metadata to be protected, will not be seen in administration,
* unless the plugin is deactivated.
* @param array $protected protected values
* @param string $meta_key current meta key
* @return string/bool $protected or true to add
@bfillmer
bfillmer / angular-wp-factory.js
Created August 28, 2014 15:32
Angular JS WordPress Factory
/**
* Small factory for accessing WP backend AJAX. Best used with the built in admin-ajax.php
* calls.
*
* Controller example:
var myApp = angular.module('myApp', [ 'WP' ]);
myApp.controller('myCtrl', function($scope, WPAjax){
@bfillmer
bfillmer / angular-focus-directive.js
Created August 31, 2014 19:04
Angular JS Focus Directive
(function(){
/**
* Emulates ng-show for focus, i.e.:
*
* <input ng-focus="truthyValue">
*
* Setting truthyValue to true focuses said input.
*/
app.directive('ngFocus', function($timeout){
@bfillmer
bfillmer / persistent.filter.js
Created March 4, 2015 17:02
Persistent Filter for Angular ng-repeats.
'use strict';
angular.module('core')
// Persistent filter, runs on any ng-repeat.
.filter('PersistentFilter', ['_', 'PersistentFilterStorage',
function (_, PersistentFilterStorage) {
var pfs = PersistentFilterStorage;
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->

Folder Structure

Motivations

  • Clear feature ownership
  • Module usage predictibility (refactoring, maintainence, you know what's shared, what's not, prevents accidental regressions, avoids huge directories of not-actually-reusable modules, etc)
@bfillmer
bfillmer / observable-store.js
Last active August 4, 2016 21:49 — forked from tungd/observable-store.js
How to use Rx.Observable in-place of Redux store
import update from 'react/lib/update'
import { Observable, Subject, ReplaySubject } from 'rx'
const INITIAL_STATE = {
user: null
}
const updates = new ReplaySubject()
export const state = Observable.of(INITIAL_STATE)
.merge(updates.map(change => state => update(state, change)))