code

Why can't I use a constant in a php object?

Why doesn't this work? define("STR_TEST", "qwerty"); class Test { public $arrTest = array( "test"=>"Bla bla bla ".STR_TEST ); } $objTest = new Test(); print($objTest->arrTest["test"]); ...

Python 2.6 and 3.1.1, earlier version compatibility

I ordered three books to start teaching myself Python - a beginning programming book, a computer science book that uses Python for all of its code references, and a book on Python network programming. Unfortunately, I was a little too quick on ordering them, because I hadn't noticed the version differences. The beginner book is for pytho...

Add code to html pages automatically

I need to add some code to the of several html contained in a folder on my desktop. How can i do that? I am using a prototyping tool (Axure) on Mac and I want to add some html meta tags to the generated pages. These pages can be overwritten every time I generate the prototype. What I need is a sort of script that I can launch after re-...

Is there any way i can make podcast application from iphone play my podcasts ? ( with code )

I'm doing an application who can play podcasts, but i feel more comfortable is the iphone default podcast application plays itself, instead of me having to handle them. Passing the url to the sharedApplication object , safari opens and starts playing it .. but i'd like to skip the user seeing safari .. is there any way ? Thanks. ...

Django - Tips to avoid repeating code in views

I'm moving from a PHP background into Django development via python, mostly for the sake of tackling a MVC (or MVT) that I feel makes the most sense, although in this pattern I've started to notice a lot of repeated code in my views. For example, when logged in I have information regarding the user that I would like to appear on every p...

A PHP regex to extract php functions from code files

I'm trying to make a PHP regex to extract functions from php source code. Until now i used a recursive regex to extract everything between {} but then it also matches stuff like if statements. When i use something like: preg_match_all("/(function .(.))({([^{}]+|(?R))*})/",$this->data,$matches2); It doesn't work when there is more than 1...

Code Generation(based on templates) for Cocoa

Hi, I have written a library for iPhone which is based upon some object models (whose definitions I get via XML). Now I have one implementation for a sample model ready but to make the code library generic I want to write an application where I can templatize the code and provide placeholders for data model specific points. Is there an...

IoC / Dependency Injection - please explain code versus XML

I understand basically how IoC frameworks work, however one thing I don't quite get is how code-based config is supposed to work. With XML I understand how you could add a new assembly to a deployed application, then change the config in XML to include it. If the application is already deployed (i.e., compiled in some form) then how can ...

Ninject - initialise objects

Hi guys, I am new to ninject, I am wondering how I can run custom initizlisation code when constructing the injected objects? ie. I have a Sword class which implements IWeapon, but I want to pass an hit point value to the Sword class constructor, how do I achieve that? Do I need to write my own provider? A minor question, IKernel kerne...

Code Trivia: optimize the code for multiple nested loops

I came across this code today and wondering what are some of the ways we can optimize it. Obviously the model is hard to change as it is legacy, but interested in getting opinions. Changed some names around and blurred out some core logic to protect. private static Payment FindPayment(Order order, Customer customer, int paymentId) ...

How can I remove the head of a main function?

I am trying to move some code from a separate binary and have it inside my main program. Unfortunately I can't mimic the initialization variables for the main function. How can I create argc and argv by hand? Can someone give me some example assignments. since it looks like this: int main(int argc, char *argv[]) I figured I could a...

How can i optimize this c# code?

I have converted my Datatable to json string use the following method... public string GetJSONString(DataTable Dt) { string[] StrDc = new string[Dt.Columns.Count]; string HeadStr = string.Empty; for (int i = 0; i < Dt.Columns.Count; i++) { StrDc[i] = Dt.Columns[i].Caption; HeadStr += "\"" + StrDc[i] + "\"...

Drupal node reference

I am using two content types - test_parent & test_child In test_child there are two fields, both of type datetime And in test_parent there are two fields, week_no & 7 node references I am using node_save to save a new node. After saving a node of parent type, and then saving the node of child type, i want to update the node it into the ...

Making a app show inside a GUI in Java

Hello. I have one problem I've been dealing with for this week. You see, I'm new to Java, so that's probably it... Anyways, I've started a project out of pure curiosity. I had it done in Java, but in plain CMD-style, which is not very pretty. It calls one of my ten programs, chosen by the user using "Case". Eg.: If you type 1, it will ...

How to make a batch file edit a text file

I got the code Set objFS = CreateObject("Scripting.FileSystemObject") strFile = "C:\test\file.txt" Set objFile = objFS.OpenTextFile(strFile) Do Until objFile.AtEndOfStream strLine = objFile.ReadLine If InStr(strLine,"ex3")> 0 Then strLine = Replace(strLine,"ex3","ex5") End If WScript.Echo strLine Loop The str...

Need to skip newline char (\n) from input file

I am reading in a file into an array. It is reading each char, the problem arises in that it also reads a newline in the text file. This is a sudoku board, here is my code for reading in the char: bool loadBoard(Square board[BOARD_SIZE][BOARD_SIZE]) { ifstream ins; if(openFile(ins)){ char c; while(!ins.eof()){ for ...

A CSS code Or Any code to put text (saved in other server) into blogspot blog..???

I have a blog in blogspot. Step (1). Whenever any visitor visit my blogspot blog through Google, the search search string is tracked through a javascript and the search string is saved in another server (say serverX) Step (2). Now, when another visitor (human/Google Bot/Any downloader/etc..) visits my blog, he/she should be able to se...

How to run OpenGL code with out compiling?

So I have some openGL code (such code for example) /* FUNCTION: YCamera :: CalculateWorldCoordinates ARGUMENTS: x mouse x coordinate y mouse y coordinate vec where to store coordinates RETURN: n/a DESCRIPTION: Convert mouse coor...

how many types of code signing certificates do I need?

in Canada, website SSL certificates can be had for as low as US$10. unfortunately, code signing certificates cost about 10 time as much, one website mentions Vista compatibility ... this seems strange because my assumption is they must support XP, Vista, Windows 7, Server 2003, and Server 2008 or they would be useless. https://secure...

Flex code region?

Is there a way in flex (Flash Builder 4) to make regions like in c#, to group a part of the code allowing us to collapse it and see through our project more easily? In c# it's like: #region exammple // my funtions I want to group #endregion ...