Skip to content

Instantly share code, notes, and snippets.

View xjamundx's full-sized avatar

Jamund Ferguson xjamundx

View GitHub Profile
@xjamundx
xjamundx / blog-webpack-2.md
Last active April 21, 2024 16:20
From Require.js to Webpack - Part 2 (the how)

This is the follow up to a post I wrote recently called From Require.js to Webpack - Party 1 (the why) which was published in my personal blog.

In that post I talked about 3 main reasons for moving from require.js to webpack:

  1. Common JS support
  2. NPM support
  3. a healthy loader/plugin ecosystem.

Here I'll instead talk about some of the technical challenges that we faced during the migration. Despite the clear benefits in developer experience (DX) the setup was fairly difficult and I'd like to cover some of the challanges we faced to make the transition a bit easier.

@xjamundx
xjamundx / data-models.md
Last active August 29, 2015 14:16
common data model

Backbone has models for both display state and server data. Views bind to models and respond to various events on the models.

Ampersand has have the concept of session data (for display stuff) and props (for server synced data) (http://read.humanjavascript.com/ch06-models.html)

Ember has controllers which "allow you to decorate your models with display logic" (http://emberjs.com/guides/controllers/)

React has state and props. State is local to the component (view) and props are immutable and passed down from a parent.

Relay Relay "By co-locating the queries with the view code...components can be moved anywhere in a render hierarchy without having to apply a cascade of modifications to parent components or to the server code which prepares the data payload." (http://facebook.github.io/react/blog/2015/02/20/introducing-relay-and-graphql.html)

@xjamundx
xjamundx / error-handling.md
Last active March 21, 2019 06:30
Full Stack Error Handling in Node.js

Ways to think about errors

  • this whole server is borked
  • this user session is broken
  • whatever action i just tried to complete did not work
  • an error will happen if we continue, so let’s not
  • who cares

Log level of various errors

@xjamundx
xjamundx / oj3.service.js
Last active December 18, 2015 02:19
oj3.service.js
// oj3 implementation
angular.module('odesk').factory('oj3', function() {
return {
widgets: odesk.mediator.widgets,
trigger: function($scope, event, data) {
// i don't know, we aren't an instance
},
registerWidget: function(name, $scope) {
// this won't quite work, because $scope doesn't talk OJ3 events
oj3.registerWidget(name, $scope);
$.ajax({
url: 'https://www.odesk.com/',
success: function() {
$.ajax({
url: 'https://www.odesk.com/',
success: function() {
// so much nesting
}
});
});
@xjamundx
xjamundx / express-infinite.js
Created May 13, 2013 19:53
bug in express 3.x (including 3.2.4)
// this will cause an infinite loop
var express = require('express');
var app = express();
app.get('/', function(req, res) {
res.send(express.toast, "bla");
});
app.listen(2222);
@xjamundx
xjamundx / async.reporter.js
Created May 4, 2013 03:59
super simple example of how to do an async reporter for jshint (with my changes)
"use strict";
exports.reporter = function(errors, data, opts, cb) {
setTimeout(function() {
console.log(errors.length ? "FAILED" : "OK");
}, 50);
};
exports.reporter.async = true;
@xjamundx
xjamundx / svgupdate.js
Last active November 16, 2017 22:17
Update Base64 SVG background image.
function updateSVG() {
var el = document.querySelector('.icon-user');
var style = window.getComputedStyle(el);
var uri = style.backgroundImage;
var svg64 = uri.replace(/^.+base64,/, "").replace(/\"?\)$/, "")
var xml = window.atob(svg64);
var hex = '#' + Math.floor(Math.random()*16777215).toString(16);
var color = xml.replace(/fill="#[A-Za-z0-9]+"/, 'fill="' + hex + '"');
var color64 = window.btoa(color);
var colorUri = "url('data:image/svg+xml;base64," + color64 + "')";
@xjamundx
xjamundx / views
Last active December 14, 2015 05:09 — forked from jquerygeek/views
define(function(require) {
var Backbone = require('backbone')
var template = require('text!../../template/newThread.html')
return Backbone.View.extend({
el: '#container',
template: _.template(template),
initialize: function () {
this.render()
var Contact = require('model/contact')
@xjamundx
xjamundx / jqmobibackbone.js
Last active December 13, 2015 19:19
jqmobi with backbone + require.js
require.config({
paths: {
jquery: "lib/jqMobi.min",
underscore: "http://underscorejs.org/underscore-min",
backbone: "http://backbonejs.org/backbone"
},
shim: {
'backbone': {
deps: ['underscore', 'jquery'],
exports: 'Backbone',