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

LinkWithin

Related Posts with Thumbnails