This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log('Location:', '' + window.location); | |
console.log('Number of links:', document.querySelectorAll('a').length); | |
console.log('Number of _blank links:', document.querySelectorAll('a[target="_blank"]').length); | |
console.log('% of _blank links:', ~~( document.querySelectorAll('a[target="_blank"]').length / document.querySelectorAll('a').length * 100 ) ); | |
// changed .log() to .dir() for twitter | |
/* Tested on 2014-04-14 | |
Location: https://www.google.co.za/ | |
Number of links: 45 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// for brevity, this sample has some properties missing :/ | |
"client": { | |
"field": { | |
"firstname": { "type": "string", "req": true, "min": 2, "max": 50, "regex": "text", "description": "First Name" }, | |
"lastname": { "type": "string", "req": true, "min": 2, "max": 50, "regex": "text", "description": "Last Name" }, | |
"email": { "type": "string", "req": true, "regex": "email" }, | |
"portfolio": { "type": "integer", "control": "input", "default": "", "req": false }, | |
"clientproduct": { "type": "rel-many", "description": "Products this client uses", "control": "checklist" }, | |
"clientstate": { "type": "integer", "req": false, "control": "select", "description": "State" } | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html><html><head><title>JS1k Entry</title><meta charset="utf-8" /><style>html, body { margin: 0; padding: 0; border: 0; }#c { display: block; } /* kill scrollbars from hell */</style></head><body><canvas id="c"></canvas><script> | |
var a = document.getElementsByTagName('canvas')[0]; | |
var b = document.body; | |
var d = function(e){ return function(){ e.parentNode.removeChild(e); }; }(a); | |
// unprefix some popular vendor prefixed things (but stick to their original name) | |
var AudioContext = window.AudioContext || window.webkitAudioContext; | |
var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame || function(f){ setTimeout(f, 1000/30); }; | |
// fix bug in safari: http://qfox.nl/weblog/218 | |
document.body.clientWidth; | |
// auto resize (original) canvas. call `onresize(w,h) to limit the size of the canvas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$settings = array( | |
// one key is used for reading images (so that this can be public facing, but still prevent people from uploading) | |
'key_read' => '~', | |
// a separate secret key for storage. we don't want just any old monkey uploading images. | |
'key_store' => '123', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Start ye'r engines | |
var | |
http = require('http'), | |
persist = require('pst-obj'), | |
state = { hits: 0 } | |
; | |
// api/layer to interface with state object | |
function getPageCount() { | |
state.hits++; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html><head> | |
<script src="sea.js"></script> | |
<script src="jquery.js"></script> | |
<script> | |
$(function(){ | |
function fakeXHR(url, callback) { | |
setTimeout(function(){callback('This is some pseudo XHR content. Random number: '+Math.random());}, Math.random()*1000+500); | |
} | |
seajs.use('loading', function(loading) { | |
$('#btnRequest').click(function() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html><head> | |
<script src="mootools.js"></script> | |
<script src="loading-mt-office-x-min.js"></script> | |
<script> | |
window.addEvent('domready', function(){ | |
$('btnRequest').addEvent('click', function() { | |
var anim = loading.start($('btnRequest')); | |
fakeXHR('goesNowhere.php', function(result) { | |
$('txtResult').set('text', result); | |
anim.stop(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// used in schema valiadtion for json objects | |
String.prototype.fromCamelToLabel = function() { | |
return this[0].toUpperCase() + this.substring(1).replace(/[A-Z]/g, function(h){ | |
return " "+h; | |
}); | |
}; | |
var jv = {}; | |
// Validate an object against a predefined schema. |
NewerOlder