Skip to content

Instantly share code, notes, and snippets.

@cuth
cuth / EventHandler.js
Last active December 18, 2015 05:19
Add this event handler to any class to give you the ability to trigger and bind events.
(function (exports) {
"use strict";
exports.EventHandler = function () {
this.collection = {};
};
exports.EventHandler.prototype.bind = function (events, callback) {
var names = events.split(" "),
x, xlen = names.length;
for (x = 0; x < xlen; x += 1) {
if (typeof this.collection[names[x]] !== 'object') {
@cuth
cuth / Timer.js
Last active December 18, 2015 05:19
Add this to any class to add timeout capabilities.
(function (exports, $) {
"use strict";
exports.Timer = function (opts) {
var defaults = {
delay: 5000,
start: null
};
this.opts = $.extend(defaults, opts);
this.timeout = null;
this.onHold = false;
@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,"")));
}
@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 / 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 / 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 / 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 / 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 / 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 / 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 || {}));