Search Results

Search found 10 results on 1 pages for 'mikk'.

Page 1/1 | 1 

  • Python OOP and lists

    - by Mikk
    Hi, I'm new to Python and it's OOP stuff and can't get it to work. Here's my code: class Tree: root = None; data = []; def __init__(self, equation): self.root = equation; def appendLeft(self, data): self.data.insert(0, data); def appendRight(self, data): self.data.append(data); def calculateLeft(self): result = []; for item in (self.getLeft()): if (type(item) == type(self)): data = item.calculateLeft(); else: data = item; result.append(item); return result; def getLeft(self): return self.data; def getRight(self): data = self.data; data.reverse(); return data; tree2 = Tree("*"); tree2.appendRight(44); tree2.appendLeft(20); tree = Tree("+"); tree.appendRight(4); tree.appendLeft(10); tree.appendLeft(tree2); print(tree.calculateLeft()); It looks like tree2 and tree are sharing list "data"? At the moment I'd like it to output something like [[20,44], 10, 4], but when I tree.appendLeft(tree2) I get RuntimeError: maximum recursion depth exceeded, and when i even won't appendLeft(tree2) it outputs [10, 20, 44, 4] (!!!). What am I missing here? I'm using Portable Python 3.0.1. Thank you

    Read the article

  • Java-script object - get variable name

    - by Mikk
    Hi, To begin with, I'm not even sure, if it is the right way to do it. Let's say, i have script (jquery included) like this: foo = function() { this.bar = function() { alert('I\'m bar'); } this.test = function() { $('body').append('<a onclick="my_var.bar();">Click me</a>'); } this.test(); } var my_var = new foo(); Is there any way, i could make variable "my_var" dynamic inside function "foo". So I could do something like $('body').append('<a onclick="'+the_variable_which_im_assigned_to+'.bar();">Click me</a>'); Thank you

    Read the article

  • Extending mysqli and using multiple classes

    - by Mikk
    Hi, I'm new to PHP oop stuff. I'm trying to create class database and call other classes from it. Am I doing it the right way? class database: class database extends mysqli { private $classes = array(); public function __construct() { parent::__construct('localhost', 'root', 'password', 'database'); if (mysqli_connect_error()) { $this->error(mysqli_connect_errno(), mysqli_connect_error()); } } public function __call($class, $args) { if (!isset($this->classes[$class])) { $class = 'db_'.$class; $this->classes[$class] = new $class(); } return $this->classes[$class]; } private function error($eNo, $eMsg) { die ('MySQL error: ('.$eNo.': '.$eMsg); } } class db_users: class db_users extends database { public function test() { echo 'foo'; } } and how I'm using it $db = new database(); $db->users()->test(); Is it the right way or should it be done another way? Thank you.

    Read the article

  • mysql_connect "bool $new_link = true" is very slow

    - by Mikk
    Hi, I'm using latest version of Xampp on 64bit Win7. The problem is that, when I use mysql_connect with "bool $new_link" set to true like so: mysql_connect('localhost', 'root', 'my_password', TRUE); script execution time increases dramatically (about 0,5 seconds per connection, and when I have 4 diffirent objects using different connections, it takes ~2 seconds). Is setting "bool $new_link" to true, generally a bad idea or could it just be some problem with my software configuration. Thank you.

    Read the article

  • mysqli and field types

    - by Mikk
    Hi, I'd like to know if there is a simple way to fetch data from mysql tables with "correct" data types? What i mean, if field type is for example INT or SMALLINT is it possible to pass those types directly to PHP as integers? I did some searching and found mysqli_fetch_fields, but for SMALLIT type is 2, for INT 3 and so on. It could be done that way, but it looks rather clumsy workaround. Is there any better way? I'm using PHP and mysqli. Thank you.

    Read the article

  • PHP validating integers

    - by Mikk
    Hi, I was wondering, what would be the best way to validate an integer. I'd like this to work with strings as well, so I could to something like (string)+00003 - (int)3 (valid) (string)-027 - (int)-27 (valid) (int)33 - (int)33 (valid) (string)'33a' - (FALSE) (invalid) That is what i've go so far: function parseInt($int){ //If $int already is integer, return it if(is_int($int)){return $int;} //If not, convert it to string $int=(string)$int; //If we have '+' or '-' at the beginning of the string, remove them $validate = ($int[0] === '-' || $int[0] === '+')?substr($int, 1):$int; //If $validate matches pattern 0-9 convert $int to integer and return it //otherwise return false return preg_match('/^[0-9]+$/', $validate)?(int)$int:FALSE; } As far as I tested, this function works, but it looks like a clumsy workaround. Is there any better way to write this kind of function. I've also tried filter_var($foo, FILTER_VALIDATE_INT); but it won't accept values like '0003', '-0' etc.

    Read the article

  • Unix timestamp and mysql date: birthdate

    - by Mikk
    Hi, I have a really basic question concerning unix timestamp and mysql date. I'm trying to build a small website where users can register and fill in their birthdate. Problem is that unix starts with Jan 01 1970. Now if i calculate age for users, form dates like date('m.d.Y', $unix_from_db) and so on it will fail with users older that 40 years, right? So what would be the rigth way for doing this. Sorry, for basic question like this, but I'm inexperienced with php and mysql.

    Read the article

  • jquery get form id by input id

    - by Mikk
    Hi, I have really basic question. How can I get form id by input element id. <form id="my_form"> <fieldset> <!--some <div>'s--> <input id="my_input"></div> <!--some <div>'s end--> </fieldset> </form> Now if I have var form_input = $('#my_input'); How can I get id "my_form"? Thank you.

    Read the article

  • Charaters with jquery json

    - by Mikk
    Hi everyone, I'm using jquery $.getJSON to retrieve list of cities. Everything works fine, but I'm from Estonia (probably most of you don't know much about this country =D) and we are using some characters like õ, ü. ä, ö. When I pass letters like this to callback function, I keep getting empty strings. I've tried to base64 encode(server-side)-decode(jquery base64 plugin) strings (i thought it was a good idea as long as I can compress pages with php, so I don't have to worry about bandwidth), but in this way I end up with some random chinese symbols. What would be the best workaround for this problem. Thank you.

    Read the article

  • Characters with jquery json

    - by Mikk
    Hi everyone, I'm using jquery $.getJSON to retrieve list of cities. Everything works fine, but I'm from Estonia (probably most of you don't know much about this country =D) and we are using some characters like õ, ü. ä, ö. When I pass letters like this to callback function, I keep getting empty strings. I've tried to base64 encode(server-side)-decode(jquery base64 plugin) strings (i thought it was a good idea as long as I can compress pages with php, so I don't have to worry about bandwidth), but in this way I end up with some random chinese symbols. What would be the best workaround for this problem. Thank you.

    Read the article

1