Saturday, February 19, 2011

JavaScript: onMouseOver Event Not Working Properly With Other Events

Programmer Question

Hello,



I have a HTML webpage that contains a 15x15 table and I also have a small square div that follows the mouse when you press and hold the left mouse button on the div.



I have assigned an onmouseover event to the 15x15 table so that when the mouse hovers over a cell, a variable called "gridPlacement" is set the value of the unique id of the table cell the mouse hovered over.



The onmouseover event seems to work fine and instantly as soon as you hover over a cell the variable "gridPlacement" is set to the cell's id.



But when the onmousedown and onmousemove events are triggered (when the mouse presses and holds the left mouse button on the div I mentioned earlier), sometimes when you hover over a cell the variable "gridPlacement" isn't set, and sometimes you have to move your mouse over the cell a few times for it to work.



It seems the onmousedown and onmousemove events seem to have an impact on the onhover event on my 15x15 table.



Does anybody know why this happens and how I can work around this problem?



I hope you understand me, I've tried to explain my problem as best as I can.



Find the answer here

How can I detect window destruction from the main thread?

Programmer Question

Typically, the window procedure for a "main" window class would call PostQuitMessage in response to a WM_DESTROY message.



I would prefer to have the main thread decide when it wants to terminate based on the lifespan of the window(s) it creates. This way, whatever window class I choose to be the main window can have a generic window procedure that doesn't have PostQuitMessage in it.



while(GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);

if(msg.hwnd == hWnd && msg.message == WM_DESTROY)
{
PostQuitMessage(0);
}
}


The above is my attempt, but the WM_DESTROY message is never posted to the message queue, it seems to be internal to the window procedure.



Is there some way to accomplish this?



Find the answer here

Backbone.js versus Express versus Ext JS ...and JSPP?

Programmer Question

What are the pros and cons of Backbone.js, Express, Ext JS, and JSPP??



Find the answer here

Making similar app as already existing on App Store

Programmer Question

Hi,



Are there some restrictions for making an exact copy (with our own branding) of an app/game that is already there on App Store? i.e. copying the idea



Find the answer here

How to migrate MS access database to Oracle ?

Programmer Question

I am using SQL developer, but while capturing Models step executes, it gives me following error



oracle.xml.parser.v2.XMLError.flushErrors1(XMLError.java:323)



Can anyone either tell me how to fix this issue or help in with an alternate way to migrate the database.



Find the answer here

Thursday, February 17, 2011

Identifying memory-mapped files

Programmer Question

Hello,



I'm identifying parts of process's virtual memory using VirtualQuery. I identify regions taken by mapped files (MEM_MAPPED), but how to determine actual files (filenames) of files allocated there? I suppose it has something to do with MapView* family of APIs but cant figure it out exactly...



Find the answer here

Log into twitter?

Programmer Question

Ok, basically what I am trying to do is get a boolean if I have logged in or not. I am using the Twitter4j library and they gave me the following three things to look at.



http://twitter4j.org/en/code-examples.html



https://github.com/yusuke/sign-in-with-twitter/blob/master/src/main/java/twitter4j/examples/signin/SigninServlet.java



https://github.com/yusuke/sign-in-with-twitter/blob/master/src/main/java/twitter4j/examples/signin/CallbackServlet.java



I have no idea how to log in and get if I logged in successfully.



Thanks, and I have no code btw... all I did was basically copy code and try different things.



PS. On a separate note how do I learn how to use someone elses library?



Find the answer here

extracting paragraph in python using lxml

Programmer Question

I would like to extract paragraphs in html by python. I used lxml module but it doesn't do exactly what I am looking for.



print html.parse(url).xpath('//p')[1].text_content()

Here is the First Paragraph.

Here is the second Paragraph.

Paragraph Three."




I should add that, in different pages I have different number of paragraph, so would like to make a list and put paragraph into it after that.



Find the answer here

Python super method and calling alternatives

Programmer Question

I see everywhere examples that super-class methods should be called by:



super(SuperClass, instance).method(args)


Is there any disadvantage to doing:



SuperClass.method(instance, args)


TIA, Ian



Find the answer here

Java performance multi-core testing environment

Programmer Question

I am interested in learning as much as i can about tuning a multi-threaded java server on a multi-core machine. I wanted to write some test servers that i could use to test different scenarios. For example thread pool sizing. Unfortunately i don't have access to a large multi-core unix (linux or solaris) machine. I just have duo-core mac laptop.



Are there any good lease options for a dedicated, say 8 to 16 core machine, that i could distribute my java test servers?



Find the answer here

Wednesday, February 16, 2011

How to check if a parameter of an inline function is known at compile time?

Programmer Question

Hello,



I have a performance critical inline function. It generates some data, based on a parameter. I want the compiler to optimize the data generation for all invocations, where the parameter is known at compile-time. The problem is that I can't force the compiler to put the optimized data out of the stack to a static constant, since marking the data static would break the case when parameter is not a compile-time constant. Having constant data on the stack hurts performance. Is there a way to deduce (maybe using templates/boost::enable_if), that the parameter is a compile-time constant and choose appropriate implementation of the data generation?



Disclaimer



This question is not the same as How to use different overload of an inline function, depending on a compile time parameter?. This is more generic problem.



Find the answer here

Monday, February 14, 2011

Running a Unix Executable Objective-C file in Java (OS X)

Programmer Question

I've seen this question asked before and tried following the solutions posted. Unfortunately, they aren't working. I'm trying to make a simple Java program that can run a compiled Objective-C program (Unix Executable file) with an input parameter. Below are the attempts at Java I have tried that don't seem to be working:



String[] cmd = {"/bin/bash", fullFilePath, Param};
Runtime.getRuntime().exec(cmd);


This is generating a Processor error of 126 for "Command invoked cannot execute". I've tried other variations that don't work as well such as:



String[] cmd = {"/bin/bash fullFilePath \"Param\""};
String[] cmd = {"/usr/bin/open fullFilePath \"Param\""};


Any suggestions or ideas on how I can get this to work? I just need to run the compiled Objective-C program in Java with the parameter. I figured it wouldn't be this hard. Thanks in advance, and if you need more information just ask.



Find the answer here

What's a good Flask/Python/WSGI analog to the PHP Apache shared memory stores like apc_store/apc_fetch?

Programmer Question

I've done a couple of years of large-scale game server development in PHP. A load balancer delegates incoming requests to one server in a cluster. In the name of better performance, we began caching all static data (essentially the game world's model objects) on each of the instances in that cluster, directly in Apache shared memory, using apc_store and apc_fetch.



For a number of reasons, we're now beginning to develop a similar game framework in Python, using the Flask microframework. At first glance, this instance's memory store is the one piece that doesn't appear to translate directly to Python/Flask. We're presently considering running Memcached locally on each instance (to avoid streaming fairly large model objects over-the-wire from our main Memcached cluster.)



What can we use instead?



Find the answer here

Regular Expression Help

Programmer Question

Trying to match a strings in notepad++ with a regular expression.



The string I'm trying to match is formatted like this:



^*^1st Choice Housing. Inc~*~


The carets and tildes serve as the delimiters around the name.



Here's the regular expression I'm trying to use to match any string between the delimiters



\^\*\^([A-Za-z0-9-.]+)\~\*\~


Notepad++ says 0 matches. What is wrong with my regular expression?



If I use:



\^\*\^1st Choice Housing. Inc\~\*\~


It matches.



Find the answer here

Sunday, February 13, 2011

Python always thinks my string is the highest possible number

Programmer Question

if month == 1 or 10:
month1 = 0
if month == 2 or 3 or 11:
month1 = 3
if month == 4 or 7:
month1 = 6
if month == 5:
month1 = 1
if month == 6:
month1 = 4
if month == 8:
month1 = 2
if month == 9 or 12:
month1 = 5


