Posts Tagged ‘logic’

Only getting the first character when accessing post variable

Sunday, August 22nd, 2010

A common way I handle things in Drupal is to create a CCK type, and then create a custom submit handler to perform logic on the CCK fields when the node is submitted. However, I have been unable to get the value when the CCK field type is a Date field because the array is structured differently.

Here I assign the portion of the $form array I want.

 //This is in the submit handler
  $fromDatePRE = array();
  $fromDatePRE[] =  $form['field_bill_start'][0]['value']['date'];
  $fromDate = ['0']['#value']['#date'];

$fromDate is printing the first character “S” of Sat 8/21/2010 which is the value I want , but I want the whole value. I know this has something do with how I’m accessing the array but I can’t figure it out.

This is what I’m working with – I added a comment to the value I’m trying to access:

drupal_set_message('<pre>'. print_r($fromDatePRE, TRUE) .'</pre>');

Which Yiedls:

 Array
    (
        [0] => Array
            (
                [#type] => textfield
                [#default_value] => Sat, 08/21/2010
                [#id] => edit-field-bill-start-0-value-datepicker-popup-0
                [#size] => 20
                [#maxlength] => 30
                [#attributes] => Array
                    (
                    )

                [#description] =>  Format: Sat, 08/21/2010
                [#post] => Array
                    (
                        [title] => llllllllllllll
                        [menu] => Array
                            (
                                [link_title] =>
                                [parent] => Array
                                    (
                                        [hierarchical_select] => Array
                                            (
                                                [selects] => Array
                                                    (
                                                        [0] => primary-links:0
                                                        [1] => label_1
                                                    )

                                            )

                                    )

                                [weight] => 0
                            )

                        [hs_form_build_id] => hs_form_7bf97c3c59ba2a064d6e841ae405dd30
                        [changed] =>
                        [form_build_id] => form-1f928faaa990f3809da391165d51981a
                        [form_token] => 616f6e8a7bb9c4ffc2aec65174c0817d
                        [form_id] => billing_node_form
                        [log] =>
                        [pathauto_perform_alias] => 1
                        [print_display] => 1
                        [print_display_urllist] => 1
                        [print_mail_display] => 1
                        [print_mail_display_urllist] => 1
                        [print_pdf_display] => 1
                        [print_pdf_display_urllist] => 1
                        [field_bill_start] => Array
                            (
                                [0] => Array
                                    (
                                        [value] => Array
                                            (
                                                //This is the value I need
                                                [date] => Sat, 08/21/2010
                                            )

                                    )

                            )

                        [field_bill_end] => Array
                            (
                                [0] => Array
                                    (
                                        [value] => Array
                                            (
                                                [date] => 08/25/2010
                                            )

                                    )

                            )

                        [name] => administrator
                        [date] =>
                        [status] => 1
                        [promote] => 1
                        [op] => Save
                    )

                [#programmed] =>
                [#tree] => 1
                [#parents] => Array
                    (
                        [0] => field_bill_start
                        [1] => 0
                        [2] => value
                        [3] => date
                    )

                [#array_parents] => Array
                    (
                        [0] => field_bill_start
                        [1] => 0
                        [2] => value
                        [3] => date
                    )

                [#weight] => 0
                [#processed] => 1
                [#required] =>
                [#input] => 1
                [#autocomplete_path] =>
                [#process] => Array
                    (
                        [0] => form_expand_ahah
                    )

                [#name] => field_bill_start[0][value][date]
                [#value] => Sat, 08/21/2010
                [#needs_validation] => 1
                [#defaults_loaded] => 1
                [#sorted] => 1
            )

    )

How do I develop quick thinking skills? [closed]

Sunday, August 22nd, 2010

Well,To start i am a grad student.

I was big shot until a few months ago, everyone came to me when they didn’t understand a certain concept or were unable to solve problems.Programming related Projects and Home Assignments given to us in our class were solved by me with 10 -15 minutes after the class.

Then there was a programming competition in our university, i was ecstatic about it.I paired up with a very close friend of mine for the competition.

We were able to win, but all the problems were solved by that close friend of mine , i was almost shocked by the speed at which his mind worked, writing correct code before even my mind fully analysed those problems.
Well after that i got really depressed and thought why was i not able to determine or build that logic as quickly as him.

I have solved the towers of hanoi and problems like that but nowadays i seem to be at a standstill unable to write quality code, unable to think correctly.Any help in this regard will be appreciated.

Iphone:Downloading game levels(or extra feautes in general)

Sunday, August 22nd, 2010

I have a game where each level has its own logic,so its a module with level -specific code and graphics.
I am confused on whether its possible to download and integrate dynamically in the app each level.
Searching the web , i found that nsbundle is the standard way for performing this task,however loadable bundles are not supported in iOS.
Is there a way to approach such a task,and if yes ,its not clear to me if its even permitted by Apple

Lowest Common Ancestor of Binary Tree(Not Binary Search Tree)..

Sunday, August 22nd, 2010

I tried working out the problem using Tarjan’s Algorithm and one algorithm from the website: http://discuss.techinterview.org/default.asp?interview.11.532716.6, but none is clear. Maybe my recursion concepts are not build up properly. Please give small demonstration to explain the above two examples. I have an idea of Union Find data-structure.

It looks very interesting problem. So have to decode the problem anyhow. Preparing for the interviews.

If any other logic/algorithm exist, please share.

Best Practices: when to make the db connection?

Sunday, August 22nd, 2010
I’ve programmed in other languages but am quite the noob in PHP. So I see a lot of tutorials and tips about putting the database connection code into a separate file that you include at the start of all your scripts. If you’re doing an insert, the logic looks like this:

Code:

include (dbconnect.inc)
if formSubmitted = yes
  validateData
  if no validationError
    insertRecord
  .
.
HTML FORM GOES HERE


But that means that the script connects to the database over and over, even when no record is inserted. Shouldn’t the database connection happen closer to when the database is actually accessed? I’m thinking like this:

Code:

if formSubmitted = yes
  validateData
  if no validationError
    include (dbconnect.inc)
    insertRecord
  .
.
HTML FORM GOES HERE


That way, if the user is just refreshing the screen or clicking OK without entering data, the script isn’t hitting the server with request after request.

Hide and display usercontrols in the same page

Sunday, August 22nd, 2010

In my web application , I have an online application form which contain 4 sections.When I click next button in the first usercontrol for the first section,i need to display the second usercontrol for the next section. When i tried, first loaded usercontrol only applying the styles.

Can anyone tell me, what logic i need to use here to display each usercontrol on the next button click. How to save the values of each usercontrol on the next button click?

Thanks in advance

How are embedded user interfaces controlled

Saturday, August 21st, 2010

How do they code the logic of a user interface running on embedded hardware. Microwave ovens, flat screen televisions, portable DVD players and even a digital watches these days have complex user interfaces. Are there tools / frameworks available to remove all the dirty work or are the developers using IF ELSE kind of constructs.

I’m not asking for user interface toolkits in the sense of QT or WxWidgets. I am more interested in knowing if there are frameworks to handle the logic behind the controls.

if (mTemperature > maxTemperature)
    temperatureDialControl.Enabled = false;

System.Windows.Media.Animation.AnimationTimeline)’ is inaccessible due to its protection level

Saturday, August 21st, 2010

Hi I am trying to programmatically control a WPF animation but am getting the error above, could someone help with the error – not very familiar with c# – thanks

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Animation;

namespace WpfApplication10
{
///
/// Interaction logic for Window1.xaml
///

public partial class Window1 : Window
{
    public Window1()
    {
        InitializeComponent();
    }
       AnimationClock clock;
       void StartAnimation()
    {
        DoubleAnimation animate = new DoubleAnimation();
        animate.To = 300;
        animate.Duration = new Duration(TimeSpan.FromSeconds(5));
        animate.RepeatBehavior = RepeatBehavior.Forever;
        clock = animate.CreateClock();
        test.ApplyAnimationClock(Ellipse.WidthProperty, clock);
    }
    void PauseAnimation()
    {
        clock = new AnimationClock();
        clock.Controller.Pause();
    }
    void ResumeAnimation()
    {
        clock.Controller.Resume();
    }

    private void button1_Click(object sender, RoutedEventArgs e)
    {
        PauseAnimation();
    }

   }

}

Need suggestions for an Applied AI project

Saturday, August 21st, 2010

I have a course in my current semester in which I’m required to do a project on application of AI. I have decided to do this on game AI. I have 2 basic ideas: implementing an FPS bot(s) or implementing soccer AI.

I’m quiet a noob at AI right now, I’ve implemented basic pathfinding algos (A*, etc), and have studied about Finite state machines, some First Order logic, basic Neural Network stuff(Backpropagation ALgo), and am currently doing a course on Genetic Algorithms.

Our main focus is on the bot right now. Our plans include:

  • Each ‘bot’ would be implemented using a Finite State Machine (FSM), which would contain the possible states the bot could have; & the rules for the action/state changes that are going to take place when it receives an input.
  • In bot group movement, each bot would decide whether to strike, ways to strike; based on range, number of bots, existing fights using Neural Networks.
  • By using genetic algorithms the opponents next move could be anticipated based on repetitive moves.

Although I’ve programmed a few 2d games till now in my free time (like pacman, tetris, etc), I’ve never really gone into the 3d area. We will most probably be using a 3d engine.

We want to concentrate most of our energy on the AI part. We would like not to be bothered with unnecessary details about the animation/3d models, etc. For example, if we could find a framework which has functions like Moveright() which just moves the bot to the right, it would be really awesome.

My basic question is : is it too ambitious to go about it in the way we have planned, considering the duration of the project is abour 3 months? Should we go 3d and use a 3d game engine? is it easy to use such engines, if you have no experience with them before? If yes, what kind of engine would be suitable to our project?

I came accross another idea, given in the book AI Game programming by example, where the player would have a top down view of the bots. Would that way be more appropriate?

Thanks .. sorry about the length of the question .. it’s just that my problem is a bit too specific.

gtk logic behind treeviewcolumns needing cell renderers

Saturday, August 21st, 2010

From what I understand about GTK, if I have a TreeView, I can’t just use any widget I want to display information about a column. For text, you need a gtk.CellRendererText. For toggle buttons, a gtk.CellRendererToggle. For anything else, it seems you have to implement yourself, which, from a sample one for buttons that I saw, doesn’t look straightforward.

Firstly, is this the case? Is there an easy way to set up whatever widget you want to be used to display some text? If not, then why is it implemented this way? If I were designing GTK i would just create some sort of system where when a row was added and when some data model information changes, user-specified callbacks would be called which would add the appropriate widget or change it, respectively.