Wednesday, April 11, 2012

how to capture events from dynamically added layouts in Android

In my android project, I need to add controls dynamically into my main activity screen. I created one xml (row.xml) which is added on button click on main screen. I want to capture events from the controls (button) given in row.xml.



Can anybody help me where and how to capture onClick events from newly added layouts?



Also, I want to add many child layout elements, do I need to write separate onClick methods for all the child views added dynamically?



row.xml



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_Time"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:orientation="horizontal" >


<EditText
android:id="@+id/editText_FromTime"
android:layout_width="216dp"
android:layout_height="wrap_content"
android:focusableInTouchMode="false"
android:hint="@string/hintFromTime" />

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:orientation="horizontal" >

<Button
android:id="@+id/button_Delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/btnDelete" />
</LinearLayout>

</LinearLayout>


So, when I click on Add Time slot button, I get a newly created row with two elements.



I want to delete this row when I click on Delete button. Do I need to have a viewID also to delete this newly-added-view?





Error C2275 while creating a COM smart-pointer within "if" statement

Why can't i



if (IUnknownPtr p = anotherComPtr) {} //error C2275: 'IUnknownPtr' : illegal use of this type as an expression


while i can



if (int* a = anotherPointer) {}


IUnknownPtr is defined throught _COM_SMARTPTR_TYPEDEF(IUnknown, __uuidof(IUnknown)) (like any others smart pointers i use)



How can i create a com smartptr within if statement and verify is it valid or not? Thank you.



I use VS 2008



p.s. This is not about is it good way of coding or not, it's about error C2275.





Hibernate dialect for Oracle Database 11g?

Is there a Hibernate dialect for Oracle Database 11g? Or should I use the org.hibernate.dialect.Oracle10gDialect that ships with Hibernate?





Creating / generating a '.eml' file from SQL Server dbmail

Is it possible to generate .eml file from SQL Server dbmail? I running SQL Server 2008 R2.



I have a requirement to create an 'email sandbox' where email will be staged before being delivered to our SMTP server for delivery. This will allow application generated (and hopefully dbmail), email to be viewed and approved before final delivery. I can achieve this in .NET by specifying a 'pickupDirectoryLocation' property for a SmtpClient object.



Questions: is there a way I can do this with SQL Server generated email as well?



Thanks





RegEx in javascript. Allow only letters, comma and punctuation

I try to make a RegEx for validating a form in javascript. The RegEx should only allow letters comma and punctuation. For instance I have this string:



Hi, this is a test of RegEx. Does it work


I've tried the following



/^[A-Za-z0-9,. ]{3,50}$/; 


But it doesn't seems to work. Solutions?



Thanks!





How to write a controller for validation of multipaged form?

I'm struggling with the proper organisation of a (MVC) Controller for my validation of a multipaged form. The problem is that I not only have to check whether the user input is existant at all, but I have to match it with different databases (depending on the field), too. I also need that database-data that results from the user-input for different view-options.



It's unclear for me where I should put that validation at all. I would like to put not too detailed things into the controller, but at the same time I don't like models using each other (without the controller).



Here's a basic example from a controller, the steps stand for different stages/pages of the form:



// GET VARIABLES FROM $_POST + $_GET
private function make_environment()
{
// PUT ALL VARIABLES INTO ARRAY
$vars = array();
if(!empty($_GET)) { $values = array_merge($vars,$_GET); }
if(!empty($_POST)) { $values = array_merge($vars,$_POST); }

// PUT ALLOWED VARIABLES INTO PROPERTY
foreach($this->properties as $property)
{
if(isset($values[$property]))
{
$this->properties[$property] = htmlspecialchars(trim($values[$property]));
}
}

}


// HANDLE DATA


// PRODUCES DATA FOR VIEW
private function set_data()
{
$data = '';
// CHOOSE DATA-OBJECT AND DATA-HANDLER
switch($this->properties['step'])
{
case 1:
// DATA HANDLER
$handler = new calendar($this->properties);
$data['calendar'] = $handler->return_data();
break;

case 2:
// DATA HANDLER
$handler = new form($this->properties);
$data['form'] = $handler->return_data();
break;
}

return $data;
}


