Skip to content

Instantly share code, notes, and snippets.

View arcanis's full-sized avatar
:octocat:

Maël Nison arcanis

:octocat:
View GitHub Profile
/**
* @class foo
*/
var foo = function () {
/**
* Stop, hammertime.
* @member foo
* @returns 42
/**
* @class
*/
var foo = function () {
/**
* Stop, hammertime.
*
* @memberOf foo#
/**
* @mixin foo
*/
var foo = {
/**
* Does something.
*/
@arcanis
arcanis / gist:2724085
Created May 18, 2012 08:59
Classes en javascript
// Chaque fonction est un constructeur
var Foo = function ( ) { this.bar = 'hello world'; };
var instance = new Foo( );
console.log( instance.bar ); // "hello world"
// Chaque fonction possède un prototype
var Foo = function ( ) { };
Foo.prototype.bar = 'hello world';
var instance = new Foo( );
console.log( instance.bar ); // "hello world"
#!/usr/bin/env sh
# Usage :
# $> sudo set-python-version 2; python -V
# Python 2.7.2
# $> sudo set-python-version 3; python -V
# Python 3.2.2
python=$(which python)
pythonX=$(which python$1)
<?php
class StringRandomizer {
public function process( $text ) {
return preg_replace_callback('/\{(((?>[^\{\}]+)|(?R))*)\}/x', array( $this, 'replace' ), $text );
}
public function replace( $text ) {
$text = $this->process( $text[ 1 ] );

The Indentation Nightmare

If there is something that I have never fully understood during the last years of learning programming languages, it's the chaos around indentation. Some says that you should use spaces, some others says that you should use tabs. And even if you're willing to use spaces, there will be multiple schools, some people saying that you should use two spaces, instead of four for some other developers.

Why is it such a mess ? I don't even see why it is such a debatable topic : indentation is made by tabs. Alignment is made by spaces. Nothing more, nothing less. Want to know why ?

Spaces have a fixed length

Spaces are usefull because they have a fixed length. It means that it should be used when you have to align code. What's aligning ? Take this piece of code :

PonyOS
http://www.ponyos.org/
Blizzard - Starcraft : Warhound is back
https://us.battle.net/sc2/en/blog/9369235
Atlassian - JIRA Jr
http://www.atlassian.com/jirajr/
Lambda The Ultimate - Migration to Facebook
MyEventManager.prototype.bootstrap = function ( ) {
var self = this;
this.listen( 'myEvent', function ( ) {
self.myEventListener( );
} );
};
// ---
var array = [ 1, 2, 3 ];