Skip to content

Instantly share code, notes, and snippets.

View leeoniya's full-sized avatar
😕
shaving bytes and milliseconds. dependencies: {}

Leon Sorokin leeoniya

😕
shaving bytes and milliseconds. dependencies: {}
View GitHub Profile
@cowboy
cowboy / duckpunching-vs-dickpunching.js
Created April 22, 2011 16:38
JavaScript: Duck Punching vs Dick Punching
// Duck Punching.
window._alert = window.alert;
window.alert = function(n) {
return typeof n === 'number'
? window._alert('QU' + Array(n + 1).join('A') + 'CK')
: window._alert.apply(window, arguments);
};
// Dick Punching.
@borzilleri
borzilleri / function.cast.php
Created May 7, 2011 00:02
PHP function to cast an object from one class to another.
<?php
/**
* Cast an object into a different class.
*
* Currently this only supports casting DOWN the inheritance chain,
* that is, an object may only be cast into a class if that class
* is a descendant of the object's current class.
*
* This is mostly to avoid potentially losing data by casting across
* incompatable classes.
@madrobby
madrobby / README.md
Created May 17, 2011 16:34 — forked from 140bytes/LICENSE.txt
Luhn10 algorithm

Implementation of the Luhn 10 algorithm to check validity of credit card numbers. See http://en.wikipedia.org/wiki/Luhn_algorithm for details on the algorithm.

var validCreditCard = function(a,b,c,d,e){for(d=+a[b=a.length-1],e=0;b--;)c=+a[b],d+=++e%2?2*c%10+(c>4):c;return!(d%10)};

validCreditCard('378282246310005'); //=> true
validCreditCard('378282246310006'); //=> false

// some numbers to test with
// 378282246310005 371449635398431 378734493671000
@cowboy
cowboy / jquery.ba-dataplus.js
Created May 18, 2011 20:52
jQuery Data+: a new signature to allow easy initializing/getting of a per-element "state object"
/*!
* jQuery Data+ - v0.1pre - 6/3/2011
* http://benalman.com/
*
* Copyright (c) 2011 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
(function($) {
@joelambert
joelambert / README
Created June 1, 2011 11:03
Drop in replacements for setTimeout()/setInterval() that makes use of requestAnimationFrame() where possible for better performance
Drop in replace functions for setTimeout() & setInterval() that
make use of requestAnimationFrame() for performance where available
http://www.joelambert.co.uk
Copyright 2011, Joe Lambert.
Free to use under the MIT license.
http://www.opensource.org/licenses/mit-license.php
@cowboy
cowboy / unreleased.md
Created June 1, 2011 20:05
Unreleased stuff...

This list will hopefully shrink faster than it can grow. (yeah, right)

jQuery

jQuery deparam / deparam+ / sortObject (WIP)
https://gist.github.com/1025817

jQuery infiniteScroller (WIP)

jQuery scrollinout event

@cowboy
cowboy / jquery.ba-farthest-descendant.js
Created June 1, 2011 21:24
jQuery Farthest Decendant: Dedicated to Kris Borchers
/*!
* jQuery Farthest Decendant - v0.2pre - 6/1/2011
* http://benalman.com/
*
* Copyright (c) 2011 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
;(function($) {
@lukemorton
lukemorton / README.markdown
Created June 4, 2011 13:32
Set caret position via jQuery

jQuery Caret

This is a very simple lightweight plugin to allow you to move the caret (or cursor) position in an <input /> or <textarea> element.

By exposing three jQuery.fn methods you can easily move a a caret to any position you like:

$.fn.caretTo( index , [ offset ] )

@leeoniya
leeoniya / json_csv_ideas.js
Created June 17, 2011 19:32
better-than-json recordset passing
(function() {
// mimicing php's array_combine()
function combine(a, b) {
var i, o = {};
for (i in a)
o[a[i]] = b[i];
return o;
}
@jeremeamia
jeremeamia / orm.php
Created July 9, 2011 22:02
View-Models for Kohana 3.2.x (ORM-specific)
<?php defined('SYSPATH') or die('No direct script access.');
class ORM extends Kohana_ORM {
protected $_as_object = NULL;
public function as_object($class)
{
$this->_as_object = $class;