Skip to content

Instantly share code, notes, and snippets.

@balupton
balupton / README.md
Last active July 13, 2024 17:32
Ajaxify a Website with the HTML5 History API using History.js, jQuery and ScrollTo
@nicholaides
nicholaides / jade_usage.js
Created April 1, 2011 16:20
How to use Jade client-side
window.Jade = require('jade');
JadeTemplates = {};
JadeTemplates["some_template"] = Jade.compile("li.feedback.exercise_item.checkbox\n input(type=\"hidden\", name=\"exercise[feedback_items_attributes][$order][_type]\", value=\"Checkbox\")\n\n - if (this.is_editing)\n != partial(\"item_actions\")\n\n .body\n .checkbox\n input(type=\"checkbox\", disabled, checked)\n\n .title\n - if (this.is_editing)\n input(name=\"exercise[feedback_items_attributes][$order][title]\", value=this.title, placeholder=\"E.g. "I completed this exercise"\", \"data-bvalidator\"=\"required\")\n\n - if (this.is_viewing)\n label= this.title\n");
JadeTemplates["exercises/_Image"] = Jade.compile("a.image(href=this.file_url)\n\timg(src=this.file_thumb_url)\n");
// defines the helpers "exercise_item" and "partial"
@kaheglar
kaheglar / jquery-assert.js
Created June 23, 2011 12:38
jQuery assert - throw error msg if condition false
(function($) {
$.assert = function(condition, msg) {
if (!condition) {
$.error(msg);
}
};
})(jQuery);
@amatiasq
amatiasq / Handlebars- Backbone.js
Created February 5, 2013 00:06
This allow Handlebars to look up Backbone Model's attributes: {{ user.address.street }} If user is a Backbone Model this will become user.get("address").street And if user.get("adress") is also a Backbone Model this will be produced: user.get("address").get("street")
Handlebars.JavaScriptCompiler.prototype.nameLookup = function(parent, name, type) {
var result = '(' + parent + ' instanceof Backbone.Model ? ' + parent + '.get("' + name + '") : ' + parent;
if (/^[0-9]+$/.test(name)) {
return result + "[" + name + "])";
} else if (Handlebars.JavaScriptCompiler.isValidJavaScriptVariableName(name)) {
return result + "." + name + ')';
} else {
return result + "['" + name + "'])";
}
};
@cuth
cuth / AMDwithManualUMD.md
Last active April 22, 2017 20:47
Mixing an AMD script loading solution with a traditional script loading solution with UMD modules causes a conflict.

Using RequireJS and loading UMD scripts normally

Mixing an AMD script loading solution with a traditional script loading solution with UMD modules causes a conflict.

Two approches to loading scripts

The traditional way to load a script is to manually add a script tag on the page like this:

@CMCDragonkai
CMCDragonkai / http_streaming.md
Last active October 24, 2024 17:43
HTTP Streaming (or Chunked vs Store & Forward)

HTTP Streaming (or Chunked vs Store & Forward)

The standard way of understanding the HTTP protocol is via the request reply pattern. Each HTTP transaction consists of a finitely bounded HTTP request and a finitely bounded HTTP response.

However it's also possible for both parts of an HTTP 1.1 transaction to stream their possibly infinitely bounded data. The advantages is that the sender can send data that is beyond the sender's memory limit, and the receiver can act on

@jpolvora
jpolvora / boot.js
Created September 28, 2016 22:20
SystemJS Knockout JS Module Loader
var systemJsLoader = {
loadComponent: function (name, templateConfig, callback) {
if (templateConfig.systemjs) {
SystemJS.import(templateConfig.systemjs)
.then(function (viewModelCtor) {
callback({
createViewModel: function (params, componentInfo) {
return viewModelCtor.viewModel(params, componentInfo);
},
template: ko.utils.parseHtmlFragment(viewModelCtor.template)
var str = 'class ಠ_ಠ extends Array {constructor(j = "a", ...c) {const q = (({u: e}) => {return { [`s${c}`]: Symbol(j) };})({});super(j, q, ...c);}}' +
'new Promise((f) => {const a = function* (){return "\u{20BB7}".match(/./u)[0].length === 2 || true;};for (let vre of a()) {' +
'const [uw, as, he, re] = [new Set(), new WeakSet(), new Map(), new WeakMap()];break;}f(new Proxy({}, {get: (han, h) => h in han ? han[h] ' +
': "42".repeat(0o10)}));}).then(bi => new ಠ_ಠ(bi.rd));';
try {
eval(str);
} catch(e) {
alert('Your browser does not support ES6!')
}
var preact = require('preact');
var createRenderer = require('./preact-dom-renderer');
// set up a rendering target
var renderer = createRenderer();
// render some stuff into the internal DOM
renderer.render(preact.h(PreactApp, pageConfig));
// get a snapshot of the current HTML
@Rich-Harris
Rich-Harris / README.md
Last active November 1, 2024 12:15
Unifying Rollup options

Rollup 0.48 introduces a few changes to the options object, because the current options are confusingly different between the CLI and the options exported by your config file.

Changes to the config file

  • entry is now input
  • sourceMap and sourceMapFile are now sourcemap and sourcemapFile (note casing)
  • moduleName is now name
  • useStrict is now strict

The dest and format options are now grouped together as a single output: { file, format, ... } object. output can also be an array of { file, format, ... } objects, in which case it behaves similarly to the current targets. Other output options — exports, paths and so on — can be added to the output object (though they will fall back to their top-level namesakes, if unspecified).