Skip to content

Instantly share code, notes, and snippets.

@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:

@cuth
cuth / noConflictAMD.html
Last active August 29, 2015 14:01
Hack to load modules in a half AMD half browser global environment.
<script>
if (typeof define === 'function' && define.amd) {
window.noConflictAMD = define.amd;
define.amd = null;
}
</script>
<script src="/module.js"></script>
<script>
if (typeof define === 'function') {
define.amd = window.noConflictAMD;
@cuth
cuth / console-dummy.js
Last active August 29, 2015 14:01
Console Dummy (https://github.com/andyet/ConsoleDummy.js) to fit my personal jshint requirements.
(function (con) {
'use strict';
function dummy() {}
['error','info','log','warn'].forEach(function (func) {
con[func] = con[func] || dummy;
});
}(window.console = window.console || {}));
@cuth
cuth / Hamburger.svg
Created May 7, 2014 20:43
Hamburger Menu Icon
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@cuth
cuth / format-tweet.js
Created April 28, 2014 20:15
Methods to format tweets with html.
(function () {
'use strict';
var userRegex = /(^|\s)(@(\w){1,15})/gi;
var urlRegex = /(^|\s)(https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*))/gi;
var linkUsers = function (tweet) {
return tweet.replace(userRegex, function ($m, $1, $2) {
return $1 + '<a href="https://twitter.com/' + $2 + '" target="_blank">' + $2 + '</a>';
});
@cuth
cuth / serve.js
Created April 14, 2014 17:21
Run a local express server on the current directory's static files using node
var host = "127.0.0.1";
var port = 1337;
var express = require("express");
var app = express();
app.use('/', express.static(__dirname + '/'));
app.listen(port, host);
console.log('Running server at http://localhost:' + port + '/');
@cuth
cuth / express.bat
Created March 17, 2014 16:36
Batch file to run IIS Express on the current directory. Optionally set the first parameter to set the port number.
SET EX="C:\Program Files\IIS Express\iisexpress.exe"
if not "%1" == "" (
CALL %EX% /path:%CD% /port:%1
) else (
CALL %EX% /path:%CD%
)
@cuth
cuth / Highlightjs-Bookmarklet.md
Last active April 3, 2021 12:09
This is a simple bookmarklet to wrap code in a textarea with the correct highlight.js elements.

highlight.js bookmarklet

This is a bookmarklet to wrap code in a textarea with the appropriate highlight.js elements. Simply select the code in a text field then activate the bookmarklet. There will be a prompt to enter the language. This will only work on sites that have highlight.js installed.

(function (d) {
    var a = d.activeElement,
        t = a.value,
 s = a.selectionStart,
@cuth
cuth / LimitText.js
Last active January 3, 2016 12:39
Limit any text field by adding to data attributes to the field.
(function (exports, $) {
"use strict";
var defaults = {
regexAttr: 'data-regex',
maxAttr: 'data-max'
},
allowedKeys = "Backspace Enter Tab Left Right Down Up",
runRegex = function () {
var value = this.$el.val(),
array = value.match(this.regex),
@cuth
cuth / EnterKey.js
Last active December 30, 2015 12:09
Add enter key submission to web forms.
// Submit Web Form on Enter Key
(function (exports, $) {
var submitAnchor = function (anchor) {
if (anchor.onclick) {
if (!anchor.onclick()) return;
}
var href = $(anchor).attr('href');
if (href.indexOf('javascript') >= 0) {
eval(unescape(href.replace(/^javascript:/i,"")));
}