Skip to content

Instantly share code, notes, and snippets.

@brianally
brianally / authenticators-admin.js
Created July 2, 2015 18:18
Ember Simple-Auth authenticator for handling manual login and getting OAuth token back from server.
// app/authenticators/admin.js
import Ember from "ember";
import Base from "simple-auth/authenticators/base";
import ENV from "../config/environment";
export default Base.extend({
// called by login form action
// this.get("session").authenticate("authenticator:admin", credentials).then(...)
@brianally
brianally / routes-login.js
Created July 2, 2015 18:33
Ember route showing both OAuth2 and manual login
// app/routes/login.js
import Ember from "ember";
import ENV from "../config/environment";
export default Ember.Route.extend({
setupController: function(controller, model) {
controller.set("errorMessage", null);
},
actions: {
@brianally
brianally / gist:740b06b1ee6e2a54edec
Created July 2, 2015 18:41
Set a class on body if Ember app is embedded in iframe, so as to hide certain elements and/or take/suppress other actions.
// config/environment.js
module.exports = function(environment) {
var ENV = {
// ...
APP: {
inIframe: false
}
@brianally
brianally / filter-controller-or-whatever.js
Last active August 29, 2015 14:24
Multiple filters for Ember-Data
// some controller
import Ember from 'ember';
export default Ember.Controller.extend({
responses : [],
filteredResponses: [],
sectors : [],
dateFrom : null,
dateTo : null,
@brianally
brianally / embed-link.js
Created July 2, 2015 19:11
Ember.js embed link widget
@brianally
brianally / UserShell.php
Last active August 29, 2015 14:24
Simple CakePHP2.x user shell for use with ACL roles
<?php
// see User model at:
// https://gist.github.com/brianally/f4f70f5bb8c0f2304307
App::uses('AppShell', 'Console/Command');
class UserShell extends AppShell {
public $uses = array('User');
@brianally
brianally / User.php
Created July 2, 2015 20:16
CakePHP 2.x User model for use with Role ACL
<?php
App::uses('AppModel', 'Model');
App::uses('SimplePasswordHasher', 'Controller/Component/Auth');
class User extends AppModel {
public $actsAs = [
'Acl' => ['type' => 'requester']
];
@brianally
brianally / PageSlugRoute.php
Created July 2, 2015 20:27
Dynamic pages with slugs for CakePHP 2.x
<?php
// app/Lib/Routing/Route/PageSlugRoute.php
//
App::uses('Page', 'Model');
App::uses('CakeRoute', 'Routing/Route');
class PageSlugRoute extends CakeRoute {
public function parse($url) {
$params = parent::parse($url);
if (empty($params)) return false;
@brianally
brianally / Category.php
Created July 2, 2015 20:41
Hierarchical categories using MPTT with CakePHP 2.x
<?php
class Category extends AppModel {
public $hasAndBelongsToMany = [
'Item' => [
'className' => 'Item',
'with' => 'CategoryItem',
'foreignKey' => 'category_id',
'associationForeignKey' => 'item_id'
]
@brianally
brianally / README.md
Last active September 23, 2015 01:58
Stroke Dash CSS Transition

One of Mike Bostock's examples shows how a line can be made to appear to be animated as its drawn to the screen using a trick with the CSS stroke-dasharray property. You can see it in action here.

As usual with d3, the code is very concise and easy to understand. (OK, not all d3 code is easy to understand but still.) However, i wondered whether the transition could be applied with CSS. Not completely, of course, as we require the length of the line to set up the initial dasharray. But what if we wanted to set the transition time in our CSS?

Sure, it's a bit ridiculous, but let's just pretend our workflow involves designers handling all the styles. Or, we have a component that does this one thing and we don't want to have to set the timing in our JS, even if just to pass it in as an int. Maybe we're anal about having presentation logic in our JS.

Yeah, i know--it's SVG.

So, right away i figured it should be easy enough to declare the stroke-dashoffset transition in