Wednesday, June 30, 2010

How can I get the program's output from GDB/MI?

Programmer Question

I'm trying to understand GDB's MI interface in order to write a basic frontend for it, but there's one thing that's confusing me. According to the documentation, any output from the running target is prepended with "@", but when I run a program on my own, the output from the program being debugged is not prepended with anything. Is GNU simply lying, or is there a way to retrieve the output that I'm not aware of?



Find the answer here

Should an object be created in an Unhealthy State? Passing from Create controller to View

Programmer Question

Hi



What are the advantages of passing a blank object eg Client from the controller?



public ActionResult Create()
{
Client client = new Client();
return View(client);
}

//
// POST: /Client/Create
[HttpPost]
public ActionResult Create(Client clientToAdd)
{
try
{
clientRepository.Insert(clientToAdd);
return RedirectToAction("Index");


As opposed to:



 public ActionResult Create()
{
return View();
}

//
// POST: /Client/Create
[HttpPost]
public ActionResult Create(Client clientToAdd)
{
try
{
clientRepository.Insert(clientToAdd);
return RedirectToAction("Index");


The reason being is that: Should an object (eg the Client) be created in an 'unhealthy' state ie blank?



Cheers



Dave



Find the answer here

How should I organize my Java GUI?

Programmer Question

I'm creating a game in Java for fun and I'm trying to decide how to organize my classes for the GUI. So far, all the classes with only the swing components and layout (no logic) are in a package called "ui". I now need to add listeners (i.e. ActionListener) to components (i.e. button). The listeners need to communicate with the Game class.



Currently I have:
Game.java - creates the frame add panels to it



import javax.swing.*;
import ui.*;

public class Game {

private JFrame frame;
Main main;

Rules rules;

Game() {
rules = new Rules();

frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
main = new Main();
frame.setContentPane(main.getContentPane());
show();
}

void show() {
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}

public static void main(String[] args) { new Game(); }

}


Rules.java - game logic



ui package - all classes create new panels to be swapped out with the main frame's content pane
Main.java (Main Menu) - creates a panel with components



Where do I now place the functionality for the Main class? In the game class? Separate class? Or is the whole organization wrong?



Thanks



Find the answer here

what's the point of a hash if it can be easily decrypted?

Programmer Question

i asked this question:
http://stackoverflow.com/questions/3143693/working-with-huge-spreadsheet



and got a great answer and i followed the advice. i used this:
http://splinter.com.au/blog/?p=86



and i hashed about 300,000 different elements in a column in an excel spreadsheet



since you can do:



=SHA1HASH('The quick brown fox jumps over the lazy dog')


And you'd get back:



2fd4e1c67a2d28fced849ee1bb76e7391b93eb12


couldnt you go backwards as well?



im saying if it encrypts the same text the same way every single time, what is the point?



if you do know the hash algorithm, is it possible to go backwards?



Find the answer here

jQuery $('#mydiv').css('top','500'); not working

Programmer Question

Hello, I have this:






With:



#mydiv{ position:relative; }


When I execute:



$('#mydiv').css('top','500');


Is not working, I'm not getting errors at all.



Basically what I need to do is move (not animate) that DIV 500px up, is there any other way to do it?



Find the answer here

Tuesday, June 29, 2010

Using standard refresh button

Programmer Question

I'm trying to display a small refresh button using UIButton in a standard UIView using the refresh icon built into UIKit. If I use an UIBarButtonItem it can be created as a refresh button, but I've had no luck in using this icon in other places.



So far I've tried to "steal" the refresh image of a UIBarButtonItem using the code below, but the image returned is nil:



UIBarButtonItem *temp = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:nil action:nil];
self.refreshButton.imageView.image = temp.image;
[temp release];


Any suggestions, or do I have to provide a refresh image myself?



Find the answer here

Drupal - add form element on successful submission

Programmer Question

In a Drupal custom module, I want to make $form['link_wrapper'] conditional on a successful submission of the form but this is not a very successful way of doing this. Can anyone suggest better approach.



function my_function_my_form($form_state){

//echo "-" . $form_state['post']['op'] ."-";
//die();

global $base_root;
$form = array();

$form ['query_type'] =array (
'#type' => 'radios',
'#title' => t('Select from available Queries'),
'#options' => array(
"e_commerce_orders" => t("Query1"),
"new_orders" => t("Query2"),
"cancelled_orders" => t("Query3")),
'#required' => TRUE,
);


// only show link when submitted
if($form_state['post']['op'] == 'Submit')
{
$form['link_wrapper'] = array(
'#prefix' => '
',
'#value' => l("Click to View file"),
'#suffix' => '


',
);
}

// add submit button
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'));

return $form;
}


Find the answer here

Paperclip and S3 -- how can I detect and handle problems?

Programmer Question

I recently implemented Paperclip and S3 in my app. The integration was really easy, the performance of S3 is great, w00t.



But it seems like occasionally, uploading a file doesn't work. This happens while saving the model -- so I'm pretty certain it's happening somewhere in the guts of Paperclip.



First of all, I'd appreciate any pointers or tips on debugging what's going on here.



But at a higher level -- even if I nail down all the bugs, I need to be able to detect problems in production and tell the user "sorry, uploading didn't work, try again". As it is now, the thing just hangs, and there isn't anything else I can do from the controller.



I can go poking around in the guts of paperclip, but wanted to see if there was anything I was missing.



Find the answer here

How do you get an iphone MPMoviePlayer video's total time?

Programmer Question

I just want to figure out how to get a video's total time in seconds. Is there video metadata that loads or something?



Find the answer here

Saturday, June 26, 2010

SAS career - where to get SAS training?

Programmer Question

I used to work as a Business Systems Analyst in the Financial Services industry. I've been looking for a career with better growth potential and more options in terms of variety of jobs, so I'm planning to switch to a SAS analyst position. I realize I need to learn SAS programming for this, and so I've been looking for institutes / organizations that offer SAS training.



I took a 3-day training session (SAS Programming Essentials) from SAS institute, but I realized that was not enough to help me practice SAS on a day-to-day basis. I then bought the SAS Learning Edition software and a couple of books, but I still feel I need somewhat of a classroom / collaborative environment to stay on track.



Are there any training classes that offer SAS programming training? So far, I only know of SAS institute, and that is pretty expensive, besides, 3 days doesn't really help (especially since I do not have a programming background).



Any input is appreciated.



Find the answer here

What exactly happens when you have final values and inner classes in a method ?

Programmer Question

I have came across many situation where I needed to pass value to an other thread and I founded out that I could do it this way, but I have been wondering how is it working ?



public void method() {
final EventHandler handle = someReference;

Thread thread = new Thread() {
public void run() {
handle.onEvent();
}
};

thread.start();
}


Edit: Just realise my question wasn't exactly pointing toward what I wanted to know. It's more "how" it works rather then "why".



Find the answer here

Simple client / server concept for .NET

Programmer Question

Hey everyone



I want to implement a simple cardgame in silverlight that can be played together via a server.



My question is, what concept for communication between client and server I should use.




  • Is it possible to use WCF to
    implement the server ? I guess no because its more like a dataprovider right ?

  • or do I need to use .NET Remoting ? Haven't read much about it yet, but
    I'm not quite sure if it is maybe out
    of date ?

  • Maybe there are newer approaches that I don't know yet ?



Maybe someone has a good tutorial link for the beginning that is not a bad coded sample from year 2002



Find the answer here

Flex-4 Beta2 : Background image stopped working

Programmer Question

AFter upgrading a project from Flex4 Beta1 to Beta2, I've found that the background-image style is no longer supported on Halo components.



Eg:






Note that jira issue SDK-23050 points out the following :




backgroundImage is not supported for Spark skins.




But this is not using a spark skin, just a standard Halo component.



Anyone got any ideas?



Find the answer here

More or less equal overloads

Programmer Question

The following code compiles in C# 4.0:



void Foo(params string[] parameters) { }
void Foo(string firstParameter, params string[] parameters) { }


How does the compiler know which overload you're calling? And if it can't, why does the code still compile?



Find the answer here

Friday, June 25, 2010

Lucene ChainedFilter vs. BooleanFilter

Programmer Question

I want to combine several filters in a Lucene search. It seems that there are two classes that can help with this: ChainedFilter and BooleanFilter.



ChainedFilter is a contributed class, and has been around for longer. It supports AND, OR, NOT, and XOR.



BooleanFilter is a newer, main-line class. It supports the unusual "Should", "MustNot", and "Must" operators.



How do I decide which one to use?



Find the answer here

Thursday, June 24, 2010

Customizing Iphone Keyboard

Programmer Question

Is there a way to customize the iphone keyboard? Say I want the number pad with a comma button and a period button added to it.



Find the answer here

Visual Studio does not generate app.config content when "add service reference"

Programmer Question

When I add a web service by using "add service reference" in the console app, the app.config does not generate the configuration. How do I generate this app.config with a specific wsdl? Thanks!



Find the answer here

database updates not showing up immediately

Programmer Question

hi,
i have a php application driven by mysql data. ie. when a user rates on a product .it gets stored in DB and the page gets refreshed. then also his ratings donot get showed up until cache is cleared. i have put the cache control code also .



header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past


any tweaks that i have to do for this?



Find the answer here

Documenting PHP Code - does it hurt performance?

Programmer Question

I can't believe anyone would normally object to documentation and comments, but whats the best practice (and practical) for doing so in PHP?



In JavaScript, you can document your code and then run a minimizer to produce a production version of your code for use. What about in PHP, does the extra lines of text affect performance? Should you keep your documents in another file (which I imagine might be important for API's and frameworks but would slow down your development)?



Find the answer here

Wednesday, June 23, 2010

converting bytes to int in Java

Programmer Question

I need to convert 2 bytes (2's complement) into an int in Java code. how do I do it?




toInt(byte hb, byte lb)
{

}


Find the answer here

Is there a book that explain the algorithm used by regular expression functions?

Programmer Question

Is there a book that explains the algorithm used by the regular expression functions, and optionally shows an implementation in some high level language?



Find the answer here

Bug Sending Contacts to Voicemail on HTC Android Phones

Programmer Question

Hi,



I've developed the app Group to Voicemail for Android and have come across an interesting issue that only occurs on HTC phones:



When I programatically send a Contact to voicemail (using the SEND_TO_VOICEMAIL field for ContactsContract.Contacts), it works as expected. However, when I set that field back to '0' (to not send that Contact to voicemail anymore) the check box is unchecked for that Contact to send them to voicemail, but calls that come in still go to voicemail. The only way to actually put the change into effect is to reboot the phone (obviously not an acceptable solution for users) :)



Anyway, I've only seen this happen, and had reports from users that have HTC phones (Incredible and Evo). It works fine on the Motorola Droid as far as I can tell.



Any ideas?



Thanks,



Matt



Find the answer here

Python: Convert args to dict?

Programmer Question

How would I write a function that I can call like:



package(var1, var2, var3)


Edit: This syntax would be fine too:



package('var1','var2','var3')


Although the former would be preferred (fewer quotes to type).



And it would return a dict:



{'var1':var1, 'var2':var2, 'var3':var3}


Is this possible? Or is the variable name lost when passed into a function with a signature like package(*args)?



Edit: Just like PHP's compact function.



Find the answer here

Does AOL OpenID allow account ID spoofing?

Programmer Question

When authenticating to any site (including stackoverflow) with an AOL OpenID, it appears that you can specify any fake username in the form, then enter a valid AOL username/password on the AOL OpenID site, and the target web site (e.g. stackoverflow) will be told that authentication succeeded, but with the FAKE username.



My question is, is this the way OpenID is supposed to work, or is AOL doing something wrong, or am I just misunderstanding what's going on?



I came across this on my own project, and after hours of debugging, decided to see if I could reproduce it on a well established site.



I went to stackoverflow, clicked "log in", clicked the AOL logo, and entered "asdf" as the username. It took me to the AOL OpenID site, where I entered my true AOL username/password. I was then returned to stackoverflow, which said:



Confirm OpenID
This OpenID does not have an account on Stack Overflow yet:
http://openid.aol.com/asdf
Create New Account


I clicked "Create" and there's now an "http://openid.aol.com/asdf" account on stackoverflow (sorry! I tried to delete it but don't see how).



This doesn't seem right... and in my app, it means that the identifier I'm using for my users may not be accurate/valid... it might even be possible for someone unscrupulous to come along, enter someone elses AOL OpenID username/URL into a login box, authenticate with a valid AOL username/password, and then gain access to the other account on the target web site?



On OpenID provider sites that return a unique identifier, like Google or Yahoo, this doesn't seem to be an issue.



Thanks for any suggestions... this is driving me crazy on my development effort...



Find the answer here

Tuesday, June 22, 2010

how to add a youtube video to / with jMediaelement

Programmer Question

Does anybody uses jMediaelement (http://protofunc.com/jme/index.html) for HTML5 videos? I am wondering how to display a youtube video. I see there's a demo on the homepage of jMediaelement, but the source code is not provided (clever!). Any idea how to? Thanks



Find the answer here

BASH: Test whether string is valid as an integer?

Programmer Question

Hello All,



I'm trying to do something common enough: Parse user input in a shell script. If the user provided a valid integer, the script does one thing, and if not valid, it does something else. Trouble is, I haven't found an easy (and reasonably elegant) way of doing this - I don't want to have to pick it apart char by char.



I know this must be easy but I don't know how. I could do it in a dozen languages, but not BASH!



In my research I found this:



http://stackoverflow.com/questions/136146/regular-expression-to-test-whether-a-string-consists-of-a-valid-real-number-in-ba



And there's an answer therein that talks about regex, but so far as I know, that's a function available in C (among others). Still, it had what looked like a great answer so I tried it with grep, but grep didn't know what to do with it. I tried -P which on my box means to treat it as a PERL regexp - nada. Dash E (-E) didn't work either. And neither did -F.



Just to be clear, I'm trying something like this, looking for any output - from there, I'll hack up the script to take advantage of whatever I get. (IOW, I was expecting that a non-conforming input returns nothing while a valid line gets repeated.)



snafu=$(echo "$2" | grep -E "/^[-+]?(?:\.[0-9]+|(?:0|[1-9][0-9]*)(?:\.[0-9]*)?)$/")
if [ -z "$snafu" ] ;
then
echo "Not an integer - nothing back from the grep"
else
echo "Integer."
fi


Would someone please illustrate how this is most easily done?



Frankly, this is a short-coming of TEST, in my opinion. It should have a flag like this



if [ -I "string" ] ;
then
echo "String is a valid integer."
else
echo "String is not a valid integer."
fi


Thanks.



Find the answer here

How to display a students grade points correctly using PHP & MySQL?

Programmer Question

So far I think I'm doing it right but I cant seem to display the grade_points correctly here is what I'm display below. How can I fix it so that my code will display the grade_points correctly?




OUTPUT DATA



Here is my current output:



user_id Array ( [1] => 1 [3] => 2 )
rank Array ( [0] => 1 [1] => 3 )
grade_points Array ( [0] => [1] => )
users Array ( [0] => 3 [1] => 2 )
the rank of user_id 3 is #2


And here is what I want to output:



user_id Array ( [1] => 1 [3] => 2 )
rank Array ( [0] => 1 [1] => 3 )
grade_points Array ( [0] => 8 [1] => 5 )
users Array ( [0] => 3 [1] => 2 )
the rank of user_id 3 is #2






PHP & MySQL CODE



Here is my PHP & MySQL code.



$i = 1;

$u = array();
$user = array();
$rank = array();
$gp = array();

$dbc = mysqli_query($mysqli,"SELECT SUM(grade_points) as p, grades.grade_points, assignment_grades.*, COUNT(*) as u, users_assignment.user_id
FROM users_assignment
LEFT JOIN grades ON users_assignment.user_id = grades.letter_grade
LEFT JOIN assignment_grades ON grades.id = assignment_grades.grade_id
GROUP BY users_assignment.user_id
ORDER BY p DESC");


if (!$dbc) {
print mysqli_error($mysqli);
} else {
while($row = mysqli_fetch_array($dbc)){
$u[$row['user_id']] = $i++;
$rank[] = $row['user_id'];
$user[] = $row['u'];
$gp[] = $row['p'];
}
}

echo 'user_id '; print_r($u); echo '
';
echo 'rank '; print_r($rank); echo '
';
echo 'points '; print_r($gp); echo '
';
echo 'users '; print_r($user);

echo "the rank of user_id 3 is" . $u[3];






MySQL TABLES



CREATE TABLE assignment_grades ( 
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
grade_id INT UNSIGNED NOT NULL,
users_assignment_id INT UNSIGNED NOT NULL,
PRIMARY KEY (id)
);



CREATE TABLE grades (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
letter_grade VARCHAR NOT NULL,
grade_points FLOAT UNSIGNED NOT NULL DEFAULT 0,
PRIMARY KEY (id)
);



CREATE TABLE users_assignment (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
user_id INT UNSIGNED NOT NULL,
assignment_content LONGTEXT NOT NULL,
grade_average VARCHAR DEFAULT NULL,
PRIMARY KEY (id)
);






TABLE DATA



assignment_grades



id      grade_id        users_assignment_id
15 15 35
16 16 35
17 17 33


grades



id      letter_grade        grade_points
15 C+ 3
16 A+ 5
17 A+ 5


users_assignment



id      user_id     assignment_content      grade_average
32 1 some content NULL
33 1 some content A+
34 3 some content NULL
35 3 some content B+
36 1 some content NULL


Find the answer here

How to get the results with count 0 too with Hibernate?

Programmer Question

i am using the Projections.rowCount() function on hibernate, but it will only return the counts greater than 0, i need to get the list with the 0 count too.



Find the answer here

Which features make a laptop fast for Java development?

Programmer Question

I remember, earlier CPU speed was the most important thing. But today I am confused. Which features determine the most if a laptop can smoothly run Eclipse with lots and lots of projects open?




  • CPU clock speed vs number of cores?

    • What is faster, 4 cores at 1 Ghz or 2 cores at 2,3 Ghz?

    • Which configuration needs more power = less battery life?


  • memory size? Will more than 4GB help a lot?

  • hard disk type -- is a SSD really that much faster? Which type?

  • are there laptops without DVD/CD drive that are still super-fast?

  • I'm looking for laptops with at least 1400 x 1050 pixels

  • Have anti-glare-displays died?

  • Can we get non-extra-wide displays?



Bonus question: What website compares laptops along these features?



Find the answer here

Sunday, June 20, 2010

MATLAB how to use FIND function with IF statement

Programmer Question

This question is related to http://stackoverflow.com/questions/3071558/matlab-how-to-merge-data



how to use the FIND function with IF statement? e.g. if I have this data:



20  10  1
20 11 1
20 15 1
23 10 1
23 10 1
23 12 0


Rule 1:
Data of column 3 must be 1.



Rule 2:
If n is the current index of column 1, if n equal n-1 (20=20) of column 1, data of column 2 of index n and n-1 is merged.



20  21  0
20 15 0
20 0 0
23 20 0
23 0 0
23 12 0

fid=fopen('data.txt');
A=textscan(fid,'%f%f%f');
code=A{1};
time=A{2};
mark=A{3};
fclose(fid);


Find the answer here

Friday, June 18, 2010

Is there a benefit to storing an object in a variable before calling a method on it?

Programmer Question

Example 1:



SomeObject someObject = new SomeObject();
if (someObject.Method())
{
//do stuff
}
//someObject is never used again


vs



Example 2:



if (new SomeObject().Method())
{
//do stuff
}


Is there any benefit to using the first method over the second, or vice versa?



Find the answer here

Thursday, June 17, 2010

Eclipse Galileo - Open file dialog path

Programmer Question

How do I get Eclipse to open files from the last directory I opened from, after re-starting Eclipse? It always reverts to my Windows profile directory.



Find the answer here

Categories in static library for iPhone device 3.0

Programmer Question

I have categories in my static library. Any application developer should set -ObjC flag to "Other Linker Flags" to use my static library properly. It works fine for iPhone device/iPhone Simulator 2.x and iPhone Simulator 3.0. But it crashes for iPhone device 3.0. As written in this article it is new linker bug. They suggest to use one more linker flag: -all_load. But when I add this flag, build fails too, because there are duplicate symbols.



How to use categories in static libraries for iPhone device 3.0? Any suggestions?



Find the answer here

Django: How can I add weight/ordering to a many to many relationship?

Programmer Question

I'm having Pages with TextBlocks on them. Text Blocks may appear on different pages, pages may have several text blocks on them. Every page may have these blocks in an ordering of it's own.
This can be solved by using a separate through parameter. Like so:



class TextBlock(models.Model):
title = models.CharField(max_length=255)
text = models.TextField()

class Page(models.Model):
textblocks = models.ManyToManyField(TextBlock, through=OrderedTextBlock)

class OrderedTextBlock(models.Model):
text_block = models.ForeignKey(TextBlock)
product_page = models.ForeignKey(ProductPage)
weight = models.IntegerField()

class Meta:
ordering = ('weight',)


But I'm not very enthousiastic about the violations of DRY for my app. (There's a lot of ordered ManyToMany relations). Is there a recommended way to go about this?



Find the answer here

Idiomatic approach for structuring Clojure source code

Programmer Question

I'm interested in how people structure their Clojure source code.



Being used to Java, I'm pretty familiar with the paradigm of one class per source code file, bundling all the data and method definitions with appropriate comments and annotations etc.



However Clojure offers a lot more flexibility, and I'm not sure how I should structure my project (likely to end up as a medium sized app, maybe 5,000 lines with three or four distinct subsystems)



In particular I'm wrestling with:




  • What guidelines should I use to determine whether code should be in a single namespace vs. separated out into different namespaces?

  • Should each protocol/datatype have it's own namespace + source file with associated set of functions?

  • When should I require vs. use other namespaces?



Find the answer here

How to iterate through luabind class (in lua or in c++)?

Programmer Question

How to iterate through luabind class (in lua or in c++)?



class 'A'

function A:__init()
-- Does not work
-- self is userdata, not a table
for i, v in pairs(self) do
end
end


Thanks



Find the answer here

Wednesday, June 16, 2010

ASP.NET Hosting and routing

Programmer Question

Is it possible to host 2 asp.net projects off one ip address? I don't have a domain name just an ip number. I'm running IIS7.



The first project runs and displays fine over the web by simply typing in the ip address into the browser but I'm having trouble accessing the second.



Currently both projects have virtual directories in IIS7.



Help is greatly appreciated.



Thx



Find the answer here

Identifying memory leaks in C++

Programmer Question

I've got the following bit of code, which I've narrowed down to be causing a memory leak (that is, in Task Manager, the Private Working Set of memory increases with the same repeated input string). I understand the concepts of heaps and stacks for memory, as well as the general rules for avoiding memory leaks, but something somewhere is still going wrong:



while(!quit){
char* thebuffer = new char[210];
//checked the function, it isn't creating the leak
int size = FuncToObtainInputTextFromApp(thebuffer); //stored in thebuffer
string bufferstring = thebuffer;
int startlog = bufferstring.find("$");
int endlog = bufferstring.find("&");
string str_text="";
str_text = bufferstring.substr(startlog,endlog-startlog+1);
String^ str_text_m = gcnew String(str_text_m.c_str());
//some work done
delete str_text_m;
delete [] thebuffer;
}


The only thing I can think of is it might be the creation of 'string str_text' since it never goes out of scope since it just reloops in the while? If so, how would I resolve that? Defining it outside the while loop wouldn't solve it since it'd also remain in scope then too. Any help would be greatly appreciated.



Find the answer here

Ext.form.combobox inside ext.window displays values at top left of screen

Programmer Question

I have a combobox inside of a ext.panel, inside of an ext.window. When I click the down arrow to show the possible SELECT options, the options pop up at the top-left of the browser window, instead of below the SELECT box. The funny thing is if I attach the drugDetailsPanel (see code below) to a div on the page (instead of inside an ext.window), the combobox works correctly. This also happens when I change ext.panel to ext.form.formpanel, by the way.



Any ideas?



My code:



drugDetailsPanel = new Ext.Panel({
layout:'form',
id:'drug-details-panel',
region:'center',
title:'Drug Details',
height:200,
collapsed:false,
collapsible:false,
items:[
new Ext.form.ComboBox({

fieldLabel:'What is the status of this drug?',
typeAhead:false,
store:drugStatusStore,
displayField:'lookup',
mode:'remote',
triggerAction:'all',
editable:false,
allowBlank:false,
emptyText:'Select a status..',
name:'/drug/drug-status',
id:'drug-status'
})

]
});

newDrugWindow = new Ext.Window({
title: 'Add Drug',
closable:true,
width:650,
height:650,
//border:false,
plain:true,
layout: 'border',
items: [drugDetailsPanel],
closeAction:'hide',
modal:true,
buttons: [
{
text:'Close',
disabled:false,
handler: function(){
newDrugWindow.hide();
}
},
{
text:'Save Drug',
handler: function(){
newDrugDialog.hide();
}
}]
});


Find the answer here

filename and line number of python script

Programmer Question

Hello everyone,



How can I get the file name and line number in python script.



Exactly the file information we get from an exception traceback. In this case without raising an exception.



Find the answer here

Where can I trade on the Stock Market via API?

Programmer Question

I have made an interactive stock trading system, and want to try it out with real money. Can anyone suggest a place where I could hook my system up to an API and make trades? Ideally, it would also have a testing area where I could test it with their api for a while, before going live.



Find the answer here

Tuesday, June 15, 2010

Objective-C Array/List Question

Programmer Question

What is the best practice, even in general programming, when you have an undefined, possibly infinite, amount of items that you need in an array but don't have defined bounds. Can you define an endless array in objective c that you can keep pushing items onto, like other lanaguages have a list item.



Thanks for any help.



Find the answer here

Get number of posts in a topic PHP

Programmer Question

How do I get to display the number of posts on a topic like a forum. I used this... (how very noobish):



function numberofposts($n)
{
$sql = "SELECT * FROM posts
WHERE topic_id = '" . $n . "'";

$result = mysql_query($sql) or die(mysql_error());
$count = mysql_num_rows($result);

echo number_format($count);
}


The while loop of listing topics:















Although it is a bad method of doing this... All I need is to know what would be the best method, don't just point me out to a website, do it here, because I'm trying to learn much. Okay? :D



Thanks.



Find the answer here

How to convert RGB to BGR?

Programmer Question

This is probably easy, but I'm trying to convert from a source which provides colors in RGB strings to an output in BGR strings in Java. I've been busting my brain and time on shifting and Long.decode and Long.toHexString.



Feel free to also throw alpha values in there (RGBA -> ABGR), though I think I can extend the principles.



Find the answer here

Can I move my asp.net mvc app into microsoft cloud?

Programmer Question

without making a lot of changes. Did anyone try it? Are there any known patterns to work with for cloud computing using Azure platform.



Find the answer here

Selling upper management on converting to ASP.net from Classic ASP

Programmer Question

A client of mine has an application written in Classic ASP and COM+. The managers are interested in migrating it to ASP.net MVC but they have to convince the CIO that it is a good move. The old app still works OK, other than the fact that no one at the company can maintain it. How can we sell upper management on converting to ASP.net from Classic ASP? Thanks in advance!



Find the answer here

Monday, June 14, 2010

rename keys in a dictionary

Programmer Question

i want to rename the keys of a dictionary are which are ints, and i need them to be ints with leading zeros's so that they sort correctly.



for example my keys are like:



'1','101','11'


and i need them to be:



'001','101','011'


this is what im doing now, but i know there is a better way



tmpDict = {}
for oldKey in aDict:
tmpDict['%04d'%int(oldKey)] = aDict[oldKey]
newDict = tmpDict


Find the answer here

should autocomplete="off" be used for all sensitive fields?

Programmer Question

What are your thoughts about this issue in regards to an e-commerce environment? Do you think it is wise to turn autocomplete off on all sensitive input fields such as passwords (for log in areas), or, will this just inconvenience the client?



thank you



Find the answer here

SQL Server Replication between availability zones on EC2

Programmer Question

I was curious if anyone has had any experience doing this and what the approach and results were. We're currently investigating replication between availability zones to maximize uptime.



Has anyone done this with success? Any guidelines or potential problems you could share with the community?



Find the answer here

Am I supposed to store hashes for passwords?

Programmer Question

User System and Passwords: I was looking through MD5 stuff, and I am wondering what is the normal/good practice for passwords. Right now, I think people super encrypt the passwords and store the hashes. If so, how does password checking work? I just have the input password go through the encryption process again and then check the hash with the stored one, correct?



This question may contradict the above, but should my salt ever be a randomly generated value? If so, when may it be useful?



Edit: Other than passwords, in a user system, what else should be encrypted as a good practice? Do they encrypt usernames or anything else?



2nd Edit: What is a one-way hash? I mean, technically, can I not reverse engineer my source code? Maybe this is a bad question because I do not know much about one-way hashing.



Find the answer here

Minimum distance between two rotated rectangles with different angles

Programmer Question

How can I calculate the minimum distance between two rectangles? It is easy for rectangles which have no angles(0 degrees) but for rotated rectangles with any different angles I do not know how to do it.. Do you recommend any way?



WhiteFlare



Find the answer here

LinkWithin

Related Posts with Thumbnails