Tuesday, May 8, 2012

Passing function as argument with variables inside - possible?

Code:



function remove_comment(){
var id = "bla";
Msg().prompt( "blabla" , function(){ Ajax().post( "id=" + id ) } , id );
}

Msg().prompt( txt , fn , args ){
$( elem ).click( fn );
}


As you can notice, I need to pass this function to prompt(), while inside the passed function one of the arguments depends on the variable id.



Now, after the function passed I need it to be assigned to an element's onclick event (the code abode is not using jQuery).



First, I'd tried to do this:
$( elem ).click( fn.apply( this , id ) );,
$( elem ).click( fn.call( id ) );, but these codes execute the function immediately (I already know why, no need to explain).
Then I'd tried to play with the function and arrange it as string to pass directly as onclick='THE_FUNCTION' html code to the element, but with no success.





getJSON + json_encode + query php

This is my query.php



<?php
$db_host="localhost";
$db_user="root";
$db_pass="root";
$db_name="mytable";

mysql_connect("$db_host","$db_user","$db_pass")or die("");
mysql_select_db("$db_name")or die("");

$query = "SELECT * FROM app";
$result=mysql_query($query);
echo json_encode(mysql_fetch_assoc($result));
?>


How can i do to learn any single attribute in my html page?
I try like this but it dont work.



$.getJSON("query.php",function(result){
$.each(result, function(i, obj){
$('div').html(obj.attribute1+" "+obj.attribute2 ecc...);
});
});




javascript validation for allow -1 and all positive numbers in text box

I am trying to validate a text box to allow all positive numbers including -1 in it.



i tried this, which will work for allowing only positive numbers



  function allownumbers(e, txtBox) {
var key;

key = (e.keyCode) ? e.keyCode : e.charCode;
if (e.charCode == 0) {
return true;
}
if ((key < 48 || key > 57) && (key != 46) && (key != 44)) {
return false;
}
if (key == 46) {
if ((txtBox.value).indexOf('.') != -1) {
return false;
}
}
if (key == 44) {
if ((txtBox.value).indexOf(',') != -1) {
return false;
}
}
return true;
}




But how to allow -1(only) with all positive numbers
Thanks in advance





JavaScript: what is NaN, Object or primitive?

what is NaN, Object or primitive?



NaN - Not a Number





Prevent Android activity from being recreated on turning screen off

How to prevent an activity from being recreated on turning screen off?



What I do





  1. Start Bejewels and go to the jewelry screen.

  2. Press power button shortly. The screen is turned off, but the device is not.

  3. Press power button again.




What I see




The same screen as before turning screen off.




In case of my application (trivial one, just a web-app with a single WebView) the scenario is the following:



What I do





  1. Start my app. The activity onCreate() method loads an URL into the WebView.

  2. Press power button shortly. The screen is turned off, but the device is not.

  3. Press power button again.




What I see




The WebView is reloading the page.




What I expected




As in Bejewels case I want to see the same screen, that for my app is the page in its previous state: scripts are running, a form fields are
filled etc.




The debugging showed, that I was wrong (in a previous question) and onDestroy() and onCreate() are being called one-by-one when the screen is just turned on. And since I still hear a music, played by a script, when the screen is off, it looks like both the activity and the WebView do exist all that time.



What I tried.




  1. android:alwaysRetainTaskState="true" The same behavior.

  2. Reading about intents (to no avail, I just did not understand, how they are applied to my situation).

  3. Using PhoneGap. It behaves differently: just killed the whole application on pressing power button. This IS better, but not the best.





Can We add object of SpriteAsset to VBox or HBox in flex?

Can We add object of SpriteAsset to VBox or HBox?

I have an object of class SpriteAsset. I want to make it visible/invisible at runtime.

As there is no methode like setVisible() for SpriteAsset.
i tried to encapsulate object of SpriteAsset in VBox or HBox so that I can try setVisible() on it.

I found that the code doesn't run when I did


objVBox.addChild(objSpriteAsset);


The code compiles fine.

Any solution to this?





A simple login system with PHP. Does it really need an SSL certificate?