// CREATE OR UPDATE VIEW

private function run_view($data)
{
new view('header','');

switch($this->properties['step'])
{
default:
new view('chooser','');
break;
case 1:
new view('calendar',$data['calendar'],$this->properties);
break;

case 2:
new view('form',$data['form'],$this->properties);
break;
}

new view('footer','');
}


At the moment the different 'handlers' (in set_data()) are querying the database, but prior to that I'd need a check whether the required fields have been submitted and whether those fields are valid (whether they exist in the database). I don't really know where to put that kind of validation. Propably in a separate model, but then I'd have to query the DB there and in the data-handler again. Maybe you got an idea ?!





PHP array only using the first line of text area for 'Get Meta Tags' Function

I am fairly new to PHP so please bear with me :)



What I am trying to do if place URL's into a text area, then pull in the meta data for each.



I have made the script, but when I place more then one URL into the text area it only returns data for the last URL entered, I thought maybe you guys can help me :)



<form method="POST">
<textarea name="TAData">
</textarea>
<input type="submit" value="submit"/>
</form>

<div id="checkboxes">
<input type="checkbox" name="vehicle" value="PR" /> Show me the PR<br />
<input type="checkbox" name="vehicle" value="KW Tag" /> Show me the KW tag<br />
<input type="checkbox" name="vehicle" value="Title Tag" /> Show me the Title tag<br />
</div>
<div id="checkboxes">
<input type="checkbox" name="vehicle" value="1stH1" /> Show me the 1st H1<br />
<input type="checkbox" name="vehicle" value="2ndH1" /> Show me the 2nd H1 tag<br />
<input type="checkbox" name="vehicle" value="SeedKW" /> Show me Seed KW's<br />
</div>

<div id="nofloat"></div>

<?php

//make the array
$TAarray = explode("\n", strip_tags($_POST['TAData']));

foreach ($TAarray as $key => &$line) { $line = trim($line); }
// get the meta data for each url
$tags = get_meta_tags($line);

unset($tags["content-type"]);
unset($tags["page-type"]);
unset($tags["page-topic"]);
unset($tags["audience"]);
unset($tags["content-language"]);

echo '<tr>';
foreach ($tags as $meta)
{
echo '<td>' . $meta . '</td>';
}
echo '</tr>';

?>




javascript onmouseover hide a div block

SO this is my code so far:



JS:



        <script type="text/javascript">
function Hide(srcField)
{
var x = srcField.getAttribute('name');
var string = new RegExp("hide_ID",'gi');

switch (x)
{
case "1":
var dataRows= document.getElementsByID("obrazovanje");
alert (dataRows[0].innerHTML);
dataRows[0].className.replace('',string);
break;
case "2":
var dataRows= document.getElementsByID("rad_iskustvo");
dataRows[0].className.replace('',string);
break;
case "3":
var dataRows= document.getElementsByID("strani_jezici");
dataRows[0].className.replace('',string);
break;
case "4":
var dataRows= document.getElementsByID("znanja_vjestine");
dataRows[0].className.replace('',string);
break;
case "5":
var dataRows= document.getElementsByID("osobine_interesi");
dataRows[0].className.replace('',string);
break;
}
}
</script>


CSS:



.hide_ID,
{
display:none
}


HTML:



    <a name="1"><h4><span name="1" onmouseover="Hide(this)">OBRAZOVANJE:</span></h4></a>

<div ID="obrazovanje">
<ul>
<li>2001.-2005. elektrotehnicar</li>
<li>2009.-2012. racunarstvo</li>
</ul>
</div>


the idea is that i want to hide the div block when i hover over the title that's in h4, but it doesn't seem to hide it... any ideas?
i started using replace but it still didn't work, before that it was just 'dataRows[0].className = "hide_ID"' but that didn't work either.



EDIT1:



so i changed the JS to:



                var x = srcField.getAttribute('name');