This code always returns month1 5. I'm quite new at programming, what am I doing wrong? (I guess it involves the fact that 12 is the highest number. But == means equals right?)



Find the answer here

Saturday, February 12, 2011

Can't get 1440x900 resolution with GRUB2 although vbeinfo says it's available

Programmer Question

I'm trying to use GRUB2 in graphical mode with 1440x900 resolution, but the result is always garbled nonsense: the highest resolution I can get is 1280x800.



Word is from googling that long as vbeinfo lists a resolution, GRUB2 can use it. This doesn't seem to be true: vbeinfo says that 1440x900 is available but it doesn't work.



Testing it from the GRUB2 command line:



set gxfmode=1440x900
terminal_output gfxterm
# -> garbled nonsense

# back to trusty 640x480
terminal_output console


The graphics card is an Intel GM965.



Find the answer here

Is it a real date, February 29, 2011 is not a real date

Programmer Question

Does PHP have a function that could help find out if a date is a real date. For example February 29, 2011 is not a real because this year February has only 28 days. This is the sort of "real date" I'm asking about. Does PHP have something to help?



Find the answer here

Strengths of Shell Scripting compared to Python

Programmer Question

I tried to learn shell(bash) scripting few times but was driven away by the syntax. Then I found Python and was able to do most of the things a shell script can do in Python. I am now not sure whether I should invest my time in learning shell scripting anymore. So I want to ask



What are strengths of shell scripting that make it an indispensable tool as compared to Python?



I am not a system administration by profession but am interested in setting up Linux systems for home users and hence think learning shell scripting can become necessary.



Find the answer here

How do I add new buttons to an existing form?

Programmer Question

Hi,



I want to add new buttons to an existing form.



I want one button that, when clicked, saves the filled in values and reloads the same form.



The second button should save the filled in values and redirect to another form.



How do I add new buttons to the form and provide actions to take for each button?



Find the answer here

Problem in showing progress bar while executing insert statement in android

Programmer Question

Hi,



Problem in showing progress bar while executing insert statement in android. While
calling this try block its showing blank screen. Not even xml is called while executing this statement.