I plan to offer my website designs and if someone is interested in an easy-to-manage blog (or just doesn't want to make new html files for new posts on his/her own) this simple login/blog system is what I will offer them as an addition. It's main purpose is to enable only one user to log in by providing the password (the username cannot be changed) and allow him/her to edit a few account settings (displayed name, avatar, bio) or make new pages/posts by just writing new content into the window. This is supposed to be a very simple system with no registration forms - a framework which I want to provide to all clients who would choose to buy my designs.
Since the login system is so simple, I dare to say that there is little authentication needed - just the password entry (+any other forms where the user enters, for example, the content of a new post). So basically, it should have the following functions: trim(), htmlspecialchars(), mysql_string_escape(), checking for valid characters with a regular expression and a user session (by the way, is a user session even needed on a site with only one user?). What else is needed on such a simple website? I was thinking about a self-signed SSL certificate, however, it causes a security warning. Is it even needed in such a situation?
This system would be reused in every HTML/CSS design project I'd work on, so it needs to be decided now, since I'm going to provide this framework along with the website for those people who just want to run their personal website/blog without learning all that wordpress stuff.
I know websites should be encrypted, but since the only encryption needed here is for the password, what should I use?





Php, how to determine if a class (and not taking account subclasses!) has a method?

I know theres a method_exists() but it says true even when that method is inherited.



class A
{
public function eix()
{
}
}

class B extends A
{
}


echo method_exists ('B', 'eix');



so its true, but B class doesnt have it. How to dodge this?





Attach to Process is not working in Visual studio 2008 in Windows 7

Today i had a wired issues with Visual Studio 2008 SP1 running in Windows 7 32bit Machine with IIS7 installed.
I am developing a web application. I have set up the default website in local host in IIS (IIS 7.0) to run the website and it is working fine when i press F5,the process runs and show break point locations. But when I try to debug the site by selecting attach to process from debug menu and select the browser process (IE8 or Mozilla), nothing happens and the process doesn't hit the break point. What am I doing wrong?



Thanks in advance for the help.





Facebook presentations

Where can I find all presentations by facebook on their technologies and architecture ? Any recommendations for some impressive presentations by facebook, thanks !





Difference between default constructor and paramterless constructor?

A default constructor has no parameters. And nor does a constructor that you write with no parameters. So what is the ultimate difference in c#?



Added to this when you inherit a default constructor and a parameterless constructor are they exposed on the inheritting type exactly the same? Because my IOC container doesn't seem to think so. (Unity).



Cheers,
Pete





Using Xuggle with Windows app in c#

Can anyone tell me the way to use XUGGLE with my windows app for rendering a series of images as video.I am new to this.Do i have to download XUGGLER or any dll is there which i have to refer in my application.
I tried to download it from following location "http://www.xuggle.com/downloads",but there is no download link provided at the site.Please help me .Any help will be appreciated





Asp.net digit grouping while typing

In asp.net project,
I want to group digits while typing in a textbox.
Example:
123456123456
123.456.123.456



How can i do this?





Stop Images from loading in UIWebView

I have a website that I wish to load in a UIWebView, but it is full of images and takes ages to load. The images are useless, and only serve to reduce the usability on the iPhone. I dont own the website so I cannot change the site's actual code.



The webpage is heavily linked in to the web with ASP.NET and AJAX (needs external files), so i dont think it is possible to have it load an HTML string.



I want to stop the images from loading altogether. So how do i block them? Change the HTML code as its loading somehow, or block images from being loaded?





can we call two functions onClick event

I am trying something like this



<div onclick="check_update('personal_details') ; showUser(2)">Click me </div>


but only check_update('personal_details') is getting called . I want to execute two separate functions at the same time when DIV is clicked. Any help will be great for me as I am still in a learning phase. Thanks in advance.





Solaris pkgadd ignores dependencies

I have a Solaris package with depend file. When I install the package, it ignores the dependencies.



My depend file looks like this:




P SUNWcsu Core Solaris, (Usr)

P XXCore My core package




I am able to install the package even if XXCore is not installed.
My Prototype looks like this:




i pkginfo

i depend

i request




Thanks in advance.





In what way is this a wsgi middleware?

I thought I understood the WSGI specification. So I'm looking at this Django module https://github.com/django/django/blob/master/django/middleware/locale.py and I just don't see how it's an implementation of a wsgi middleware as pep0333 explains it.



I was expecting a signature somewhere, such as



def __call__(self, environ, start_response)


as well as a small routine that would call another application and handle its returned value.



Could someone explain where's the server bit and where's the application in this middleware?





Equals() method is called on existing object or incoming object in collections

Can anyone please clarify when we check equality on collections, equals() method is called on incoming object or on those objects which are there in collection. for ex.
If a Set or a Hashmap has objects object1, object2 and object3 and a fourth object called object4 tries to get into the Set or it is compared with the already existing three objects in case of hashmap then equals() method is called on this fourth object and the already existing three objects are passed one by one or reverse is true.?





What's the relation between WS and socket.io?

I just installed socket.io for the first time, and at the end it gave me this message:



To install WS with blazing fast native extensions, use
<npm install ws --ws:native>


What does that mean? Is WS replacement for socket.io? I googled around and I can't figure it out. Or is it replacement for node.js? Or is it something I can install alongside socket.io and node.js?



Also I assume the message refers to this ws?





How to Get a Column number in Excel by its Column name using C#

I created an Excel application using C# with MVVM model. In that excel I created some columns as template columns. For example I am having some columns like Unit, Cost and Quantity. Now I want to find the exact column number of "Quantity" .



How can i get that particular column(Quantity) number? can any one tell me some method to achieve this?



Thanks.





How does Alternating Bit Protocol work?

From Wikipedia entry on ABP ( http://en.wikipedia.org/wiki/Alternating_bit_protocol ):




When A sends a message, it resends it continuously, with the same
sequence number, until it receives an acknowledgment from B that
contains the same sequence number. When that happens, A complements
(flips) the sequence number and starts transmitting the next message.



When B receives a message that is not corrupted and has sequence
number 0, it starts sending ACK0 and keeps doing so until it receives
a valid message with number 1. Then it starts sending ACK1, etc.




I simply do not get it.



I understand the pretext and the whole thing with acknowledgements, but the process itself is described differently in different publications (a



In particular:




  1. What does it mean "...and keeps doing so"? Does it mean that the receiver can send two consecutive acks down the ack channel without any activity from the sender at all? I.e. at that point it is not synchronized with the sender at all?


  2. What does it mean "resends continuously"? Same as above - is sender completely independent of the receiver during this resending?




There is an alternative coverage of the way it works here, but it gives a conflicting picture again: http://staff.science.uva.nl/~psf/specifications/abp.html





Hover event stops working after sorting divs

I'm working on an application which renders out images side by side. When hovering an image a hidden class is revealed showing information of the image.



I also have a sort function so that one can sort the images by points (highest first, descending) instead of the default sort (date). Both hovering and sorting works fine, except for one thing.



When the images is sorted by points and rendered out again, hovering the images doesn't work. I have looked at the generated code and it looks the same, but regardless that it doesn't work.



I would really appreciate som help here, thanks!



<div id="images">
<div class="image">
<div class="post">
// other code here
<div class="postDesc">
// other code here
<p class="postDescContent">Points: 10</p>
</div
</div>
</div>
<div class="image">
<div class="post">
// other code here
<div class="postDesc">
// other code here
<p class="postDescContent">Points: 20</p>
</div
</div>
</div>
// and so one...
</div>


sorting function:



sortByPoints: function() {
var contents = $('div#images div[class^="image"]');

contents.sort(function(a, b) {

var p1= parseInt($('p.postDescContent', $(a)).text().replace('Points:','').trim()),
p2 = parseInt($('p.postDescContent', $(b)).text().replace('Points:','').trim());
return p1 < p2;

});

var images = $('#images');

images.empty();
images.append(contents);
}


hover function:



$('.image').hover(function () {
$(this).find('.postDesc').toggle();
});




Setting Image Property Stretch to "UniformToFill" doesnt work well on WINRT

I'm using XAML/C#. and I'm trying to set the Image's Stretch property to UniformToFill. it doesn't work as expected. The Images get trimmed, this is my xaml:



<DataTemplate>
<Grid VariableSizedWrapGrid.ColumnSpan="{Binding ColumnSpan}" Margin="5">
<Image Stretch="UniformToFill" Source="{Binding ImageHQ}" />
<StackPanel VerticalAlignment="Bottom" Background="#AA000000">
<TextBlock Margin="5,5,5,0" FontSize="26" Text="{Binding Name,Mode=OneWay}" FontFamily="Arial Black" />
<TextBlock Margin="5,0,5,5" FontSize="24" Text="{Binding Section,Mode=OneWay}" Foreground="{Binding SectionColor,Mode=OneWay}" />
</StackPanel>
</Grid>
</DataTemplate>


Is there something wrong with my code?





ImageView - how to inflate or add programatically?

I am programatically adding ImageView, but still I have no success. Is there any simple way, how to add ImageView into Activity programatically?



Thx



Edit:



I have tried this and it is not working.



                for(Bitmap b: photoField){
try{
Log.d("BIT", "Bitmapa "+b);
if(b!=null){
ImageView imv=new ImageView(PoiDisplay.this);
imv.setImageBitmap(b);
}
}catch (NullPointerException e) {
e.printStackTrace();
}
}




how to make footer right hand side and left hand side as curve using css

![Actual Result of css and html files given below][1]![Expected Result image][2]
Hi All,
I have a table which has two rows and three columns.
The first row serves the purpose of body and The second row serves the purpose of footer.
I want to design footer using css.so that the look and feel is better.
However i can add the image However, there is gap between between each image.so it has not come out well.
As i mentioned above the row (tr) has three columns(td) and each td has one-one image.


Below is the code of html.

//left css class

//middle css class



some text


some text


//right css class

The Css class code are given below:
td.FooterLeftBG //css class for left td and left td is used to make left hand side curve footer
{
background: url('footer-leftbg.png') bottom left;
height:35px;
width:12px;
padding:0px;
float:right;
}
td.FooterRightBG // css class for right td and right td is used to make right hand side curve footer
{
background: url('footer-right-bg.png') bottom right;
height:35px;
padding:0px;
width:12px;
float:left;
}
td.FooterBG // css class for td where the footer holds some contents.
{
background:url('footer-middle-bg.png');
background-repeat:repeat-x;
border-collapse:collapse;
height:35px;
width:5px;
} Please help.I have been trying from 1week:( i have tried through google also.



Expected Format:


[1]: http://i.stack.imgur.com/c7ULg.png
[2]: http://i.stack.imgur.com/2J4zW.png




How do I set up a check box with ASP MVC in my view?

I have the following class:



   public class City {  
public string Name { get; set; }
public bool CityValid { get; set; }
}


I know how to set up the name but how can I set up the CityValid field so it acts like a checkbox. I'd like to do this without using HTML helpers.





Calling ShowDialog in BackgroundWorker

My background worker is doing a sync task, adding new files, removing old ones etc.



In my background worker code I want to show a custom form to user telling him what will be deleted and what will be added if he continues . with YES/NO buttons to get his feedback.



I wondering if it is ok to do soemthing liek this in background worker's doWork method ?
if it is not safe how should I do it



Please advise..



private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
MyForm f = new MyForm();
f.FilesToAddDelete(..);
DialogResult result = f.ShowDialog();
if(No...)
return;
else
//keep working...
}




Is it possible to detect the entire face region (only) in IOS?

I need to detect the full face region in my app...
Is it possible to detect that region ?



Currently i was using the CIDector to get the face features...
CIDector detects only nose,left and right eye...



how do i detect the entire full face(not as square marked face entire space. I attached the image below exactly what is the need) from the source image...?



any idea or solution for this problem highly appreciated...



Thanks in advance....



Regards,



Spynet



enter image description here





jquery accordion not working with contents received from AJAX

I have a problem with an accordion not working when receiving contents from another page via AJAX. THe page is this one: http://jbm.utad.pt/testes/tempo/index.php



As soon as the page loads it sends a default city name to processtempo.php which with AJAX shoots the results back to a div:



In the processtempo.php I have the HTML for an accordion but the jQuery for it is in index.php. Is this accordion not working because the HTML have to be in the main page or did I screw up with the jQuery?



You can view the accordion jQuery script in the source... I haven't yet put it in specific js file.



Thanks so much for all the help possible and sorry for this vague question



Cheers





jQuery Tabs - getting selected tab on page reload

I'm usig the jQuery Tabs funtion from jqueryfromdesigners, but only the first example works for me. That's the script-code I use:



    <script type="text/javascript" charset="utf-8">
$.noConflict();
$(function () {
var tabContainers = $('div.tabs > div');
tabContainers.hide().filter(':first').show();

$('div.tabs ul.tabNavigation a').click(function () {
tabContainers.hide();
tabContainers.filter(this.hash).show();
$('div.tabs ul.tabNavigation a').removeClass('selected');
$(this).addClass('selected');
return false;
}).filter(':first').click();
});
</script>


And here's the demo-code for displaying the tabs:



<div class="tabs">
<!-- tabs -->
<ul class="tabNavigation">
<li><a href="#first">Send a message</a></li>
<li><a href="#second">Share a file</a></li>
<li><a href="#third">Arrange a meetup</a></li>
</ul>

<!-- tab containers -->
<div id="first">
<p>Lorem ipsum dolor sit amet.</p>
</div>
<div id="second">
<p>Sed do eiusmod tempor incididunt.</p>
</div>
<div id="third">
<p>Ut enim ad minim veniam</p>
</div>
</div>


I have already changed the code for my use. In the tab-content-divs are now displayed informations which I grab via php. This content has many links in it that reloads the page when clicked.



How can I achieve that when the user clicks on a link in #tab2 the page reloads and displays the last selected #tab2? Now it always shows #tab0...



I would appreciate any hint on this!



Cheers!