Skip to content

Instantly share code, notes, and snippets.

View aaronj1335's full-sized avatar
🤠

Aaron Stacy aaronj1335

🤠
View GitHub Profile
@aaronj1335
aaronj1335 / mockery.md
Last active December 14, 2015 19:38
mocking up a resource definition

summary

each resource file, say api/enamel/1.0/infoset.js, defines an ancestor of the Model class. the resource class has a __requests__ member that defines mesh/request instances for each request (get, put, post, query, delete, etc). each of these request instances has an ajax method that's just a reference to $.ajax, and it uses that do actually make the xhr.

'mocking' a resource amounts to the following:

@aaronj1335
aaronj1335 / testy.md
Last active December 15, 2015 08:09
unit testing -- from test.js to continuous integration

unit testing

unit tests are good for number of reasons, but it's important to know when writing them is worth the time effort. we're not dogmatic about TDD, but we try to make it as easy as possible for the developer to write meaningful tests.

when deciding whether or not to write a test, keep the following in mind:

  • javascript is INSANELY dynamic, so refactoring can cause a lot of subtle bugs, and it's nearly impossible without good unit tests. in as much as you

we should probably get some unit tests around the following corner cases:

  1. collection load's
  2. a collection has been loaded and includes a particular model
  3. that model is updated server-side, not on the page
  4. the collection is re-loaded, and the change from the server side is applied to the local copy of the model
  5. i don't know if the model triggers a change event in this case
  6. pertinent code: when a query resolves and converts the plain objects into model instances
@aaronj1335
aaronj1335 / find_globals.md
Last active May 25, 2023 17:11
finding global variables

good unit tests framesworks in javascript will throw errors when you leak global variables. it can be massively difficult to trace down the offending lines of code in a large application. a quick and effective fix is to add the attached bit of javascript at the beginning of your application and open your debugger (chrome dev tools, firebug, node debugger, etc.).

you'll get a break point at the error and it's easy to fix from there.

@aaronj1335
aaronj1335 / exception.txt
Last active December 17, 2015 05:39
meteor exception
Exception from Deps recompute: Error: Can't create second landmark in same branch
at Object.Spark.createLandmark (http://localhost:3000/packages/spark/spark.js?4af332696fb84f1c71f2e678ad0a267755b2b828:1169:13)
at http://localhost:3000/packages/templating/deftemplate.js?9369dfa782cc1c8cd4d568925617249ec480b84f:116:24
at Object.Spark.labelBranch (http://localhost:3000/packages/spark/spark.js?4af332696fb84f1c71f2e678ad0a267755b2b828:1114:14)
at Object.Meteor._def_template.partial [as row] (http://localhost:3000/packages/templating/deftemplate.js?9369dfa782cc1c8cd4d568925617249ec480b84f:115:22)
at http://localhost:3000/packages/handlebars/evaluate.js?742a34cf3479d95600582786665b53c0eba4f7d9:352:48
at Object.Spark.labelBranch (http://localhost:3000/packages/spark/spark.js?4af332696fb84f1c71f2e678ad0a267755b2b828:1114:14)
at branch (http://localhost:3000/packages/handlebars/evaluate.js?742a34cf3479d95600582786665b53c0eba4f7d9:311:20)
at template (http://localhost:3000/packages/handle
@aaronj1335
aaronj1335 / crc_fail.md
Last active December 17, 2015 16:19
i've tried to download the last part of the IE9 Windows 7 VM from the [modern.ie](http://www.modern.ie/en-us/virtualization-tools#downloads) site numerous times, and it's never the correct file. the strange thing is it seemed to work for parts 1-4, but 5 keeps failing.
astacy∂ʇoqǝɔɐʇs ☠ ~  12:15:30 May23
§ curl http://www.modern.ie/cdn/md5/IE9.Win7.For.MacVirtualBox.part5.txt # expected md5
277bb59670149cdc1714262c01c4fc11

astacy∂ʇoqǝɔɐʇs ☠ ~  12:13:47 May23
§ md5 ~/Downloads/IE9*Win7.For.Mac*part5* # what i'm actually getting
MD5 (/Users/astacy/Downloads/IE9-1.Win7.For.MacVirtualBox.part5.rar) = b7c4319f951c924a99c0fa28bf47c315
MD5 (/Users/astacy/Downloads/IE9-2.Win7.For.MacVirtualBox.part5.rar) = 720ae9af8efecf53c02bd9c1def05274
MD5 (/Users/astacy/Downloads/IE9-3.Win7.For.MacVirtualBox.part5.rar) = 72935ee1673e0101e5969dd7a67f4951
@aaronj1335
aaronj1335 / post_in_category.php
Created May 25, 2013 19:00
check if post is in category
<?php
c++;
if (in_array(1, wp_get_post_categories($post.id)) && $c == 1) { ?>
this text will only show up if $post is in category 1 and the counter is 1
<?php } ?>
#!/usr/bin/env node
🌞 = 'sun';
☔ = 'rain';
console.log('the ' + 🌞 + ' wouldnt b special if it wasnt for ' + ☔);
var node = svg.selectAll('circle.node')
.data(nodes)
.enter().append('svg:circle')
.attr('class', 'node')
.attr('cx', function(d) { return d.x; })
.attr('cy', function(d) { return d.y; })
.attr('r', 8)
.style('fill', function(d, i) { return fill(i & 3); })
.style('stroke', function(d, i) { return d3.rgb(fill(i & 3)).darker(2); })
.style('stroke-width', 1.5)
# we'll format our research in YAML. it should be pretty easy to figure out the
# format, but generally a line starts w/ a key followed by a colon and a space,
# and then the value
#
# if you want to check whether you've properly formatted it, you can run
# something like:
#
# python -c "import yaml; print yaml.load(open('assets/data/crises/CRI_SVRBLD.yaml').read())"
#
# note that you need to format dates according to iso 8601, so if you have a