Skip to content

Instantly share code, notes, and snippets.

View cange's full-sized avatar
🧉

Christian Angermann cange

🧉
  • Hamburg, Germany
View GitHub Profile
/**
* Returns a string in which all 3 after a number exceeded a point is set.
* @param {String,Number}
* @example pointSeperatorHelper(1234567) // -> "1.234.567"
* @return {String}
*/
function pointSeperatorHelper (value) {
value = String(value);
var regExp = new RegExp('(-?[0-9]+)([0-9]{3})');
while(regExp.test(value)) {
@cange
cange / gist:255403
Created December 13, 2009 12:50
Mootools extension
/** Define primitives type for better compression */
var FALSE = false,
TRUE = true,
NULL = null,
window = self,
undefined;
/**
* Extension of Array Mootools class
*/
/**
* Twitter message String
* Searches in a string for links, replies, and hash and generates a <a>-Tag for the results.
* @param {String} message
* @return {String}
*/
function generateLinks ($message) {
$pattern[0] = '/(http:\/\/[0-9a-z-_.\/]+)/i'; # find is urls
$pattern[1] = '/@([0-9a-z-_]+)/'; # find is replies
$pattern[2] = '/#([0-9a-z-_]+)/'; # find is hashes
@cange
cange / Application.js
Created January 8, 2010 16:59
Simple analog clock with second hand (my Google friday experiment) CSS3, HTML5, jQuery basics
var Application = $.inherit({
__constructor: function(){
this._initClock();
},
_initClock: function(){
if($.browser.msie || $.browser.opera){
return false;
}
var elements = {
@cange
cange / gist:297079
Created February 7, 2010 00:16
Set a custom 'paste' event in jQuery 1.4.1
// set custom event
var name = 'paste';
$.fn[name] = function(fn) {
return fn ? this.bind(name, fn) : this.trigger(name);
};
// prevented paste event
$('#mySelector').bind(name, function(){
return !1; // false
})
/**
* Mashup of jquery.pyte and jquery.customdata for Component-based plugins
* load classes from JavaScript.
* @see http://github.com/psyk/jquery-pyte
* @see http://github.com/ubilabs/jquery-customdata
*
* @example
* <!-- DOM structure -->
* <div id="myComponent" data-jsc="module.MyComponent">component content</div>
*
@cange
cange / gist:509456
Created August 5, 2010 09:06
Check if a given year is leap year. #learnjs
/**
* #learnjs
* Check if a given year is leap year.
* @param {int} [year] Year to be evaluated. If no date is used defines the client year.
* @return {boolean} Returns <em>true</em> is year a leap year, otherwise <em>false</em>.
*/
function isLeapYear (year) {
return (new Date(year || (new Date).getFullYear(), 1, 29, 0, 0).getMonth() != 2);
}
@cange
cange / gist:509467
Created August 5, 2010 09:15
Find the largest, or smallest, number in an array. #learnjs
/**
* #learnjs
* Find the largest, or smallest, number in an array.
*/
var a = [-88, 4, 2, 0, 9, 1, 8];
Math.max.apply(Math, a); // 9
Math.min.apply(Math, a); // -88
@cange
cange / gist:509487
Created August 5, 2010 09:44
Generate unique random alphanumeric strings #learnjs
/**
* #learnjs
* Generate unique random alphanumeric strings
* @return {int} length
*/
function passGen(length) {
var str = '',
randomChar = function () {
var num = Math.floor(Math.random() * 62),
charCodeNum = (num < 36) ? num + 55 : num + 61;
@cange
cange / gist:600730
Created September 28, 2010 09:55
Find and remove an element from an array #learnjs
/**
* #learnjs
* Find and remove an element from an array #learnjs
*/
Array.prototype.remove = function (item) {
var pos = this.indexOf(item);
if (pos != -1) {
this.splice(pos, 1);
}
}