Skip to content

Instantly share code, notes, and snippets.

View ychaouche's full-sized avatar

Yassine Chaouche ychaouche

View GitHub Profile
@ychaouche
ychaouche / compte_est_bon.py
Last active August 17, 2016 16:43
"Le compte est bon" resolver ("the total is right", see http://bit.ly/Lxvowq)
## Yassine chaouche
## [email protected]
## http://ychaouche.informatick.net
## Jun 16 2012 - 19:21
import sys
def main():
numbers = sys.argv[1:-1]
result = sys.argv[-1]
@ychaouche
ychaouche / caculator.py
Last active June 16, 2016 11:11
"le compte est bon" (documented version)
## Yassine chaouche
## [email protected]
## http://ychaouche.informatick.net
## Jun 16 2012 - 02:42
"""
This file contains the evaluate function that computes expressions like (4+3)/(2*(5+4)).
game.py feeds this function with expressions generated by the generator.combo function
(file generator.py). Its main function is evaluate. It takes an expression as a parameter,
which is simply a string, and returns the result of the computation of that expression.
@ychaouche
ychaouche / readme.txt
Created June 17, 2012 12:40
Tahar code inspector -> tells you if your python code is readable or not.
Hello,
Tahar is a little program (named after Inspecteur Tahar, a famous algerian movie character) that helps you keep your code minimal and clean. It warns you if one of your functions or methods code is longer than MAX_LENGTH lines (you can change the value of this macro in the begining of tahar's source code. Default is 25, this is the french EPITA/EPITECH's school standard for C functions).
You don'thave to copy tahar.py (or naive_tahar.py at the time of this writing) in the directory containing the modules you want to scan. You can just pass a dirctory or a list of python files with full access path.
Tahar should print something like this :
<execution trace>
@ychaouche
ychaouche / gist:3181595
Created July 26, 2012 11:42
javascript / C++
Do you agree what that statement below ?
"In Javascript, it is preferable to declare methods outside of the function definition.
Because if you define it inside the function, it's like you're defining a method inside a constructor.
You usually don't do that do you ? usually a constructor just initialises attributes.
You would declare the methods outside of the function definition."
So instead of this :
var Dog = function(name,age,sex){
Are those identical ?
// Javascript
var person = Object.create(animal)
// Some obscure language
object person inherits animal
//1
obj = {key:value};
//2
obj = Object.create(null);
obj[key] = value;
//3
obj = Object.create(null);
@ychaouche
ychaouche / doc-js-oo.txt
Created July 31, 2012 17:33
Orientation objet du javascript
Javascript orienté objet
========================
L'orientation objet du javascript
---------------------------------
Il n'y a pas de notion de classe en javascript. Il n'y a que des objets. L'héritage se fait entre objets et non entre classes, c'est ce qu'on appelle l'héritage par prototype (où le prototype d'un objet est l'objet duquel il hérite. Analogiquement en orientation objet classique, on parle de classe mère ou classe parente, ici on parle de prototype).
Ceci a pour conséquence que l'abstraction du programme en "classes" desquelles on instancie des objets n'existe pas en tant que tel en javascript. Au lieu de ça, on a le choix entre soit créer un objet via le mot clé "new" suivi du constructeur de l'objet (analogiquement aux constructeurs de classes dans la OO classique), ou bien en utilisant la nouvelle fonction Javascript (introduite en ECMAScript 5) dédiée à la création d'objets qui est "Object.create".
function YRSSReader(){ // Yahoo! RSS Reader
this.feed_url = "http://rss.news.yahoo.com/rss/topstories";
this.items = [];
this.callback = AjxCallback(this,this.simpleResponseHandler);
}
YRSSReader.prototype = new ZmZimletBase();
YRSSReader.prototype.constructor = YRSSReader;
// Handle de la réponse à la requête XHR en cas de succès
s15389121:/opt/zimbra/bin # telnet localhost 389
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
s15389121:/opt/zimbra/bin #
So I decided to check
s15389121:/opt/zimbra/bin # netstat -natp | grep 389
@ychaouche
ychaouche / gist:3888894
Created October 14, 2012 15:22
ADN parser
>>> bar = lambda x:all(map(lambda x:x in "ATCG",x))
>>> bar("AGCT")
True
>>> bar("AGCTACCCTTA")
True
>>> bar("AGCTACCCTTA1")
False
>>>