Skip to content

Instantly share code, notes, and snippets.

View yoko's full-sized avatar
🍐
I like pear

yksk yoko

🍐
I like pear
View GitHub Profile
Array.prototype.split = function(n) {
var ret = [], i = 0;
while (n && (ret[i++] = this.splice(0, n)).length == n && this.length);
return ret;
};
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Function.prototype.bind</title>
<link rel="stylesheet" type="text/css" href="http://github.com/jquery/qunit/raw/master/qunit/qunit.css"/>
<script type="text/javascript" src="http://github.com/jquery/qunit/raw/master/qunit/qunit.js"></script>
<script type="text/javascript" src="Function.prototype.bind.js"></script>
</head>
<body>
debug = !(/^test\.example\.com/.test(location.host));
if (typeof console == 'undefined') {
console = {};
console.log = function() {
try {
var res = [];
for (var i = 0, l = arguments.length; i < l; i++)
res.push(arguments[i].toString());
if ($.browser.opera)
// so disgraceful..
killContextMenu = function() {
$('img').bind('contextmenu', function() {
return false;
});
};
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" focusIn="bg(true)" focusOut="bg(false)" backgroundColor="0xCCCCCC" backgroundImage="none">
<mx:Script>
<![CDATA[
private function bg(focus:Boolean):void
{
this.setStyle('backgroundColor', focus ? '0x333333' : '0xCCCCCC');
}
]]>
</mx:Script>
Math.randomInt = function(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
};
document.write = function(str) {
var script = document.getElementsByTagName('script');
script = script[script.length - 1];
var container = document.createElement('div');
container.innerHTML = str;
script.parentNode.insertBefore(container, script);
};
@yoko
yoko / jquery.getid.js
Created June 1, 2009 09:43
$('<div id="id-1234"/>').getId(); /* => 1234 */ $('<div id="id-foo"/>').getId(/-(\w+)$/); /* => foo */
(function($) {
$.fn.getId = function(pattern) {
pattern = pattern || /(\d+)/;
var id = this.attr('id');
if (!id) return null;
var ids = (pattern.exec(id) || []).slice(1);
return (ids.length > 1 ? ids : ids[0]) || null;
};
})(jQuery);
javascript:%20(function(){var%20form=document.createElement('form');form.method='POST';form.action='http://mapy.kayac.com/';form.innerHTML='<div><input%20type="hidden"%20name="url"%20value="'+location.href+'"/></div>';document.body.appendChild(form);form.submit();})();
/*
(function() {
var form = document.createElement('form');
form.method = 'POST';
form.action = 'http://mapy.kayac.com/';
form.innerHTML = '<div><input type="hidden" name="url" value="'+location.href+'"/></div>';
document.body.appendChild(form);
form.submit();
(function($) {
var rules = {
body: function(val) {
if (val.length == 0) return 'requires body';
if (val.length > 140) return 'body has a 140 character limit';
return true;
},
username: function(val) {
if (val.length > 20) return 'username has a 20 character limit';