switch (x)
{
case "1":
var dataRow= document.getElementByID("obrazovanje");
dataRow.className += "hide_ID";
break;


the rest of the JS is also edited, but i didn't feel the need to paste it all)
but still no result.



also tried to change display:none to display:block but now results.



EDIT2:



the JS now looks like this:



        function Hide(id)
{
switch (id)
{
case "obrazovanje":
var dataRow= document.getElementByID("obrazovanje");
if ( dataRow.className.indexOf('hide_ID') == -1 ) dataRow.className += ' hide_ID';
else dataRow.className = 'obrazovanje';
break;
...


and the html is:



    <a name="1"><h4 class="menu" onmouseover="Hide('obrazovanje')">OBRAZOVANJE:</h4></a>

<div ID="obrazovanje" class="content">
<ul>
<li>2001.-2005. elektrotehnicar</li>
<li>2009.-2012. racunarstvo</li>
</ul>
</div>


and still it wont budge...





Manually delete facebook cookie in FOSFacebookBundle

I would like to manually delete the facebook cookie used by my application, in order to be able to regenerate a new access token when the user's one is not valid anymore.



How can I do that ?





Removing repeating component in a list

I have a python data-structure as follows:



A = [{'abc': 'kjkjl'},{'abc': 'hjhjh'},{'abc': '78787'}]


How can I remove the 'abc' from A and make a new list:



B = ['kjkjl','hjhjh','78787']




How to delete the border in android when an input text field is selected?

When i select a input text field the android default browser draw a border around the input text field?



I tried this, but it does nothing.



input[type="text"]:focus { border: none; outline: none;}


Is it possible to have no border around the input text field when the text field is selected in the android browser?





Dividing a square into N smaller squares and finding center coordinates of the N smaller squares

I have a square that has dimensions 10by10 and I want to divide it into 25 smaller squares with dimensions 2by2 so in the end I will have a 5by5 array.What I also want to do is find the center coordinates of each of the new squares. I have written the following code as a starting point, and it gives me the coordinates of the centers of the squares of the x(0) and y(0) coordinates. I have experimented with nesting, but that gave me y values that were to high. I know I need to keep one variable fixed and iterate the other in terms of it. I am just unsure as how to link them. If any one can help out or point to some documentation that will help with finding the off diagonal elements it would be appreciated. Thanks in advance.



def Cell_centers():
dx = 2
dy = 2 #length of cell side
N = 5 #number of cells
Xc = zeros(N) #array creation
Yc = zeros(N)
x1=0
y1=0

for i in range(N): #for loops to define cell centers
Xc[i] = dx/2 +x1
x1+=dx #increments x1 positions by dx
for j in range(N):
Yc[j] = dy/2 +y1
y1+=dy

centers = np.array((Xc, Yc), dtype=float)
return(centers)




Is it possible to use an std::string for read()?

Is it possible to use an std::string for read() ?



Example :



std::string data;



read(fd, data, 42);



Normaly, we have to use char* but is it possible to directly use a std::string ? (I prefer don't create a char* for store the result)



Thank's





underline text in UIlabel

How to underline a text that could be multiple lines of string?
I find some people suggest UIWebView, but it is obviously too heave a class for just text rendering.



My thoughts was to figure out the start point and length of each string in each line.
And draw a line under it accordingly.



I meet problems at how to figure out the length and start point forthe string. Can anybody help me on this?



I try to use -[UILabel textRectForBounds:limitedToNumberOfLines:], this should be the drawing bounding rect for the text right?
Then I have to work on the aligment ?
How can I get the start point of each line when it is center-justified and right justfied?



I am new here, so thank in advance.





Reading 2D Barcode from Images

i need library to read 2D barcode (datamatrix) from images on C# project (windows Forms) i tried it using other sdk's,but that sdk's are not free.Is there any free sdk is there for reading 2d Barcode from images?





How to add hyperlinkbuttons dynamically from c# codebehind to a stackpanel present in the listbox?

Hi i have a requirement i need your suggestion's and guidance for it:-



I have a set of phone numbers of type string separated by a comma , now i want to assign each phone number to hyperlink and on click of it will invoke the PhoneCallTask and make a call to that particular phone number.



1) So , how to assign each phone number to a hyperlink(should we dynamically generate the hyperlink? in c# codebehind)



2)if so , how to dynamically generate hyperlink buttons and add it to a stack panel present in a listbox ?



3)How would i know which Hyperlinkbutton is clicked?



4)All HyperlinkButton's would point to same hyperlink click event?



Thanks in Advance.





Unable to define oracle datasource on Jboss AS 7

I'm using Jboss AS 7.1.1.final and I'm trying to add an oracle Datasource:



<datasource jndi-name="java:jboss/datasources/DefaultDS" pool-name="DefaultDS" enabled="true" use-java-context="true">
<connection-url>jdbc:oracle:oci@TNS_NAME</connection-url>
<driver>oracle</driver>
<security>
<user-name>username</user-name>
<password>pwd</password>
</security>
</datasource>


And the driver:



<driver name="oracle" module="com.oracle.ojdbc">
<xa-datasource-class>oracle.jdbc.OracleDriver</xa-datasource-class>
</driver>


But when i start the server i get:



JBAS014775:    New missing/unsatisfied dependencies:
service jboss.jdbc-driver.oracle (missing) dependents: [service jboss.data-source.java:jboss/datasources/DefaultDS]


I have a module under modules/com/oracle/ojdbc/main:



<module xmlns="urn:jboss:module:1.0" name="com.Oracle.ojdbc">
<resources>
<resource-root path="ojdbc6.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
</dependencies>
</module>


and of course the jar is there.



Can someone please tell me what am I doing wrong here?





Creating SSRS style expressions (functions) in a .Net server application

We have a rather flexible application written in C# (.net 4.0) that copies data to different ERP systems around the company. It uses an XML file to determine the from and to ERP systems, the data source, credentials, and the columns to copy.



What we are seeing is that the is an interest in transforming the data as it is copied. So a part number with a product family, gets converted to just a product family. For example to do the following transformation 564-8911277 ==> 564 using SSRS functions this would be



=Left("564-8911277", instr(564-8911277", "-") - 1))


The thought is to put the expression in the XML file and have the system interpret the expression and transform the data.



I'm researching and working on a cost estimate to develop this feature, and wondering if there is anything out there that already exists that can be integrated into a .net application?



I've found a few things (scripting.net from 2001), but thought I'd reach out to the community to see what else is out there.



Thanks, Tim





Why does Chrome audit recommend me to minimize cookie size?

How can I minimize cookie size of my requests? Chrome seems to 'warn me' about my cookie size being 41B, which is not a lot at all, but is there a reason it warns me about it?



It is a PHPSESSID cookie, which I do not really know how to minimize. Any ideas?



My request responses themselves should already be Gzipped, but from what I know it is not possible to compress headers themselves, or is there?



Thanks! I'm just a little OCD about performance and audits that tell me I could do something better.





How to turn date into timestamp

How would i turn
2012-04-11 12:49:14
into a unixtime stamp?



I have tried



$time = mktime("2012-04-11 12:59:14");


and



$time = strtotime("2012-04-11 12:59:14");




Mobile network generations and bandwidth

I have couple of question related to mobile network generations:



1) While comparing generation of mobile network people mention that 1G and 2G has to use maximum bandwidth. What is bandwidth in this content and why they use maximum bandwidth?
2) 1G and 2G are narrow band networks. What is narrow band here?
3) 3G and 4G are wide band networks. Don't they use maximum bandwidth?



