Skip to content

Instantly share code, notes, and snippets.

View adjohu's full-sized avatar
🎶
Writing code

Adam Hutchinson adjohu

🎶
Writing code
View GitHub Profile
@adjohu
adjohu / terriblecodeexample.js
Created May 1, 2014 14:18
terrible code example
// Copyright 2013 Host Europe Group - All rights reserved.
// The 123-reg mobile site
if (!Object.keys) {
Object.keys = (function () {
'use strict';
var hasOwnProperty = Object.prototype.hasOwnProperty,
hasDontEnumBug = !({
toString: null
}).propertyIsEnumerable('toString'),
dontEnums = ['toString', 'toLocaleString', 'valueOf', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable', 'constructor'],
(function ($) {
/**
* Override console in this scope so we can squash errors.
*/
var con = window.console;
var console = {
log: function () {
con && con.log && con.log(Array.prototype.slice.call(arguments));
},
$(document).on("click", ".edit_trigger", function () {
var $trigger = $(this);
// Find linked editable
var editableID = $trigger.data("editable");
var $editable = $("#" + editableID);
// Replace editable with input.
var $input = $("<input>").val($editable.html().trim());
$editable
@adjohu
adjohu / models.js
Created February 27, 2013 11:03
Simple model class
var A = function (props) {
this.properties = props;
this.constructor.addModel(this);
};
A.models = [];
A.addModel = function (model) {
model.properties.id = this.models.length + 1;
this.models.push(model);
var createPoller = function (pollFunc, interval) {
var timeout;
var poll = function () {
pollFunc();
timeout = setTimeout(poll, interval);
};
return {
start: function () {
var createClass = function (methods, staticMethods) {
if (!methods || !methods.hasOwnProperty("init")) {
throw "you must include an init method";
}
var newClass = function () {
this.init();
};
$.extend(newClass.prototype, methods);
$.extend(newClass, staticMethods);
return newClass;
@adjohu
adjohu / gist:3913410
Created October 18, 2012 17:15
updateOpenTagState
(function () {
var isObject = function (foo) {
return foo.constructor == Object;
};
var mixin = function (a, b) {
for (var property in b) {
if (b.hasOwnProperty(property)) {
if (isObject(b[property])) {
(withJQuery = function withJQuery() {
// Check for jQuery
if (!window.jQuery) {
return setTimeout(withJQuery, 100);
}
var getISODateFor = function (title) {
var selector = ".DtlDetailTbl td:contains('" + title + "') + .ResConfirmValue";
var date = new Date($(selector).text());
return date.toISOString();
var highest = 16777215;
var steps = 1000;
var step = highest / steps;
var emptyColor = "000000";
for (var i=0; i < steps; i++) {
var color = parseInt(step * i, 10).toString(16);
color = emptyColor.slice(0, -color.length) + color;
var span = document.createElement("span");
span.innerHTML = "a"
//var formContainer = $("#ctl00_ContentPlaceHolder1_ffnpPayBrasPag1_dvBPCC");
var findPrev = function (node, needle) {
var found = false;
do {
node = node.previousSibling;
var nv = node.nodeValue;
if (nv && nv.indexOf(needle) > -1) {
found = true;
}
} while (!found);