Skip to content

Instantly share code, notes, and snippets.

@JasonStoltz
JasonStoltz / gist:2511617
Created April 27, 2012 18:37
Steve souders nav timing code as bookmarklet
javascript:function formatTime(a){var b=new Date(a);return b.getHours()+":"+("0"+b.getMinutes()).slice(-2)+":"+("0"+b.getSeconds()).slice(-2)+"."+("00"+b.getMilliseconds()).slice(-3)}function doTime(a,b,c){if(!a){return""}if("undefined"===typeof b){if("undefined"===typeof performance.timing[a]){return"";return a+" is undefined"}else{b=performance.timing[a];c=undefined}}if(0===b){return"";return a+" is 0"}else if(b&&"undefined"===typeof c){return formatTime(b)+" = "+a+" ("+(b-gStart)+")"}else if(b&&c){return a+" = "+(c-b)+" ms"}}function doTimeln(a,b,c){var d=doTime(a,b,c);return d?d+"\n":""}function doNavTiming(){if("undefined"===typeof performance){alert("ERROR: Navigation timing API was not found.")}else{gStart=performance.timing.navigationStart;var a=doTimeln("total time",performance.timing.navigationStart,performance.timing.loadEventEnd)+doTimeln("dns",performance.timing.domainLookupStart,performance.timing.domainLookupEnd)+doTimeln("connect",performance.timing.connectStart,performance.timing.connectEnd)+
@JasonStoltz
JasonStoltz / gist:5048787
Last active December 14, 2015 07:09
Fixed width, 12 column, bootstrap-esque grid. Just set a few configurations... 'area-width' -- total width to fill, 'max-col' -- number of columns in grid, and 'spacing' -- spacing in between columns..., then just use class="grid", class="row", class="col1", "col2", etc. http://grab.by/kgds
.inline
{
display:inline-block;
zoom:1;
*display:inline;
}
@area-width: 758px;
@max-col: 12;
@spacing: 26px;
@JasonStoltz
JasonStoltz / Sharing for Terry
Last active December 20, 2015 14:39
Sharing for Terry
/**
Terry, here's a basic example of sharing. You specify ANY url in the addthis_share variable. Drop this into your console when on your site and you should see sharing buttons appear at the top of your page.
*/
$.getScript('//s7.addthis.com/js/300/addthis_widget.js#pubid=xa-51fd6b9d3d7d6b20', function(){
/* Options for markup are documented here:
http://support.addthis.com/customer/portal/articles/381238-addthis-toolbox#.Uf1qlT770U4
https://www.addthis.com/get/sharing#.Uf1wfj770U4
*/
var addthisMarkup = "";
@JasonStoltz
JasonStoltz / experience.js
Created November 21, 2013 13:20
A wrapper for Test & Target to turn its "over-simplified-for-marketers" mbox api into a developer friendly, JSONP-like service call.
/**
*
* Adobe Test and Target doesn't really have a nice API for dynamically including content, so this wraps it to provide that.
*
* What T&T wants you to do is simply define an "mbox" div on a page, call them and tell them the id of that div, and they handle
* populating content to that div.
*
* What I prefer to do is simply make a service call to T&T, have them give me some data/configuration back, and I will handle rendering
* content, however I see fit.
*
// modified from code of "JQuerify" bookmarklet
// http://www.learningjquery.com/2009/04/better-stronger-safer-jquerify-bookmarklet
(function() {
function z(a, b) {
var c = document.createElement("script");
c.src = a;
var d = document.getElementsByTagName("head")[0], e = !1;
c.onload = c.onreadystatechange = function() {
!e && (!this.readyState || this.readyState === "loaded" || this.readyState === "complete") && (e = !0, b(), c.onload = c.onreadystatechange = null, d.removeChild(c));
};
@JasonStoltz
JasonStoltz / tail-recursion
Created February 25, 2014 14:21
Scala tail recursion example. Returns the "nth" position in the fibonacci sequence. Tail recursive because evaluation is completed and passed to next call, nothing else needs to be evaluated after return. This lets scala compiler optimize this.
def fibNum(pos: Int) = {
def go(n: Int, curr: Int, next: Int): Int = {
if (n == 0) curr
else go(n-1, next, curr+next)
}
go(pos, 0, 1)
}
@JasonStoltz
JasonStoltz / gist:988bc09169ae7e792867
Created July 8, 2014 13:16
Accessing settings from another project in an sbt task
lazy val webAggregateImpl = webAggregate := { mappings: Seq[PathMapping] =>
def go(m: Seq[PathMapping], p: ResolvedProject): Seq[(File, String)] = {
if (p.dependencies.isEmpty) {
m
} else {
p.dependencies.map({ dep =>
val subp = Project.getProjectForReference(dep.project, buildStructure.value).get
/*
At this point I have a http://www.scala-sbt.org/0.12.4/api/sbt/ResolvedProject.html ... so I can access project
certain properties of the project, like base, id, etc.
@JasonStoltz
JasonStoltz / xample.gif
Last active August 29, 2015 14:15
Debugging Angular expressions in chrome console

Inline expressions sort of suck because they're hard to debug... if you end up with a really long, unweildy filter, here's a way to debug them in the browser console.

ex. of lengthy expression:

<tr id="element" ng-repeat="resource in alertingEnvironment.environment.database_services.resources | map:'servers.resources' | flatten | unique:'id' | concat: alertingEnvironment.environment.servers.resources">
</tr>
function $eval(expr) {
@JasonStoltz
JasonStoltz / gist:f0ef0d9255dc5a5e1d83
Created February 24, 2015 15:00
Using a view presenter in an ng-repeat
/*
Sometimes, in angular, you'll want to wrap an object with some view presenter logic, but not modify the underlying resource.
If you try something like:
`server in serverRequests(requests.resources)` or `server in requests.resources|map:asServerRequest`, you will fail miserably. You will get some depth recursion errors of some sort. There's a reason for it, but I forget the details. The key is to put your wrapping logic an `ng-init`.
*/
<div ng-repeat="server in requests.resources" ng-init="serverRequest=asServerRequest(server)">
</div>
@JasonStoltz
JasonStoltz / JS Builder
Created March 31, 2015 18:13
Javascript Builder pattern for function
function makeSoup(base){
var ingredients = {
base: base
};
var options = {
withMushrooms: function(){
ingredients.mushrooms = true;
return this;
},