Thanks and Regards,
Deepa





Android : onRetainNonConfigurationInstance is not called on Screen orientation change

I have implemented onRetainNonConfigurationInstance() on one of my Activity to handle android screen orientation. Here is the code :



  @Override
public Object onRetainNonConfigurationInstance() {
Log.d("[DEBUG]", "onRetainNonConfigurationInstance : "
+ this.getClass().getName());
MyState state = new MyState();

return state;
}


I then installed the app on an android device. Here is the configuration :



Device : Samsung Nexus S
Android version : 4.0.4
Kernel version : 3.0.8-g6656123android-build@vpbs1 #1


When I debug the app on the phone by changing screen orientation, my onRetainNonConfigurationInstance() method is not called.



Even weird, I have added a log line in the onCreate() method of my Activity. According to the documentation, Android is supposed to re-create the activity when screen orientation happens. So I have something like the following :



public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mylist);
Log.d(Constants.LOG_TAG, "Oncreate : " + this.getClass().getName());
}


But here, the onCreate() method is not called when I change screen orientation on the device.



Have you guyz already experienced this issue ?



In the documentation, they also say that this method is deprecated and that instead I should use something related to Fragments etc. Can it be the reason why I don't have the method called ?



actually, I am implementing for 2.3.3 to 3.0 devices but my test device is 4.0.4 : Can it be the problem ? I thought there were some kind of backward compatibility between Android OS versions.