try {
while ((str = in.readLine()) != null) {
try {
db.execSQL(str);
} catch (Exception e) {

}
}


Thanks,
Yuvaraj



Find the answer here

Friday, February 11, 2011

WPF: How to select which Generic.xaml gets used?

Programmer Question

So I'm using a class library called MyControls.dll in this I have set up a few themes: Generic.xaml (where my controls appear regular), GenericBlue.xaml (where my controls appear blue), etc.



When I use this class library it picks Generic.xaml automatically. My question is can I somehow manually pick which GenericXXX.xaml to pick. I'd like some programs to appear a certain color, and some other programs to appear in another color, etc.



Find the answer here

Wednesday, February 9, 2011

How to link jsoncpp?

Programmer Question

How to link jsoncpp with a C++ program using g++? I tried "g++ -o program program.cpp -L/path/to/library/files -ljsoncpp", -ljson, -llibjsoncpp, but g++ keeps saying: "/usr/bin/ld: cannot find -lsomething"



Find the answer here

Store value from SELECT statement into variable

Programmer Question

How can i store the value from a SELECT MySQL statement into a PHP variable?
for example:



$myvariable = SELECT * FROM X WHERE id = X


Thanks



Find the answer here

USE MULTIPLE LEFT JOIN

Programmer Question

Is it possible to use multiple left join in sql query?
if not then whats the solution?



    LEFT JOIN
ab
ON
ab.sht = cd.sht


i want to add to atach one more query like this to it?
will it work?



    LEFT JOIN
ab AND aa
ON
ab.sht = cd.sht
AND
aa.sht = cc.sht


Wil this work?



Find the answer here

What would be the best (runtime performance) application or pattern or code or library for matching string patterns

Programmer Question

Hi,

I have been trying to figure out a decent way of matching string patterns. I will try my best to provide as much information as I can regarding what I am trying to do.



The simplest thougt is that there are some specified patterns and we want to know whic of these patterns match completely or partially to a given request. The specified patterns hardly change. The amount of requests are about 10K per day but the results have to pe provided ASAP and thus runtime performance is the highest priority.



I have been thinking of using Assembly Compiled Regular Expression in C# for this, but I am not sure if I am headed in the right direction.



Scenario:

Data File:

Let's assume that data is provided as an XML request in a known schema format. It has anywehere between 5-20 rows of data. Each row has 10-30 columns. Each of the columns also can only have data in a pre-defined pattern. For example:




  1. A1- Will be "3 digits" followed by a
    "." follwed by "2 digits" -
    [0-9]{3}.[0-9]{2}

  2. A2- Will be "1
    character" follwoed by "digits" -
    [A-Z][0-9]{4}



    The sample would be something like:





  

123.45
A5567
456EV
xxx





Rule File:



Rule ID    A1                 A2       
1001 [0-9]{3}.45 A55[0-8]{2}
2002 12[0-9].55 [X-Z][0-9]{4}
3055 [0-9]{3}.45 [X-Z][0-9]{4}


Rule Location - I am planning to store the Rule IDs in some sort of bit mask.

So the rule IDs are then listed as location on a string



Rule ID     Location (from left to right)  
1001 1
2002 2
3055 3


Pattern file: (This is not the final structure, but just a thought)



Column   Pattern                Rule Location
A1 [0-9]{3}.45 101
A1 12[0-9].55 010
A2 A55[0-8]{2} 100
A2 [X-Z][0-9]{4} 011


Now let's assume that I run the SOMEHOW (not sure how I am going to limit the search to save time) I run the regex and make sure that A1 column is only matched aginst A1 patterns and A2 column against A2 patterns. I would end up with the follwoing reults for "Rule Location"



Column   Pattern                Rule Location
A1 [0-9]{3}.45 101
A2 A55[0-8]{2} 100



  • Doing AND on each of the loctions
    gives me the location 1 - 1001 -
    Complete match.

  • Doing XOR on each of the loctions
    gives me the location 3 - 3055 -
    Partial match. (I am purposely not
    doing an OR, because that would have
    returned 1001 and 3055 as the result
    which would be wrong for partial
    match)



The final reulsts I am looking for are:

1001 - Complete Match

3055 - Partial Match



Input:

The data will be provided in some sort of XML request. It can be one big request with 100K Data nodes or 100K requests with one data node only.

Rules:

The matching values have to be intially saved as some sort of pattern to make it easier to write and edit. Let's assume that there are approximately 100K rules.



Output:

Need to know which rules matched completely and partially.



Preferences:

I would prefer doing as much of the coding as I can in C#. However if there is a major performnace boost, I can use a different language.



The "Input" and "Output" are my requirements, how I manage to get the "Output" does not matter. It has to be fast, lets say each Data node has to be processed in approximately 1 second.



Questions:




  1. Are there any existing pattern or
    framewroks to do this?

  2. Is using Regex the right path
    specifically Assembly Compiled
    Regex?

  3. If I end up using Regex how can I
    specify for A1 patterns to only
    match against A1 column?

  4. If I do specify rule locations in a
    bit type pattern. How do I process
    ANDs and XORs when it grows to be
    100K charcter long?



I am looking for any suggestions or options that I should consider.



Thanks..



Find the answer here

Why does this Ajax work in IE 7 and 8 but not FF or Chrome?

Programmer Question

Say I'm using the following Ajax call:



$(document).ready(function () {
$.ajax({
type: "GET",
url: "http://www.w3schools.com/xml/cd_catalog.xml", //test xml
dataType: "xml",
success: xmlParser,
error: alert("We can't find your XML!"),
asynch: true
});
});

function xmlParser(xml) {

$(xml).find("CD:lt(3)").each(function () {

$("#offers").append('

' + $(this).find("ARTIST").text() + '

' + $(this).find("YEAR").text() + '

');

});


This works fine in IE 7 and 8, but doesn't work in FF or Chrome. I get an empty XML file and the following error in those browsers:




XML Parsing Error: no element found
Location:
moz-nullprincipal:{77f5fd10-d793-4d35-9a4b-b8280b704fba}
Line Number 1, Column 1:




When I googled the error, I thought that it was due to the Ajax cross-domain issue. But if that were the case, wouldn't it be disabled in all browsers? Any help is appreciated - I'm kinda new to this whole Ajax thing.



Thanks!



Find the answer here

Tuesday, February 8, 2011

Accessing a variable defined in a parent function

Programmer Question

Is there a way to access $foo from within inner()?



function outer()
{
$foo = "...";

function inner()
{
// print $foo
}

inner();
}

outer();


Find the answer here

Why does this line of script crash apache?

Programmer Question

Here's the branch of code I've isolated...



if ( !is_search() 
&& (get_option('option1')
&& !(is_page()
|| get_option('option2')
|| get_option('option3')
|| in_category('excludeme', $post )
)
)
)


I've inserted...



 


above and below this line to isolate the cause of the crash



Find the answer here

How do I get a cPanel-created Ruby On Rails setup working properly? It's returning nothing for custom views.

Programmer Question

I've gone through the very helpful tutorial at railsforzombies.org and am now ready to get a test RoR install going. My site is on a shared host, using cPanel. I've created the test application using cPanel, and it's set up at ~/rails_apps/blog. I created a rewrite that redirects mydomain.com/testblog/ to mydomain.com:12002, which is the port that cPanel has my RoR app running on. I also started the application via cPanel, in development mode.



If I go to http://mydomain.com/testblog/, I see the helpful page that lets me know that my RoR app has been created and is functioning. Great, right? Well, not so fast.



I'm following along with the Getting Started guide at http://guides.rubyonrails.org/v2.3.8/getting_started.html, and I get to step 4. I've run



script/generate controller home index


and edited the resulting view at app/views/home/index.html.erb. It's just a simple



Hello rails!




However, when I go to mydomain.com/testblog/home/index (with or without the trailing '/'), I get a blank page in my browser, nothing at all (View Source shows nothing).



To make sure that I'm not going crazy, I put a text file in my rails app's /public directory, and when I go to mydomain.com/testblog/test.txt, it gets served properly. So I know that the Apache rewrite from cPanel is working properly.



Any ideas? I figure I'm overlooking something that's obvious, but I'm drawing a blank for now.



For reference, I'm running on cPanel 11, Ruby 1.8.7 and Rails 2.3.8. I would love to be running Rails 3.0, but the shared host says it's a no-go for now.



Find the answer here

Can a library I use in my Android app .apk collide with that library used in another app?

Programmer Question

I linked jets3t into a test app and got logcats I've not yet seen during install ..



02-08 12:21:11.825: DEBUG/PackageParser(1086): Scanning package: /data/app/vmdl28891.tmp
02-08 12:21:12.059: DEBUG/PackageManager(1086): Scanning package org.jets3t
02-08 12:21:12.075: INFO/PackageManager(1086): /data/app/org.jets3t-1.apk changed; unpacking
02-08 12:21:12.082: DEBUG/installd(1009): DexInv: --- BEGIN '/data/app/org.jets3t-1.apk' ---
02-08 12:21:12.481: DEBUG/dalvikvm(26867): creating instr width table
02-08 12:21:12.715: DEBUG/dalvikvm(26867): DexOpt: 'Lorg/apache/commons/codec/Decoder;' has an earlier definition; blocking out
02-08 12:21:12.715: DEBUG/dalvikvm(26867): DexOpt: 'Lorg/apache/commons/codec/BinaryDecoder;' has an earlier definition; blocking out
02-08 12:21:12.715: DEBUG/dalvikvm(26867): DexOpt: 'Lorg/apache/commons/codec/Encoder;' has an earlier definition; blocking out
02-08 12:21:12.715: DEBUG/dalvikvm(26867): DexOpt: 'Lorg/apache/commons/codec/BinaryEncoder;' has an earlier definition; blocking out
... many more ...
'Lorg/apache/commons/logging/impl/WeakHashtable$Entry;': multiple definitions
02-08 12:21:12.973: DEBUG/dalvikvm(26867): DexOpt: not verifying 'Lorg/apache/commons/logging/impl/WeakHashtable$Referenced;': multiple definitions
02-08 12:21:12.973: DEBUG/dalvikvm(26867): DexOpt: not verifying 'Lorg/apache/commons/logging/impl/WeakHashtable$WeakKey;': multiple definitions
02-08 12:21:12.973: DEBUG/dalvikvm(26867): DexOpt: not verifying 'Lorg/apache/commons/logging/impl/WeakHashtable;': multiple definitions
02-08 12:21:13.168: INFO/dalvikvm(26867): DexOpt: not resolving ambiguous class 'Lorg/apache/commons/logging/LogFactory;'
... many more ...
02-08 12:21:13.364: INFO/dalvikvm(26867): DexOpt: not resolving ambiguous class 'Lorg/apache/commons/logging/LogFactory;'
02-08 12:21:13.387: DEBUG/libgps(1086): GpsInterface_inject_location( 37.378289, -122.059655, 897.000 )
02-08 12:21:13.387: DEBUG/dalvikvm(26867): DexOpt: load 111ms, verify 540ms, opt 21ms
02-08 12:21:13.543: DEBUG/installd(1009): DexInv: --- END '/data/app/org.jets3t-1.apk' (success) ---
02-08 12:21:13.551: INFO/ActivityManager(1086): Force stopping package org.jets3t uid=10084
02-08 12:21:13.559: DEBUG/PackageManager(1086): Activities: org.jets3t.MainActivity
02-08 12:21:13.832: INFO/installd(1009): move /data/dalvik-cache/data@app@org.jets3t-1.apk@classes.dex -> /data/dalvik-cache/data@app@org.jets3t-1.apk@classes.dex
02-08 12:21:13.832: DEBUG/PackageManager(1086): New package installed in /data/app/org.jets3t-1.apk


I'm reading that as shared library overwrites. If it is, I'm wondering if this is a result of something I did wrong? If I overwrite, what are the chances that other apps could break? Of course any properly created library will be backward compatible .. and I guess Android package mgr would not replace a package with an older variant?



Plus "multiple definitions"? "not resolving ambiguous class"?



Oh yeah.. the test app seems to work fine so far :)



Thanks. Guess I need to go read up on pkg install, load, and link lol.



Find the answer here

var in console command C#

Programmer Question

How can I insert a var in console command? i mean somthing like that:



string color = Console.readline();
Console.ForegroundColor = ConsoleColor.color;


Find the answer here

Sunday, February 6, 2011

Django - Internationalisation and Google Maps api v3

Programmer Question

Hi, all



I have a Django app and have integrated some Google maps via the v3 api. After a week of discovery and playing around everything was working fine, until...



I changed the language on my app by clicking on a flag on a form that POSTS the action to /i18n/setlang/, which is what Django uses to change the language. Now the new language is showing up, but the maps aren't. In the Chrome debugger it's giving the following error:



Failed to load resource: the server responded with a status of 400 (Bad Request)

StaticMapService.GetMapImage


The following is the Chrome debugger header content for the error:



1.
Request URL:
http://maps.googleapis.com/maps/api/js/StaticMapService.GetMapImage?1m2&1iNaN&2iNaN&2e2&3u8&4m2&1uNaN&2uNaN&5m3&1e3&2b1&5sen-US&token=128748
2.
Request Method:
GET
3.
Status Code:
[400 Bad Request]
400 Bad Request
4. Request Headers
1.
Referer:
http://127.0.0.1:8000/uns/uns_cities_form/Mu%C4%9Fla/
2.
User-Agent:
Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.3 (KHTML, like Gecko) Chrome/6.0.472.63 Safari/534.3
5. Query String Parameters
1.
1m2:
2.
1iNaN:
3.
2iNaN:
4.
2e2:
5.
3u8:
6.
4m2:
7.
1uNaN:
8.
2uNaN:
9.
5m3:
10.
1e3:
11.
2b1:
12.
5sen-US:
13.
token:
128748
6. Response Headers
1.
Content-Length:
1350
2.
Content-Type:
text/html; charset=UTF-8
3.
Date:
Sun, 06 Feb 2011 20:29:59 GMT
4.
Server:
staticmap
5.
X-XSS-Protection:
1; mode=block


If I set the language back to English all works fine again...



Ok, so there is nothing to do with any translation whilst loading the map, but I'm figuring that Django has changed something or other which is disrupting the Http request, although to be honest I have no idea what is going on. The following is the options and the call to the map



//Map Options
myOptions =
{
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.HYBRID,
streetViewControl: false,
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
},
}

//Create the map
map = new google.maps.Map(elem,myOptions);


Has anyone come across this, or can anyone throw some light on what might be happening?



enter code here


Find the answer here

Good scalaz introduction

Programmer Question

Recently scalaz caught my eye. It looks very interesting, but I have not found any good introduction to the library. Seems that scalaz incorporates a lot of ideas from haskell and mathematics. Most articles that I found assume that you already feel comfortable with these concepts.



What I'm looking for is gradual introduction to the library and underlying concepts - from simple and basic concepts to more advanced (which basesd in basics).



I also looked to the examples, but it's hard for me to find the point where I should start to learn library.



Can somebody recommend me some good scalaz introduction or tutorial (that covers basics and advanced concepts)? Or give me starting point in the answer.



Thank you in advance!



Find the answer here

Entity Framework & Include

Programmer Question

Hi, All
Please help me make include() work in the following case:



ctx.Messages
.Include("Comments.CommentType")
.Include("Comments.Owner")
.Include("Comments.Message")
.Where(m => m.RID == messageId)
.SelectMany(m => m.Comments)
.Where(c => c.CommentType.Id == commentTypeId)
.ToList();


How I should rewrite this query?



P.S. I'm using EF 3.5 (not 4.0)



Find the answer here

Saturday, February 5, 2011

What are some of the problems of "Implied Global variables"?

Programmer Question

Javascript good parts defines these kinds of declarations as bad:



foo = value;


The book says "JavaScript�s policy of making forgotten variables global creates
bugs that can be very difficult to find."



What are some of the problems of these implied global variables other than the usual dangers of typical global variable.



Find the answer here

Backbone.js: Why isn't this event bound?

Programmer Question

I have a simple todo list, and all is rendering as expected, but when I click on the submit button in the edit form, the form is submitted (GET /todo_items), and the page is reloaded an only shows the edit form. The "submit form" event isn't being bound and I can't figure out why. What am I missing?



App.Views.Edit = Backbone.View.extend({
events: {
"submit form": "save"
},
initialize: function(){
this.render();
},
save: function(){
var self = this;
var msg = this.model.isNew() ? 'Successfully created!' : 'Saved!';

this.model.save({
title: this.$('[name=title]').val(),

success: function(model, resp){
console.log('good');
new App.Views.Notice({message: msg});
self.model = model;
self.render();
self.delegateEvents();
Backbone.history.saveLocation('todo_items/'+ model.id);
$('#edit_area').html('');
},
error: function(){
console.log('bad');
new App.Views.Error();
}
});

return false;
},
render: function(){
$('#edit_area').html(ich.edit_form(this.model.toJSON()));
}
});


Here's the edit form:






Find the answer here

How do I find the last sequential div with a specified class in jQuery?

Programmer Question

I have a DOM structure that looks like this:



...

...

...

...

...

...

...

...



In my javascript, I'll have the ID of the div that is getting a new reply, eg comment-2391. What I need to do is find that comments last reply, and insert a new div after that. The script is currently using append('#comment-1234') and that is working just fine, but it inserts it at the top of the replies.



Any ideas?



Find the answer here

How do I call a Spring controller method with Jquery AJAX

Programmer Question

I have the following Spring Controller



@Controller
@RequestMapping("/accreq")



with the following mapping



@RequestMapping(value = "/defRoles", method=RequestMethod.GET)
public @ResponseBody String loadDefaultRoles(@RequestParam(value="idGroup", required=false) String groupID) throws ServletException
{



I'm trying to call this method with the following jquery ajax



$($.ajax({
type: 'GET',
url: '/accreq/defRoles',
data: {idGroup: $('#infoGroup').val() },
success: function() {
alert("success");
}
}));



Please help me figure out why the Spring method is not being called even though the ajax method is being called when I click a button. I have stepped through the script with firebug and it definitely hits the ajax function.



Find the answer here

IRC Client Sending Messages Improperly, C++

Programmer Question

The problem occurs when sending messages. They segment into individual messages where spaces are. The messages are composed using sprintf(message, "PRIVMSG %s :%s\n", irc_chan, buffer); The error will appear as follows(Individual messages are contained in ""s). I will enter a message "Hi there". It will output "Hi" "there". buffer is a char[1024]. Any ideas please let me know.



The following is the part of the code that sends the message, the class I've used for the socket is of no concern to you, I can receive messages and connect FINE.



scanf("%s", buffer);
sprintf(message, "PRIVMSG %s :%s", irc_chan, buffer);
send(IRCSocket.iSocket, message, strlen(message), 0);


Find the answer here

Friday, February 4, 2011

facebook newsfeed example.

Programmer Question

I'm trying to access the news stream to pan for certain events



I'm running into a few issues with the facebook developer toolkit



does anyone have or can point me to an example of getting the news stream?



Find the answer here

Gallery limit problem on a flash template.

Programmer Question

Hi guys, I'm working in another template, and i have this problem with the gallery.



I need more than the 10 pictures on that template, but i really don't know how to add another picture to the website.



the thing is the gallery is the website (more or less) and i can't find the way to add another picture to the gallery.



Can anyone help me with this?



thanks.



pd: the link to the template. link



Find the answer here

Thursday, February 3, 2011

select first child with jquery

Programmer Question

I am trying to select first child of ul and then remove it and then append it in the end of that ul but unfortunately i can not selet first child.



Here is code



current = 0;
$(document).ready(function(){

width=951;

var totalSlides=$(".slider ul li").length;
$(".slider ul").removeAttr('width');
$(".slider ul").attr('width',width*totalSlides);

$('#next img').click(function(){
current -= width;
$(".slider ul").animate({"left":current+"px"}, "slow");
$(".slider ul").append($(".slider ul:first-child"));
//$('.slider ul:firstChild').remove();
});
});


Find the answer here

Top bad practices in PHP

Programmer Question

Hi



Until now I've learned from Stack Overflow that some of the code I've been writing so far is considered "bad practice". Like using tons of global variables, create_function() etc. I'm curious to know more about this.



So please post here what you think are bad practices in PHP and why. But please only one per answer, this way the worst can get the most votes.



thanks :D



Find the answer here

Finding "Keywords" with potentially damaged HTML Files and Counting Hits

Programmer Question

I'm trying to create a master index file for a bunch of HTML files sitting in a directory. There could be anywhere from 5 to 5000. These files aren't clean or nice, so some of the libs I looked at don't seem like they would play nice. Many of these files come from the temp directory or are carved out of the file slack (ergo incomplete files in many cases). Plus, sometimes people just write sloppy HTML.



I've basically decided to enumerate through the directory and use something like



string[] FileEntries = Directory.GetFiles(WhichDirectory);

foreach (string FileName in FileEntries)
{
using (StreamReader sr = new StreamReader(FileName))
{
HTMLContents = sr.ReadToEnd();
}


I'm hoping that the StreamReader can dump the contents into a character array the same way it would a text file.



Anyways, given that this might not be the cleanest HTML in the world, there a few things I'd like to parse out of the array.




  1. Any Instance of a date in ANY format (e.g. 1/1/11, January 1st, 2011, 1-1-11, Jan-1-2011, etc) and dump these into a string to be read back later. Hopefully there is a lib or something for finding "instances" of dates.


  2. Read a text file line by line with various "keywords" to look for in the mess of HTML. Things like "Bob Evans" or "Sausage Factory Ltd" etc. I then want to count the number of times each "keyword" shows up. The problem is I don't want to have to resort to the user having to know regex expressions.




So, the desired output would be something like this:




BobEvans9304902.html

Title: Bob Evans Secret Sausage Recipe



Dates Found: "October 2nd, 2009" , "7/22/09"



"Bob Evans Sausage" : 30 hits



"Paprika" : 2 hits



"Don't overwork it" : 5 hits




All the solutions I have seen so far seem like they only work for single characters or words (LINQ) or split a "neat' sentence into words. I'm hoping I won't have to create a new copy of the string and strip out all the HTML tags, since it's not always going to be neat and I don't want to add another step to mass file processing. If that's the only way to do it, though, so be it.



Find the answer here

How do I start IRB console from a rake task?

Programmer Question

I'm trying to write a rake task that will set up an environment mirroring my project.



task :environment do 
require 'rubygems'
require 'sequel'
# require 'my_projects_special_files'
end

task :foo => [:environment] do
require 'irb'
IRB.start
end


Leads to irb complaining that "foo" doesn't exist (the name of the task)




10:28:01:irb_test >> rake foo --trace
(in /Users/mwlang/projects/personal/rake/irb_test)
** Invoke foo (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute foo
rake aborted!
No such file or directory - foo
/opt/local/lib/ruby/1.8/irb/input-method.rb:68:in `initialize'
/opt/local/lib/ruby/1.8/irb/input-method.rb:68:in `open'
/opt/local/lib/ruby/1.8/irb/input-method.rb:68:in `initialize'
/opt/local/lib/ruby/1.8/irb/context.rb:80:in `new'
/opt/local/lib/ruby/1.8/irb/context.rb:80:in `initialize'
/opt/local/lib/ruby/1.8/irb.rb:92:in `new'
/opt/local/lib/ruby/1.8/irb.rb:92:in `initialize'
/opt/local/lib/ruby/1.8/irb.rb:57:in `new'
/opt/local/lib/ruby/1.8/irb.rb:57:in `start'
/Users/mwlang/projects/personal/rake/irb_test/Rakefile:9


Find the answer here

web development idol admiration [closed]

Programmer Question

What are current web technologies capable of? Please, give me links to visibly complicated web apps. Thanks!



Find the answer here

Sunday, January 30, 2011

How to extract exponents and modulus from SSH-RSA key files

Programmer Question

http://www.faqs.org/rfcs/rfc4253.html

::http://www.faqs.org/rfcs/rfc4251.html



Does anyone know the SSH key file format?



!! UPDATE

!! The base64 function I was using doesn't work. After running the key file through a different function (mozilla's built in atob()) the data fit into the specifications listed above.



I have rsa key files created with puttygen, but I must be missing something critical. Here is the hex of the public section:



00 00 00 07 73 73 68 2d 72 73 61 00 00 00 01 25
00 00 00 10 1c 1c 57 3f 4f 58 63 69 38 ad 19 35
b5 28 3d 78 53 35 53 6c 15 0e 69 23 ac 17 14 84
21 29 13 07 36 62 90 26 37 93 73 17 28 b8 ce 95
c3 11 24 21 61 b7 82 d9 04 42 97 f8 27 c3 44 06
46 ca e8 a3 a3 34 d7 3c c3 95 13 dd 16 1b 2c 29
7c 35 19 5f c2 7a 17 d5 14 0d 26 36 27 18 71 67
8d 9c 5b c4 7d


first 4 bytes are UINT 7, the number of bytes inthe following string "ssh-rsa" but the format stops making sense after that. It SHOULD be followed by two MPINT but they lengths don't add up for the 3rd value.



Thanks!



Find the answer here

Using a numbered file descriptor from Java

Programmer Question

I need to access numbered file descriptors from Java -- other than 0, 1 or 2.



How can this be done? I looked at the FileDescriptor class but did'nt find any way to initialize it with a given file descriptor number.



As a concrete example lets suppose Java gets called as a child process from another programing language. File descriptors 3 and 4 are provided by the other language for input and output.



What I need in Java are InputStream and OutputStream objects connected to these file-descriptors, just like System.in, System.out and System.error are connected to file-desctiptors 0, 1 and 2.



I'm using Java 1.6 and this should run on Unix alike systems.



Tested working solution:



The answer with the file descriptor special filesystem entries did point me to the following workable solution:




  1. find out if and where your Unix alike system has a special filesystem that contains named entries for all file descriptors.




    • I'm using FreeBSD where fdescfs(5) is a filesystem that does just this. Under Linux it would be procfs.


  2. make sure this filesystem is mounted




    • FreeBSD: put fdescfs /dev/fd fdescfs rw 0 0 in /etc/fstab



      or run mount -t fdescfs null /dev/fd on a shell prompt (probably with sudo)



  3. Use new FileInputStream("/dev/fd/3") and new FileOutputStream("/dev/fd/4") to get the streams connected to the filedescriptors (the paths are for FreeBSD, replace with your operating systems paths)




Find the answer here

Saturday, January 29, 2011

Checking a null value in Objective-C that has been returned from a JSON string

Programmer Question

Heya,



I have a JSON object that is coming from a webserver.



The log is something like this:
{"status":"success","UserID":15,"Name":"John","DisplayName":"John","Surname":"Smith","Email":"email","Telephone":null,"FullAccount":"true"}



Note the Telephone is coming in as null if the user doesn't enter one.



When assigning this value to a NSString, in the NSLog it's coming out as



What is the correct way to check this value? It's preventing me from saving a NSDictionary.



I have tried using the conditions [myString length] and myString == nil and myString == NULL



Additionally where is the best place in the iOS documentation to read up on this?



Many thanks



Find the answer here

Friday, January 28, 2011

How can I intercept the mass-assignment hash for an ActiveRecord object and filter it?

Programmer Question

Let's say I have a record class Person with an integer field awesomeness.



If I call Person.new(:awesomeness => 5), it works fine.



If I call Person.new(:awesomeness => 'five'), as expected, Rails does its bets to figure out what 'five' is as an integer and fails, so it just defaults to 0. Can I intervene by intercepting the hash and fidgeting with the data somehow?



The earliest "event" in the ActiveRecord callbacks is the before_save, by which point 'five' has already become 0.



I could obviously do this controller-side, but this seems to be something that belongs strictly in the model as a filter.



Find the answer here

TSQL- Finding the differene in days of multiple records

Programmer Question

Is it possible to find the difference of days of different records in SQL Server 2008 R2?



SELECT OrderDate FROM OrdersTbl WHERE SKU='AA0000' ORDER BY ORDERDATE DESC


OrderDate
-----------------------
2009-12-03 00:00:00.000
2009-04-03 00:00:00.000
2008-02-22 00:00:00.000
2008-02-21 00:00:00.000
2007-02-18 00:00:00.000
2007-01-27 00:00:00.000
2006-10-13 00:00:00.000


I would like a way to get how many days in between there are for each order date so that I could find the average frequency. Thanks in advance.



Find the answer here

Display RSS Image with SimplePie

Programmer Question

I'm setting up a page which grabs the first entry from multiple RSS feeds. I'm running into a lot of RSS feeds that are formated differently. I'm using SimplePie to parse the feeds. The current feed I'm trying to grab the image from is below:




2011-01-28T09:00:00Z
Information on Title of Product




Title of Image






How can I grab the img tag from within the summary tag with SimplePie so I can display this on my website?



Thanks in advance.



Find the answer here

Import JavaScript file from within JavaScript synchroniously?

Programmer Question

Instead of messing up my HTML file, I'd like to import my external JavaScript files through another JavaScript file, much like @import in css.



On several websites, including StackOverflow itself, I noticed that appending a script tag to the DOM can solve this issue; however, this is done asynchroniuosly, while the order of my files is important - the second file for example may rely on the first file in the list. When, say, loading jQuery first and then loading a dependency (plugin etc.) of it, the dependency might finish loading earlier and will throw errors because jQuery doesn't exist yet.



Therefore, this does not seem to be an option. How can I synchroniously load JavaScript files from within another JavaScript file?



Find the answer here

Thursday, January 27, 2011

How to use sprite css

Programmer Question

I have the following image that I want to use for users to log into site.



http://dl.dropbox.com/u/7468116/facebook_signin.png



However I am not able to make css work properly.



Find the answer here

Wednesday, January 26, 2011

Xpath checking the amount of text input fields

Programmer Question

Hello everyone,



I am trying to write a phpUnit test in the Zend framework. And this time I for the fun want to test that I have two input fields of type text in my contact form.



So I wrote this line of code:



 $this->assertQueryCount('form#contact-form/input[@type="text"]',2);


But it returns:




1) IndexControllerTest::testCanDisplayContactForm
Failed asserting node DENOTED BY form#contact-form/input[type="text"] OCCURS EXACTLY 2 times




So I have a form with the id 'contact' form. And within this I want to get all the input fields of type text



Any idea's or tips?



Find the answer here

How can I get non-english characters from ajax form to MySQL

Programmer Question

I have a form that submits data using the jQuery form plugin. From there it goes through some server side handling and finally stored in a MySQL db.



Upon submitting these characters ����� they become sent to the server as áâãäï' (before hitting the database). The same type of thing happens with Japanese characters, etc.



I have tried both UTF-8 and ISO-8859-1 for the form encoding, page encoding, php server side encoding and db encoding. Still no luck.



Find the answer here

How to get a vendor type from an open OdbcConnection in C#?

Programmer Question

I might be connected to either Oracle, Sybase, or MSFT SQL Server databases.
How can I detect which vendor I am connected to at run-time if an instance of System.Data.Odbc.OdbcConnection is passed to my method? Here is a set-up:



enum VendorType
{
Unknown = 0, // Bill Wagner recommends an Unknown enum.
Microsoft,
Oracle,
Sybase
}

public static VendorType GetConnectionVendorType()
{
if (Connection == null)
{
return VendorType.Unknown;
}

if (...)
{
return VendorType.Microsft;
}

if (...)
{
return VendorType.Oracle;
}

if (...)
{
return VendorType.Oracle;
}

// Just in case we got here.
return VendorType.Unknown;
}


Thanks!



Find the answer here

Proper Amazon AWS S3 usage

Programmer Question

Heres a quick rundown. We have two apps. Both apps are different from each other in every aspect.



Our first app is a company profile (4 page layout: home, products, about, contact). I don't think it will generate the same traffic as social web sites online. It allows staff members to post product photos. Is it better to have an AWS S3 account to store this content on? Or would I be better off storing the files on the local web server?



Our second app is more social oriented. Here, we have decided to use an S3 bucket for this app. Since we already have an AWS account, should we create a bucket for the first app on this AWS account? Or will this just render more expenses in the long run? What are your thoughts?



On another note. Should app related content (logo, icons, background images, buttons, etc) be stored on the S3 account or on the local server? What is the general consensus on this?



Find the answer here

Cancel split window in Vim

Programmer Question

I have split my windows horizontally. Now how can I return to normal mode, i.e. no split window just one window without cancelling all of my open windows. I have 5 and do not want to "quit", just want to get out of split window.



Find the answer here

Sunday, January 23, 2011

How to capture into file only last 30 secounds? Java JFM

Programmer Question

Hi Guys,
Maybee anyone have any idea how to capture into file only last 30 secounds from camera?



It's working something like this.
Camera working non stop, but when it catch action ( maybee from button )
I'm should ge only last 30 secounds of movie.
Please help.
Mik



Find the answer here

Realistic dice throwing animation with predefined outcome

Programmer Question

I need to create a small dice game in Flash. The random number generator is external and I have to create a 3D realistic dice animation with that outcome.



I'm using Away3D engine and JigLib for physics.
So far the best idea I've had is to do many simulations and create a list of outcomes and their corresponding input parameters (initial position, initial orientation and the forces added to the RigidBody).



This is not working so well. Sometimes for the same parameters the outcome is different.



What is the best way to do this?



Find the answer here

How should I handle third-party input/output streams?

Programmer Question

Hi all!



There is a piece of project dealing mostly with input/output streams. So I have to pass streams as arguments and receive them from third-party libraries. I've read Good design: How to pass InputStreams as argument? and Closing Java InputStreams, but I'm not 100% sure that third-parties are sharing the same coding values and following best designs patterns (in particular - "the one who opens the stream should close the stream")



Assuming that streams are pretty big (500Mb - 3Gb) and I'm tight on CPU and memory resources, here are few questions to the java SO community:




  1. Should I ever try to close streams I got from third-party library?

  2. What are possible dangerous implications of unclosed streams (not counting extra GC workload)

  3. Are these implications somewhat proportional to the stream size?



Find the answer here

Android: More descriptive error please!

Programmer Question

Hi all



I'm using Eclipse.



I'm burning hours trying to debug my first (very simple) android app.



When I hit an error, I don't get a proper exception with a description of what went wrong, I get a screen asking for source code and a "Suspended(Exception RuntimeException))" on the debug log.



I'm resorting to logging each line to see where the last execution point was, and then trying to understand by googling why the following line would cause an error.



See my screenshots: Error and Missing Source.



The highlighted line:



SimpleCursorAdapter scaSights = new SimpleCursorAdapter(this,R.layout.sight_row,sightsCursor,fromDisplayFields,toDataFields);


is where the exception occurs. I've got no idea what's wrong there, but a good exception message would help, not a prompt for source code.



Any help is hugely appreciated!



Find the answer here

Friday, January 14, 2011

PHP and Javascript cookies

Programmer Question

Can I access a cookie written with jQuery's cookie plug-in with PHP? I know you can't set Javascript equal to PHP or vice versa, but IN ESSENCE is:



$.cookie('var') = $_COOKIE['var']?


Again, I know you can't set them equal to each other, but if I set it in jQuery and then go to another page, can PHP access it? I've read lots of posts about this, but I can't seem to find an answer to this part.



Note, if I look in Firefox's preferences, I can see the cookies are there, so I know they're set.



Find the answer here

Platform independent remote file editing

Programmer Question

I've been investigating possibilities on editing remote files from a website without having a need to download and upload the files manually while editing. So far I've ruled out WebDAV as a possibility since it is cumbersome to use on any platform (it either requires manual setup or works unreliably).



Currently I'm looking in to various Applets, but they mostly target either uploading or downloading, not file editing. What I'm currently looking for is an applet that downloads the document, launches the application that is meant to open the file and then monitors the file for changes and uploads the changed file (either automatically or by prompting the user first).



I know that I'm not alone with this scenario, so i'm looking for solutions that others have thought of.



Find the answer here

const variable paradox

Programmer Question

hello everyone, if I have some expression on c++:



const int x = 3;


can I say that x is a variable? It seems very strange cause x is not variable cause I can't change it, thanks in advance for any expanations



Find the answer here

Trace (like OutputDebugString/Trace.writeline) from MS-SQL stored procedure

Programmer Question

Hey everybody



I've been looking for a while for a way to trace from SQL stored procedure on MS-SQL.
I am talking about tracing to "DebugView", just like the function OutputDebugString() (or C#'s Trace.WriteLine()).



Does anyone know how to do that, or if it is even possible?



Thanks! :-)



Find the answer here

Can someone explain to me why I would need functional programming instead of OOP?

Programmer Question

Can someone explain to me why I would need functional programming instead of OOP?



E.g. why would I need to use Haskell instead of C++ (or a similar language)?



What are the advantages of functional programming over OOP?



Find the answer here

Thursday, January 13, 2011

Java Equivalent to iif function

Programmer Question

Hello, the question is simple, there is a functional equivalent of the famous iif in java?



For example:



IIf (vData = "S", True, False)


Thanks in advance.



Find the answer here

Wednesday, January 12, 2011

How to execute several batch commands in sequence

Programmer Question

I want to create a Windows XP batch script that sequentially performs something like the following:



@echo off
:: build everything
cd \workspace\project1
mvn clean install
cd ..\project2
mvn clean install

:: run some java file
cd \workspace\project3
java -jar somefile.jar


When I create a Batch script like this (following these instructions), I still have the problem that the script stops doing something after the first



mvn clean install


and then displays the command line.
How can i execute all of these commands in sequence in one batch file?



I don't want to refer to other files, I want to do it in one file.



Find the answer here

What are the best practices for writing maintainable CSS?

Programmer Question

I am just starting to explore this area and wonder what are the best practices when it comes to production of clean, well-structured and maintainable CSSes.



There seems to be few different approaches to structuring CSS rules.



One of the most commonly encountered ones I saw was throwing everything together in one rule, i.e. margins, borders, typefaces, backgrounds, something like this:



.my-class {
border-top:1px solid #c9d7f1;
font-size:1px;
font-weight:normal;
height:0;
position:absolute;
top:24px;
width:100%;
}


Another approach I noticed employed grouping of properties, say text-related properties like font-size, typeface, emphasis etc goes into one rule, backgrounds go into other, borders/margins go into yet another one:



.my-class {
border-top:1px solid #c9d7f1;
}

.my-class {
font-size:1px;
font-weight:normal;
}

.my-class {
height:0;
top:24px;
width:100%;
position:absolute;
}


I guess I am looking for a silver bullet here which I know I am not going to get, bet nevertheless - what are the best practices in this space?



Find the answer here

OpenId authentification in ASP.NET MVC as a restful service?

Programmer Question

Can I offer the authentication, authorization, etc created using "ASP.NET MVC Open Id website" extension.. as a REST service in ASP.NET MVC? How can I create this service(maybe using WCF)?
(Please if you can, offer me some examples please).



Find the answer here

IE8 on Win7 image not loaded.

Programmer Question

I have an image that is not loading in IE8. When browsing to the image it comes up. It loads in Firefox and Chrome.



I have tried running IE8 in safe mode and compatibility mode.



On some boxes with the same OS and browser it displays. Any other suggestions?



Thanks



Find the answer here

Magento order import/export

Programmer Question

Hi,



Is there any way to import/export the orders from magento. Since we have magento store on live and another dev. version is ready with greatest change now we only need to import the magento orders alone. Here i can see only export -



http://www.magentocommerce.com/magento-connect/slandsbek/extension/1350/simple-order-export



But how can i import the order data into new store.



Find the answer here

Saturday, January 8, 2011

ffmpeg async io?

Programmer Question

Anyone know if ffmpeg does asynchronous file io? That is, the input file is read in a separate thread as to avoid io blocking the processing thread?



Basically what I want to figure out is whether or not i need to do calls to "av_read_frame" inside a separate thread (to avoid blocking) or if ffmpeg alrdy handles this issue?



How might I figure this out? I've tried downloading the ffmpeg source but haven't been able to find anything useful.



Find the answer here

Jquery mobile framework in android OS

Programmer Question

Why jquery mobile framework is slow performance in android2.2 OS



Find the answer here

can php function parameters be passed in different order as defined in declaration.

Programmer Question

Suppose I have a function/method F() that takes 3 parameters $A, $B and $C defined as this.



function F($A,$B,$C){
...
}


Suppose I don't want to follow the order to pass the parameters, instead can I make a call like this?



F($C=3,$A=1,$B=1);


instead of



F(1,2,3)


Find the answer here

I can't insert data into my database

Programmer Question

I don't know why, but my data doesn't go into my database 'users' with the table 'data'.










All i get is a blank page.



Find the answer here

ClassLoader exceptions being memoized

Programmer Question

Hello,



I am writing a classloader for a long-running server instance. If a user has not yet uploaded a class definition, I through a ClassNotFoundException; seems reasonable.



The problem is this: There are three classes (C1, C2, and C3). C1 depends on C2, C2 depends on C3. C1 and C2 are resolvable, C3 isn't (yet). C1 is loaded. C1 subsequently performs an action that requires C2, so C2 is loaded. C2 subsequently performs an action that requires C3, so the classloader attempts to load C3, but can't resolve it, and an exception is thrown. Now C3 is added to the classpath, and the process is restarted (starting from the originally-loaded C1). The issue is, C2 seems to remember that C3 couldn't be loaded, and doesn't bother asking the classloader to find the class... it just re-throws the memoized exception.



Clearly I can't reload C1 or C2 because other classes may have linked to them (as C1 has already linked to C2).



I tried throwing different types of errors, hoping the class might not memoize them. Unfortunately, no such luck.



Is there a way to prevent the loaded class from binding to the exception? That is, I want the classloader to be allowed to keep trying if it didn't succeed the first time.



Thanks!



Find the answer here

Thursday, January 6, 2011

How do I distribute precompiled extension modules for Windows on pypi for multiple versions of Python?

Programmer Question

I would like to distribute a precompiled C extension module for Python 2.6 and Python 2.7 for 32- and 64-bit versions of Python. How should I build and distribute that on pypi? Should I just use bdist_egg? Can I retain compatibility with pip?



I notice ordinary bdist just creates a .zip that does not include the Python version, although the internal folder structure does. Can this .zip just contain e.g. a Python26 and Python27 subdirectory?



Find the answer here

how to run line by line in text file - on windows mobile ?

Programmer Question

hi



in WinForm on PC i use to run like this:



FileStream FS = null;
StreamWriter SW = null;
FS = new FileStream(@"\Items.txt", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
SW = new StreamWriter(FS, Encoding.Default);
while (SW.Peek() != -1)
{
TEMP = (SW.ReadLine());
}


but when i try this on Windows-mobile i get error:



Error   1   'System.IO.StreamWriter' does not contain a definition for 'Peek' and no extension method 'Peek' accepting a first argument of type 'System.IO.StreamWriter' could be found (are you missing a using directive or an assembly reference?)
Error 2 'System.IO.StreamWriter' does not contain a definition for 'ReadLine' and no extension method 'ReadLine' accepting a first argument of type 'System.IO.StreamWriter' could be found (are you missing a using directive or an assembly reference?)


how to do it ?



thanks



Find the answer here

Best practice for ignoring files within a folder with GIT

Programmer Question

I'm just looking for some advice on the best way to manage the following situation with git.



my project has a folder called "photos" that users can upload images to.



I have a version of the project running locally and I am adding images to this folder for testing purposes.



When I push to the live server I want the "photos" folder to get pushed but not the images within it. Also when users add images to the "photos" folder on the live server I want GIT to ignore them.



I know I need to use Git Ignore but I'm unsure what the best way to do this is.



Should I just add "photos" to the git ignore file and then manually create the "photos" folder on the live server?



Thanks in advance.



Find the answer here

Wednesday, January 5, 2011

What programming language is my windows hosts file?

Programmer Question

Maybe this is a silly question, but today I was working in my hosts file (C:\windows\system32\drivers\hosts) in notepad++ and would like to use the language formatting.



For example, the first line appears to be a comment



# Copyright (c) 1993-1999 Microsoft Corp.


What language do I choose to view the file?



Find the answer here

How to fetch data for AutoCompleteTextView in separate thread?

Programmer Question

For my AutoCompleteTextView I need to fetch the data from a webservice. As it can take a little time I do not want UI thread to be not responsive, so I need somehow to fetch the data in a separate thread. For example, while fetching data from SQLite DB, it is very easy done with CursorAdapter method - runQueryOnBackgroundThread. I was looking around to other adapters like ArrayAdapter, BaseAdapter, but could not find anything similar...



Is there an easy way how to achieve this? I cannot simply use ArrayAdapter directly, as the suggestions list is dynamic - I always fetch the suggestions list depending on user input, so it cannot be pre-fetched and cached for further use...



If someone could give some tips or examples on this topic - would be great!



Find the answer here

UIApplicationExitsOnSuspend anything else I'm missing?

Programmer Question

So I know this has been beaten to death but I still can't figure out a solution.



I have my UIApplicationExitsOnSuspend set to in the Info.plist and still both in the simulator as well as on an iPhone 4 device, the app goes into standby instead of terminating?



Any ideas of what else could one do to get it to terminate? Perhaps are there methods that I need to remove from the app delegate? Any ideas?



Find the answer here

Accessing TextView from another class

Programmer Question

I've got my main startup class loading main.xml but I'm trying to figure out how to access the TextView from another class which is loading information from a database. I would like to publish that information to the TextView.



So far I've not found any helpful examples on Google.



EDIT:
This is my class that is doing the Database work:



import android.widget.TextView;import android.view.View; 
public class DBWork{
private View view;
...
TextView tv = (TextView) view.findViewById(R.id.TextView01);
tv.setText("TEXT ME")


Yet, everytime I do that I get a nullpointerexception



Find the answer here

Can't store UTF-8 in RDS despite setting up new Parameter Group using Rails on Heroku

Programmer Question

I'm setting up a new instance of a Rails(2.3.5) app on Heroku using Amazon RDS as the database. I'd like to use UTF-8 for everything. Since RDS isn't UTF-8 by default, I set up a new Parameter Group and switched the database to use that one, basically per this. Seems to have worked:



SHOW VARIABLES LIKE '%character%';

character_set_client utf8
character_set_connection utf8
character_set_database utf8
character_set_filesystem binary
character_set_results utf8
character_set_server utf8
character_set_system utf8
character_sets_dir /rdsdbbin/mysql-5.1.50.R3/share/mysql/charsets/


Furthermore, I've successfully setup Heroku to use the RDS database. After rake db:migrate, everything looks good:



CREATE TABLE `comments` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`commentable_id` int(11) DEFAULT NULL,
`parent_id` int(11) DEFAULT NULL,
`content` text COLLATE utf8_unicode_ci,
`child_count` int(11) DEFAULT '0',
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `commentable_id` (`commentable_id`),
KEY `index_comments_on_community_id` (`community_id`),
KEY `parent_id` (`parent_id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;


In the markup, I've included:






Also, I've set:



production:
encoding: utf8
collation: utf8_general_ci


...in the database.yml, though I'm not very confident that anything is being done to honor any of those settings in this case, as Heroku seems to be doing its own config when connecting to RDS.



Now, I enter a comment through the form in the app: "�be� ��iL", but in the database I've got "Úbe® ƒåiL"



It looks fine when Rails loads it back out of the database and it is rendered to the page, so whatever it is doing one way, it's undoing the other way. If I look at the RDS database in Sequel Pro, it looks fine if I set the encoding to "UTF-8 Unicode via Latin 1". So it seems Latin-1 is sneaking in there somewhere.



Somebody must have done this before, right? What am I missing?



Find the answer here

Tuesday, January 4, 2011

What are good ways to collaberate on a group programming project?

Programmer Question

I'm in my second year of CS now (not the American one though) and am looking at a pretty big project next semester. I don't know the specifics just yet, but it'll involve a back-end in COBOL, most of the 'functionality' in Java and the rest in .Net. (I still know nothing about .Net, it's a course that starts in the 2nd semester as well)



We're programming Cobol in Percobol and Java in Eclipse. Next to the programming, we'll also have extra assignments such as English and French translation tasks that are often related to the software.



So here's my question: how would you organize this, knowing you work together with 3 other people?



Last year we had a smaller project. We synchronized our code using Google Code (through the Subversion plugin for Eclipse) and used Google Wave to share documents and updates. Google Wave was actually very useful, but it appears it's shutting down soon. I don't want to take any risks with a project this important.



Sharing documents is very easy with Dropbox, but it doesn't quite offer the flow of communication and interactivity that Google Wave did. (Can you add this sort of functionality to Dropbox?)



To state what I specifically need:




  • A website or program to easily collaborate with 3 other people, sharing files and providing commentary. Google Wave is/was a good example. Dropbox is an improvement on the file sharing, but lacks in the communication department.


  • An easy way to share a Cobol project? I'm willing to switch compilers, because Percobol royally sucks.


  • You're welcome to comment about .Net, but I don't know anything about it yet so I don't really have questions about it (yet).




Any opinions or advice on the matter are welcome. Thanks in advance!



Find the answer here

How to reformat URLs to be more restful (from .../?id=123 to .../123)?

Programmer Question

Currently I have pages accessed via:



www.foo.com/details.html?id=123


I'd like to make them more restful-like, such as by the following:



www.foo.com/details/123


I'm using Google App Engine. Currently the URL's are mapped in the html-mappings file:



 ('/details.html*', DetailsPage),


And then on the DetailsPage handler, it fetches the ID value via:



class DetailsPage(webapp.RequestHandler):
def get(self):
announcement_id = self.request.get("id")


How might I restructure this so that it can map the URL and a extract the ID via the other-formatted URL: www.foo.com/details/123



Thanks



Find the answer here

Ruby using helpers in single script

Programmer Question

I am wanting to use the pluralize text helper in a ruby script I am writing, but can't find anywhere on how to include Rails helpers in a single ruby script. I know you need to include the helper module and require the helpers, but like I said I am not 100% sure on how to get it to work.



Find the answer here

Fatal warnings on Windows

Programmer Question

While working between a Windows MySQL server and a Debian MySQL server, I noticed that warnings were fatal on Windows, but silently ignored on Debian. I'd like to make the warnings fatal on both servers while I'm doing development, but I wasn't able to find a setting that effected this behavior. Anyone have any ideas?



Find the answer here

Web UI prototyping tools

Programmer Question

Can anyone recomend me a simple web UI prototyping tool,
so I could quicky prototype the look of a my web site.



I have tried to use MS Visio for this, but found it
very "user un-friendly".



What I really need is to be able quicky sketch the layout
of the page, put some links, images and buttons on in,
play a little bit with a colors (CSS), and it would be
great it this tool could support navigation between
the pages - but it is not essential.



I would rather consider a low-cost or an open-source solution,
since I am not a web designer and not going to use that
tool on a daily basis.



Find the answer here

LinkWithin

Related Posts with Thumbnails