Skip to content

Instantly share code, notes, and snippets.

@machty
machty / angular-question.md
Created April 29, 2014 05:37
Angular question about mixing in directive behaviors

Let's say I've declared three class-restricted directives "am-wat", "am-foo", and "am-bar", that each augment the attached element with some behavior, e.g.:

<div am-wat="some data" am-foo="other data" am-bar="lol">
  Yadda yadda yadda
</div>

Is there a way to write a directive that mixes in the behavior of the three directives, e.g.:

@machty
machty / qp-limitation.md
Last active August 29, 2015 14:01
Basic/obvious QP limitation

Limitation regarding hrefs on non-route-driven controllers

TL;DR: lack of information about default values on non-route-driven controllers might force us to make href's overly verbose in some cases, or possible make us punt on non-route-driven-controller query params.

Scenario:

Router.map ->
  this.route('about')

// application.hbs
@machty
machty / qp-thoughts.md
Last active August 29, 2015 14:01
query params HOME STRETCH

Aside from the few bugs that I know I need to fix about query params, there are a few remaining issues that I need help with, driven by real legit use cases from folk I've been talking to.

Also, if you haven't been keeping up, I have a PR in that added the model-dependent state stuff I talked about at EmberConf to query params, which impacts the way query params are reset/restored between changing routes/models.

TL;DR generate changelists of app state mutations that can be used in cases where it's necessary to be able to predict what will happen when some action is invoked, e.g. linking into another route.

I've had this zany idea floating around that I just wanted to share that's probably extremely over-engineered to over-solve problems in the routing domain, but I figured I'd share it and see if any lightbulbs go off.

So in routing land, one of the harder things to calculate is a link's href; we have have to use the provided destination rout and the contexts to provide to basically ask "if this transition were to take place, what URL would you end up with?". This has led to some interesting code with query params, particularly with model dep state, where we have to say "given this destination route, these contexts, this list of explicitly provided query params, please fill sensible default values for unspecified query params and tell me what the final URL is going to be".

Particularly in nailing down these last

@machty
machty / gist:ec52161e47424dd138d2
Created June 2, 2014 14:28
possible query-params helper enhancements
  • (query-params)
    • Basic form
      • e.g. (query-params page=nextPage)
      • set page to nextPage
      • any other QPs on target route get automatically filled in based on model-dependent state
      • active state: route considered inactive unless supplied params match
    • PROPOSAL: Specify params to reset
      • e.g. (query-params '-sortOrder' page=nextPage)
  • Like above, sets page to nextPage, but resets the
@machty
machty / idea.js
Created July 19, 2014 21:35
this is a backwards compatible approach to namespace-less nested routes.
Router.map(function(root) {
// this === root
this.route("articles", function(scope) {
// this === scope, hence making `scope` an optional
// arg unless you have some reason to use it within callbacks below
// these two are identical and generate a route
// named "articles.show"
this.route("show");
//scope.route("show");
test("customers can use a forgot password link", function() {
ajax('/setup_test_env/signup/preexisting-users').then(function() {
visit(...);
fillIn(...);
click(...);
andThen(function() {
equal(find('.errors p').text(), "E-mail taken");
});
});
import FooComponent from 'foo';
function funHelper(value, options) {
return value + "!!!";
}
var foo = "yes";
export default Ember.Component.extend({
bar: 123,
@machty
machty / index.html.slim
Created April 7, 2012 14:24
An attempt at Slim/Haml helpers for handlebars
= handlebars_template_named "edit-field" do
= hb %{ if isEditing } do
= hb %{ view BD.TextField valueBinding="value" }
= hb_else
= hb %{ if value } do
= hbb %{ value }
= hb_else
span.no-name empty
/ Outputs
@machty
machty / gist:2931511
Created June 14, 2012 17:05
async queue download
ownloadQueue = async.queue (photo, callback) ->
# Here we define the task handled by this concurrency-limiting queue.
downloadfile = photo.url
host = url.parse(downloadfile).hostname
filename = url.parse(downloadfile).pathname.split("/").pop()
filename = "./public/downloads/#{filename}"
photo.localFilename = filename
console.log "set photo.localFilename to #{photo.localFilename}"
theurl = http.createClient(80, host)
requestUrl = downloadfile