thanks in advance,





Building PyQT on CentOS 6


$%& CENTOS, and Riverbank, what's wrong with good old ./configure ???



Now, I have been trying to install PyQT for about 2 hours now, and I am lost.



I do:



PyQt-x11-gpl-4.9.1 # export QMAKESPE=linux-g++


But this does not work?



# python configure.py -w --confirm-license --qmake=/usr/lib64/qt4/bin/qmake -k                                                   
Determining the layout of your Qt installation...
/usr/lib64/qt4/bin/qmake -o qtdirs.mk qtdirs.pro
make -f qtdirs.mk
g++ -c -m64 -pipe -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_CORE_LIB -I/usr/lib64/qt4/mkspecs/linux-g++-64 -I. -I/usr/include/QtCore -I/usr/include -I. -o qtdirs.o qtdirs.cpp
g++ -m64 -Wl,-O1 -o qtdirs qtdirs.o -lQtCore -lpthread
./qtdirs
Error: Unable to find the qmake configuration file
/usr/lib64/qt47/mkspecs/default/qmake.conf. Use the QMAKESPEC environment
variable to specify the correct platform.


The README file does not provide that much of a great help, and at this point I really admire Debian and hate the only 1 Billion dollar open-source company.
Can someone here give me a tip how to build PyQT ?





Typecasting or accessing char array to integer array in Python

I have a char array in Python, which is read from a file e.g.



char_array = [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f]


how do i convert/typecast/access this to an array of integers like



int_array[0] = 0x03020100
int_array[1] = 0x07060504
int_array[2] = 0x0b0a0908
int_array[3] = 0x0f0e0d0c


similar to how one would access an array of bytes as integers in C/C++ i.e. type cast an unsigned char * to an unsigned long *.





How to release a variable using automatic reference counting? I do not want to set something to nil since it will create dangling pointers?

How to release anything while using arc? I do not want to set something to nil since it will create dangling pointers?





Building an Intrusion Detection System using fuzzy logic

I want to develop an Intrusion Detection System (IDS) that might be used with one of the KDD datasets. In the present case, my dataset has 42 attributes and more than 4,000,000 rows of data.



I am trying to build my IDS using fuzzy association rules, hence my question: What is actually considered as the best tool for fuzzy logic in this context?





Using Controller to Attach Events (sencha touch / extjs)

My experience in web programming is limited to intermediate, self-taught JS and jQuery with a dash of PHP. ExtJS is turning out to be an entirely different animal.



I can't figure out why my controller isn't doing what I expect, especially since I'm following the syntax that is used in the documentation (which is becoming increasingly useless as they fail to describe what is actually happening in the examples... but I digress).



Main.js



    Ext.define("cs.view.Main", {
extend: 'Ext.TabPanel',
tabBarPosition: 'bottom',

requires: [
'cs.view.form',
'cs.view.location',
'Ext.TitleBar',
'cs.controller.geolocate'
],

config: {
tabBar: {
docked: 'bottom',
},
defaults: {
flex: 1
},
items: [
{ xtype: 'form' },
{ xtype: 'location' }
]
},
});


form.js



