Skip to content

Instantly share code, notes, and snippets.

View etoxin's full-sized avatar

Adam Lusted etoxin

View GitHub Profile
@etoxin
etoxin / app.js
Last active January 19, 2016 03:02
Javascript Module Loader
// All modules must have a init function.
/**
* ready Function
* @param fn
*/
function ready(fn) {
if (document.readyState != 'loading'){
fn();
} else {
document.addEventListener('DOMContentLoaded', fn);
@etoxin
etoxin / randomString.js
Created January 20, 2016 07:01
Create a string that s random
/**
* @param lng {Number}
* @returns {string}
* @constructor
*/
function MakeId(lng) {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < lng; i++)
@etoxin
etoxin / chatAppInATweet.js
Created February 3, 2016 02:37
Chat App in a tweet.
r=require,f='<form><input name=m>';r('http').createServer((q,s)=>s.end(f=('<p>'+(r('querystring').parse(q.url)['/?m']||'')+f))).listen(3000)
$.validator.addMethod("passwordCheck", function (value, element) {
return this.optional(element) || /((?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%-_=+<>]).{8,30})/g.test(value);
}, "Field must contain only letters, numbers, or dashes.");
@etoxin
etoxin / val.js
Created February 22, 2016 02:18
Salesforce Password validation.
$.validator.addMethod("passwordCheck", function (value, element) {
return this.optional(element) || /((?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%-_=+<>]).{8,30})/g.test(value);
}, "Field must contain only letters, numbers, or dashes.");
@etoxin
etoxin / http.js
Created February 24, 2016 00:41
json, ajax, xhr, http on node.js
var http = require("http");
http.get(weatherApi, function(res) {
var body = '';
// get chunks of data and add it to body
res.on('data', function(chunk){
body += chunk;
});
@etoxin
etoxin / exampleModule.js
Last active June 24, 2016 06:52
Revealing Namespace Module Loader
/**
* project.exampleModule
* @namespace project.exampleModule
*/
(function (window, project, undefined) {
/**
* @constructor
* @public
* @memberof project.exampleModule
@etoxin
etoxin / Apply.js
Last active May 10, 2016 00:24
Call, Apply, Bind
/**
* Using apply and built-in functions
*
* Clever usage of apply allows you to use built-ins functions for some tasks that otherwise probably would have been written by looping over the array values. As an example here we are going to use Math.max/Math.min to find out the maximum/minimum value in an array.
*/
// min/max number in an array
var numbers = [5, 6, 2, 3, 7];
// using Math.min/Math.max apply
@etoxin
etoxin / Cache Images Then Callback
Created May 24, 2016 07:02
cacheImagesThenCallback
/**
* Pass an Array of image urls and it will run `callback` once they are cached.
*
* @example
cacheImagesThenCallback([image.jpg, picture.png], function() {
...
});
* @alias CORE.cacheImagesThenCallback
* @constructor
* @param imageSrcArray {array} Array of image urls.