Skip to content

Instantly share code, notes, and snippets.

View treasonx's full-sized avatar

James Morrin treasonx

  • San Francisco CA
View GitHub Profile
$scope.shortenInText = function () {
var text = $scope.content.text || '';
var PROTO_PTRN = /^https?:\/\//;
var tokens = text.split(/\s/);
_.chain(tokens)
// get tokens that look like URLs
.map(function(token) {
if(PROTO_PTRN.test(token)) {
return token;
@treasonx
treasonx / gist:23080846dcf2785e24be
Last active August 29, 2015 14:13
Learning Most
canvas.scrollStream.takeWhile(function () {
console.log('streamEvent');
return canvas.percentVisible() < VISIBILITY_THRESHOLD;
}).observe(function () {}).then(function () {
console.log('Became visible');
triggerVisibiliyAnalytics();
});
function imageUploadController(app, logger) {
var adminImages = express.Router();
adminImages.use(administrator);
app.use('/adminImagesOrSomething', adminImages);
adminImages.get('/', function (req. resp) {
@treasonx
treasonx / dijit_layout_programmatic.html
Last active January 3, 2016 05:49 — forked from anonymous/dijit_layout_programmatic.html
Fixed errors in handling of child widget removed from grid on destroy.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Test Programmatic Dijit Layout</title>
<meta name="viewport" content="width=570">
<style>
@import "../../dijit/themes/claro/document.css";
@import "../../dijit/themes/claro/claro.css";
@import "../css/skins/claro.css";
@treasonx
treasonx / gist:6166904
Created August 6, 2013 17:59
Seems like it would be great to refactor into a wire spec?
define(function () {
'use strict';
var LocationManager = require('modules/spxcontroller/LocationManager');
var WindowManager = require('modules/spxcontroller/WindowManager');
var SlinkAnchorService = require('modules/spxcontroller/SlinkAnchorService');
var PresentationService = require('modules/spxcontroller/PresentationService');
var g = require('utils/globalObject');
var utils = require('utils/utils');
//Gets a jquery object containing all of the elements on the page that have a css class of "show-example1"
var showDescriptionInput = $('.show-example1');
//when someone clicks on an element with the id of "name" or "phone" run this function. I think "click.toggle"
//is a mistake it should be just click
$("#name, #phone").bind('click.toggle', function(e) {
//dont do the default HTML thing. SO if this is a link dont make the browser load the new page.
e.preventDefault();
@treasonx
treasonx / build.js
Created April 23, 2013 14:24
Namespaced AMD
/*
This is the build config for my main JS file.
*/
({
baseUrl: "src/",
//wrap will wrap the entire script in an IIFE which will create private define/require functions
wrap: true,
out: 'dist/spxmain.js',
modules: [{
name: 'requireLib',
@treasonx
treasonx / aspects.js
Created January 2, 2013 23:33
Meld Aspects
var when = require('when');
var meld = require('meld');
var winston = require('winston');
var config = require('./config');
var dbAspects = {
introDeferred: function(obj,name) {
meld.around(obj, name, function(joinpoint) {
var def = when.defer();
var promise = def.promise;
@treasonx
treasonx / gist:3813041
Created October 1, 2012 17:07
Insert CSS
loadCss: function( cssString, $head) {
var $css = $('<style type="text/css">'+cssString+'<style>');
$head = $head || $('head');
$head.append($css);
return $css;
}
@treasonx
treasonx / gist:3293539
Created August 8, 2012 08:45
Setting Data Attributes
//Incorrect
jQuery(document).ready(function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://ardrone.swoop.com/js/spxw.js"; // use this for linked script
//The following will not properly set the required data attributes properly
script.attributes['data-domain'] = 'SW-XXXXXX-X';
script.attributes['data-theme'] = 'red';
script.attributes['data-serverbase']= 'http://ardrone.swoop.com/';