Ext.define('cs.view.form', {
extend: 'Ext.form.Panel',
requires: 'cs.controller.geolocate',
xtype: 'form',
alias: 'widget.getLoc',

config: {
title: 'Home',
iconCls: 'home',
items: [
{
xtype: 'toolbar',
docked: 'top',
title: 'Client Finder'
},
{
xtype: 'textfield',
name: 'address',
label: 'address'
},
{
xtype: 'textfield',
name: 'dist',
label: 'distance(mi)'
},
{
xtype: 'button',
ui: 'confirm',
text: 'submit',
id: 'submitButton',
alias: 'widget.submitButton',
}
]
},
});


geolocate.js



Ext.define('cs.controller.geolocate', {
extend: 'Ext.app.Controller',

config: {
views: ['Main', 'form', 'location'],
control: {
aButton: {
tap: 'message'
}
},//control
refs: {
aButton: '#submitButton'
},//refs
},//config

message: function(){
Ext.Msg.alert("Success", "Finally!");
}
});




RCov for RSpec 2 not detecting coverage correctly? (not Rails!)

Preface

I've just started getting into Ruby and try to not only learn the language but also some development strategies. As kind of a beginner I'm concentrating on Test and Behaviour Driven Development. (yes, I'm doing both for comparison purposes)



With my small software project I'm using




  • UnitTest (TDD)

  • Cucumber (BDD)

  • Rspec (TDD and BDD)



On various places I encountered RCov as a tool for telling me how much of my actual code I'm really testing.



I set up the following RakeTask in my Rakefile for the covarage analysis of the UnitTests:



desc "Run RCov to get coverage of UnitTests"
Rcov::RcovTask.new(:rcov_units) do |t|
t.pattern = 'tests/**/tc_*.rb'
t.verbose = true
t.rcov_opts << "--html"
t.rcov_opts << "--text-summary"
t.output_dir = "coverage/tests"
end


This works fine and I'm getting a nice coloured HTML report in coverage/tests.



Problem Introduction

Similar I wrote the following RakeTasks for RCov to be used for coverage analysis of my specs:



desc "Run RCov to get coverage of Specs"
Rcov::RcovTask.new(:rcov_spec) do |t|
t.pattern = 'spec/**/*_spec.rb'
t.verbose = true
t.rcov_opts << "--html"
t.rcov_opts << "--text-summary"
t.output_dir = "coverage/spec"
end


Problem Definition

However, the generated HTML report in coverage/spec looks somehow incomplete and almost failed.



None of the tested method bodies are marked as covered and thus red. However, I'm 100% sure they are executed within the specs. Only the lines def method_name(args) and class ClassName are marked 'green'. (as well lines with attr_reader :instance_variable)



Am I missing something?






$: ruby --version  
ruby 1.8.7 (2011-02-18 patchlevel 334) [x86_64-linux]

$: rspec --version
2.8.0

$: rcov --version
rcov 0.9.11 2010-02-28

$: rake --version
rake, version 0.9.2




Process terminated when signaling a pthread waiting on "join"

I'm trying to implement a signal handler.
each pthread is created joinable, and is blocked upon all signals using sigprocmask.



The problem occurs when I send the thread a signal from another thread, using



pthread_kill(_threads[threadIndex], SIGHALT);


If the called pthread is waiting on pthread_join at the time the signal is sent, the whole proccess is terminated immidiately. However, if the thread is not waiting on join, it ignores the signal as expected. Any idea why does it happen and how to change it?



Thank you!





does array_merge works on array of integers?

Does array_merge works on array of integers.



$range = array_merge(range(1, 1)
, range(1,10));


and output is



array(11) { [0]=> int(1) [1]=> int(1) [2]=> int(2) [3]=> int(3) [4]=> int(4) [5]=> int(5) [6]=> int(6) [7]=> int(7) [8]=> int(8) [9]=> int(9) [10]=> int(10) } 


Edit:



You guys didn't understand my question. I was expecting that the second array would override the first, leaving only 1 element with 1 as a value. The result should have been



    array(10) { [0]=> int(1) [1]=> int(2) [2]=> int(3) [3]=> int(4) [4]=> int(5) [5]=> int(6) [6]=> int(7) [7]=> int(8) [8]=> int(9) [9]=> int(10) } 


Why isn't it so?