Tuesday, May 22, 2012

How secure are Cookies when set by an ASP.NET web application?

I want to know how secure a cookie is and if it can be read by other applications other than the one that set it.



I want to set a cookie that will store some sensitive data for my site to read at any time.



Can other applications read cookies that my application sets? If so, do I need to encrypt the data stored in the cookie?



NOTE: I do not have access to SSL.





Android ListView image resize

I have a lazy-loading ListView populated with images gotten over the network. The list rows are set to wrap_content, so once the image loads it resizes and the full scale image will be displayed. It looks great when scrolling down, but when scrolling up the rows resize and force the bottom rows off the screen. How can I prevent this jumpy scrolling while scrolling up?



----- EDIT:



The images are comics of varying sizes. Some are 2 or 3 frames where they aren't very tall. Others are single frame comics where they are much taller. The image needs to take up the full width and the height should not cut off any of the comic.





Can I reference a complete Ruby Net::HTTP request as a string before sending?

I'm using Net::HTTP in Ruby 1.9.2p290 to handle some, obviously, networking calls.



I now have a need to see the complete request that is sent to the server (as one long big String conforming to HTTP 1.0/1.1.



In other words, I want Net::HTTP to handle the heavy lifting of generating the HTTP standard-compliant request+body, but I want to send the string with a custom delivery mechanism.



Net::HTTPRequest doesn't seem to have any helpful methods here -- do I need to go lower down the stack and hijack something?



Does anyone know of a good library, maybe other than Net::HTTP, that could help?



EDIT: I'd also like to do the same going the other way (turning a string response into Net::HTTP::* -- although it seems I may be able to instantiate Net::HTTPResponse by myself?





Can't compile gSOAP with WS-Security support (i.e. wsse-plugin)

On a linux system, I want to create a client app using gSOAP-2.8.8 that interacts with a SOAP service build upon WCF. Therefore, I went through the following:



wsdl2h -t typemap.dat -o myService.h myService.wsdl    
soapcpp2 -Igsoap/import -CLix myService.h


And replaced '#include soapH.h' in wsseapi.h with soapcpp2-generated soapH.h as mentioned in wsseapi.h



Then, the critical step is to manually add the following lines to myService.h



#import "wsse.h"

struct SOAP_ENV__Header"
{
mustUnderstand // must be understood by receiver
_wsse__Security *wsse__Security; ///< TODO: Check element type (imported type)
};


...and compile those files like



g++ -DWITH_DOM -DWITH_OPENSSL -Igsoap -Igsoap/import -Igsoap/plugin -o test \
myService.cpp soapC.cpp soapmyServiceProxy.cpp gsoap/stdsoap2.cpp gsoap/dom.cpp \
gsoap/custom/duration.c gsoap/plugin/wsseapi.cpp gsoap/plugin/smdevp.c gsoap/plugin/mecevp.c \
-L/usr/lib -lssl -lcrypt


I do get object files for all my sources;-) but still end up with two errors at linking stage.



soapC.cpp:203: undefined reference to `soap_in_ns4__duration(soap*, char const*, long long*, char const*)'
soapC.cpp:676: undefined reference to `soap_in_ns4__duration(soap*, char const*, long long*, char const*)'


Edit: As a workaround I currently substitute soap_in_ns4__duration() with soap_in_xsd__duration(), which is implemented in custom/duration.c



Nevertheless, can anyone give me a hint whats going wrong here?! Thanks in advance





how to 'ror 3.2' with 'yui 3.5'?

Trying to write my first RoR application with YUI framework. Was googling for ror+yui manuals with no success. So i went to YUI site. YUI says:



// Put the YUI seed file on your page.
<script src="http://yui.yahooapis.com/3.5.1/build/yui/yui-min.js"></script>


Where it's suppossed to be putted in RoR app?



I've tried to app/assert/javascripts/yui-min.js.

As a result i got <html class="yui3-js-enabled"> in every page. Supposing YUI is working now i've tried to copy-paste "Work with the DOM" example from YUI's page to app/public/index.html. And an error i've received:

Uncaught ReferenceError: YUI is not defined.



Sorry for my English and thanks in advance



P.S.

Tutorial/Suggestions on YUI with Ruby on Rails wasn't helpful for me.





How do i access the information in an hl7 message parsed with nHapi

I am learning how to use nHapi. As many have pointed out, there's not much documentation. Following this doc I've been able to parse a message using the library. But I can't figure out how to access that message using an object model (which is what I really want nHapi to do). Essentially, I want to take an HL7 message as a string and access it using the object model, in the same way that LINQ to SQL takes a database record and lets you access it as an object. I found Parsing an HL7 without apriori messageType knowledge, but it seems to be about something else because the code in the post returns a string instead of an HL7 object (like I need). In the documentation I linked to above they seem to access the parts of a message using a "query"--but I can't find the materials to query IMessages in the library.



Here is the code I'm using, with a line showing what I want to do...



Imports NHapi.Base
Imports NHapi.Base.Parser
Imports NHapi.Base.Model



Module Module1

Sub Main()

Dim msg As String = "MSH|^~\&|SENDING|SENDER|RECV|INST|20060228155525||QRY^R02^QRY_R02|1|P|2.3|QRD|20060228155525|R|I||||10^RD&Records&0126|38923^^^^^^^^&INST|||"
Dim myPipeParser As PipeParser = New PipeParser()
Dim myImsg As IMessage = myPipeParser.Parse(msg)
Dim msgType As String = myImsg.GetStructureName
Dim mySendingFacilityName As String = myImsg.getSendingFacility() //this is what I want

End Sub




How to let a method accept two types of data as argument?

this is somewhat the same question as I've asked some time ago:
How to let a method accept two types of data as argument?



Yet the current situation differs.. a lot.



Take this:



public FormResourceSelector(Dictionary<string, Effect> resourceList, string type)


Alright, nothing wrong with it.
Now I try to run this:



FormResourceSelector frs = new FormResourceSelector(AreaEffect.EFFECTS, "Area effect");
FormResourceSelector frs2 = new FormResourceSelector(DistanceEffect.EFFECTS, "Distance effect");


Both AreaEffect and DistanceEffect (custom classes) derive from Effect.



public class AreaEffect : Effect
{
public static Dictionary<string, AreaEffect> EFFECTS = new Dictionary<string, AreaEffect>();
...
}


For some reason I get the following error while making the new FormResourceSelector instance:



Argument 1: cannot convert from 'System.Collections.Generic.Dictionary<string,SCreator.AreaEffect>' to 'System.Collections.Generic.Dictionary<string,SCreator.Effect>'  


at:



new FormResourceSelector(AreaEffect.EFFECTS, "Area effect");


I suspect the dictonary being a harass, but I don't really know how to fix this.



Thanks for helping me out :).



~ Tgys



EDIT: Easiest would be to allow input of both Dictionary and Dictionary as resourceList in the first code snippet I've given.





Pass parameters to function call in event trigger

Right now I have this



jQuery('.widget-prop').keyup(function() {
var prop = jQuery(this).attr('id');
var val = jQuery(this).val();

stuff;
}


and



jQuery('.widget-prop').click(function() {
var prop = jQuery(this).attr('id');
var val = jQuery(this).val();

stuff;
}


two functions are the same, so I'd like to simplify it by defining external function and calling it with



jQuery('.widget-prop').click('myFunction');


but how would I pass parameters to myFunction?



function myFunction(element) {
stuff;
}


Thanks





Setting up Twitter OAuth without 3rd party libraries

Continuation from Get twitter public timeline, json+C#, no 3rd party libraries



I'm still new to C# and oAuth so please bear with me if I fail to understand anything



I've created a C# class named oAuthClass, and these are the variables I currently have:



    static class oAuthClass
{
public static void run()
{
int oauth_timestamp = GetTimestamp(DateTime.Now);
string oauth_nonce = PseudoRandomStringUsingGUID();
string oauth_consumer_key = "consumer key here";
string oauth_signature_method = "HMAC-SHA1";
string oauth_version = "1.0";
}
}


I've read up on OAuth Signatures, and I chose to use HMAC-SHA1 for now, I don't know how to generate the signature, I'm also extremely confused after reading and seeing stuff like HTTP-Encodings and Base-Strings and whatnot (I've no idea what they mean at all), but my guess is to create a URL that's "Http-encoded", like spaces->"%20"?



In summary:
-What are base-strings?



-Am I right on the spaces->%20 example?



-HMAC-SHA1 involves a message and a key, is the consumer secret the message? Is the consumer key the key then?



-How to create a signature through the use of the HMAC-SHA1 algorithm



-If I do manage to create the signature, how do I pass these values to Twitter?



I could use



http://example.com?consumer_key=asdf&oauth_signature=signaturevalue&etc., 


but I've read and apparantly people use HTTP-Headers or something (again, I don't really know what this is)



Thank you! Again, no 3rd party libraries allowed :(





How to get the id of the user that send the request?

In my app there is a MultiFriendSelector to invite friends.



I want that the recipient see in the canvas page the id of the user that has sent the request via MultiFriendSelector.



I need to get the id without using PHP or other server side language, but I can use javascript or fbml for example.





how to insert and select in mysql with android?

LoginActivity.java



package tn.pack.ordre.enregistrer;


import org.json.JSONException;
import org.json.JSONObject;

import tn.pack.ordre.HomeActivity;
import tn.pack.ordre.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class LoginActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ecran_accueil);

}

public void btn_enrg(View v){
startActivity(new Intent(getApplicationContext(),EnregistrerActivity.class));
}


public void btn_login(View v) {

EditText u = (EditText) findViewById (R.id.editText_username);
EditText p = (EditText) findViewById (R.id.editText_motdepasse);

String username = u.getText().toString();
String password = p.getText().toString();

UserFunctions userFunction = new UserFunctions();
JSONObject json = userFunction.loginUser(username, password);
Intent home =new Intent(getApplicationContext(),HomeActivity.class) ;

// check for login response
try {
if (json.getString("success") != null) {
// loginErrorMsg.setText("");
String res = json.getString("success");
if (Integer.parseInt(res) == 1) {
// user successfully logged in
// Store user details in SQLite Database
JSONObject json_user = json.getJSONObject("user");
System.out.println(" "+json_user.getString("userName")+" "+json_user.getString("created_at"));
//Bundle pass = new Bundle();
//pass.putString("userName", json_user.getString("userName"));
//pass.putString("created_at", json_user.getString("created_at"));
//home.putExtra("INTENT_EXTRA_STRING", pass);
//Log.d("test","uid:"+json.getString("uid"));
startActivity(home);
finish();
} else {
// Error in login
Toast.makeText(getApplicationContext(), "Erreur login",3000).show();
}
}
} catch (JSONException e) {
System.out.println("Connecter: "+e.toString());
}

}


}


JSONParser.java -parser class to parse api response JSON.



package tn.pack.ordre.enregistrer;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

public class JSONParser {

static InputStream is = null;
static JSONObject jObj = null;
static String json = "";

// constructor
public JSONParser() {

}

public JSONObject getJSONFromUrl(String url, List<NameValuePair> params) {

// Making HTTP request
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params));

HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();

} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
json = sb.toString();
Log.e("JSON", json);
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}

// try parse the string to a JSON object
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}

// return JSON String
return jObj;

}
}


EnregistrerActivity.java



package tn.pack.ordre.enregistrer;

import org.json.JSONException;
import org.json.JSONObject;

import tn.pack.ordre.enregistrer.UserFunctions;

import tn.pack.ordre.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

public class EnregistrerActivity extends Activity {


private TextView error;


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Fixe la mise en page d'une activité
setContentView(R.layout.inscription);

}



public void btn_valider() {

String user=((EditText)findViewById(R.id.et_un)).getText().toString();
String password=((EditText)findViewById(R.id.et_pw)).getText().toString();
String rpassword=((EditText)findViewById(R.id.et_rpw)).getText().toString();
String cin=((EditText) findViewById(R.id.et_cin)).getText().toString();
// String region = ((Spinner) findViewById (R.id.spinner_rg)).getSelectedItem().toString();



UserFunctions userFunction = new UserFunctions();
JSONObject json = userFunction.registerUser(user,password,rpassword,cin);
try {

error=(TextView)findViewById(R.id.textViewerrer);
if (json.getString("success") != null) {

String res = json.getString("success");
if (Integer.parseInt(res) == 1) {

error.setText("enregistrement ok");


} else {
error.setText("erreur pendant l'enregistrement");

}
}
} catch (JSONException e) {
e.printStackTrace();
System.out.println("btnRegister: "+e.toString());
}


}

public void Annuler(View v) {

startActivity(new Intent(getApplicationContext(),LoginActivity.class));

}
}


UserFunctions.java -all the functions will interact with JSONParser.



package tn.pack.ordre.enregistrer;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;

public class UserFunctions {

private JSONParser jsonParser;

private static String loginURL = "http://10.0.2.2/webservice/index.php";
private static String registerURL = loginURL;

private static String login_tag = "login";
private static String register_tag = "register";

// constructor
public UserFunctions(){
jsonParser = new JSONParser();
}


public JSONObject loginUser(String userName, String password){
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("tag", login_tag));
params.add(new BasicNameValuePair("userName", userName));
params.add(new BasicNameValuePair("password", password));
JSONObject json = jsonParser.getJSONFromUrl(loginURL, params);
// return json
// Log.e("JSON", json.toString());
return json;
}


public JSONObject registerUser(String userName, String password,String rpassword, String cin){
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("tag", register_tag));
params.add(new BasicNameValuePair("userName", userName));
params.add(new BasicNameValuePair("cin", cin));
params.add(new BasicNameValuePair("password", password));
params.add(new BasicNameValuePair("rpassword", rpassword));
// params.add(new BasicNameValuePair("region", region));


// getting JSON Object
JSONObject json = jsonParser.getJSONFromUrl(registerURL, params);
// return json
return json;
}


}


config.php -This file contains constant variables to connect to database.



<?php

/**
* Database config variables
*/
define("DB_HOST", "localhost");
define("DB_USER", "root");
define("DB_PASSWORD", "");
define("DB_DATABASE", "appactel");
?>


DB_Connect.php -This file is used to connect or disconnect to database.



<?php
class DB_Connect {

// constructor
function __construct() {

}

// destructor
function __destruct() {
// $this->close();
}

// Connecting to database
public function connect() {
require_once 'include/config.php';
// connecting to mysql
$con = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
// selecting database
mysql_select_db(DB_DATABASE);

// return database handler
return $con;
}

// Closing database connection
public function close() {
mysql_close();
}

}

?>


DB_Functions.php -This file contains functions to store user in database, get user from database.



 <?php

class DB_Functions {

private $db;

//put your code here
// constructor
function __construct() {
require_once 'DB_Connect.php';
// connecting to database
$this->db = new DB_Connect();
$this->db->connect();
}

// destructor
function __destruct() {

}

/**
* Storing new user
* returns user details
*/
public function storeUser($userName,$cin , $password, $repassword) {
$uuid = uniqid('', true);
$hash = $this->hashSSHA($password);
$encrypted_password = $hash["encrypted"]; // encrypted password
$salt = $hash["salt"]; // salt
$result = mysql_query("INSERT INTO user_appmobile(unique_id, user_name, cin, encrypted_password,encrypted_repassword, salt, created_at, updated_at) VALUES('$uuid','$userName', $cin,'$encrypted_password', $encrypted_repassword,'$salt', NOW())");
// check for successful store
if ($result) {
// get user details
$uid = mysql_insert_id(); // last inserted id
$result = mysql_query("SELECT * FROM user_appmobile WHERE uid = $uid");
// return user details
return mysql_fetch_array($result);
} else {
return false;
}
}

/**
* Get user by email and password
*/
public function getUserByCinAndPassword($cin, $password) {
$result = mysql_query("SELECT * FROM user_appmobile WHERE cin = '$cin'") or die(mysql_error());
// check for result
$no_of_rows = mysql_num_rows($result);
if ($no_of_rows > 0) {
$result = mysql_fetch_array($result);
$salt = $result['salt'];
$encrypted_password = $result['encrypted_password'];
$hash = $this->checkhashSSHA($salt, $password);
// check for password equality
if ($encrypted_password == $hash) {
// user authentication details are correct
return $result;
}
} else {
// user not found
return false;
}
}

/**
* Get user by userName and password
*/
public function getUserByUserNameAndPassword($userName, $password) {
$result = mysql_query("SELECT * FROM user_appmobile WHERE user_name = '$userName'") or die(mysql_error());
// check for result
$no_of_rows = mysql_num_rows($result);
if ($no_of_rows > 0) {
$result = mysql_fetch_array($result);
$salt = $result['salt'];
$encrypted_password = $result['encrypted_password'];
$hash = $this->checkhashSSHA($salt, $password);
// check for password equality
if ($encrypted_password == $hash) {
// user authentication details are correct
return $result;
}
} else {
// user not found
return false;
}
}

/**
* Check user is existed or not
*/
public function isUserExisted($cin) {
$result = mysql_query("SELECT cin from user_appmobile WHERE cin = '$cin'");
$no_of_rows = mysql_num_rows($result);
if ($no_of_rows > 0) {
// user existed
return true;
} else {
// user not existed
return false;
}
}

/**
* Check user is existed or not
*/
public function isUserNameExisted($userName) {
$result = mysql_query("SELECT username from user_appmobile WHERE username = '$userName'");
$no_of_rows = mysql_num_rows($result);
if ($no_of_rows > 0) {
// user Name existed
return true;
} else {
// user Name not existed
return false;
}
}
public function isCinExisted($cin) {
$result = mysql_query("SELECT username from user_appmobile WHERE cin = '$cin'");
$no_of_rows = mysql_num_rows($result);
if ($no_of_rows > 0) {
// user Name existed
return true;
} else {
// user Name not existed
return false;
}
}

/**
* Encrypting password
* @param password
* returns salt and encrypted password
*/
public function hashSSHA($password) {

$salt = sha1(rand());
$salt = substr($salt, 0, 10);
$encrypted = base64_encode(sha1($password . $salt, true) . $salt);
$hash = array("salt" => $salt, "encrypted" => $encrypted);
return $hash;
}

/**
* Decrypting password
* @param salt, password
* returns hash string
*/
public function checkhashSSHA($salt, $password) {

$hash = base64_encode(sha1($password . $salt, true) . $salt);

return $hash;
}


}
?>


index.php -This file plays role of accepting requests and giving response. GET and POST requests.



<?php

/**
* check for POST request
*/
if (isset($_POST['tag']) && $_POST['tag'] != '') {
// get tag
$tag = $_POST['tag'];

// include db handler
require_once 'include/DB_Functions.php';
$db = new DB_Functions();

// response Array
$response = array("tag" => $tag, "success" => 0, "error" => 0);

// check for tag type
if ($tag == 'login') {
// Request type is check Login
$userName = $_POST['userName'];
$password = $_POST['password'];

// check for user
$user = $db->getUserByUserNameAndPassword($userName, $password);
if ($user != false) {
// user found
// echo json with success = 1
$response["success"] = 1;
$response["uid"] = $user["unique_id"];
$response["user"]["userName"] = $user["user_name"];
$response["user"]["cin"] = $user["cin"];
$response["user"]["created_at"] = $user["created_at"];
$response["user"]["updated_at"] = $user["updated_at"];
echo json_encode($response);
} else {
// user not found
// echo json with error = 1
$response["error"] = 1;
$response["error_msg"] = "Incorrect username or password!";
echo json_encode($response);
}
} else if ($tag == 'register') {
// Request type is Register new user


$userName = $_POST['userName'];
$cin = $_POST['cin'];
$password = $_POST['password'];
$repassword = $_POST['repassword'];
$region = $_POST['region'];

// check if user is already existed a separer (cas cin & cas username )
if ( ($db->isUserNameExisted($userName))&&($db->isCinExisted($cin)) ) {
// user is already existed - error response
$response["error"] = 2;
$response["error_msg"] = "User already existed";
echo json_encode($response);
} else {
// store user
$user = $db->storeUser($userName, $cin, $password, $repassword);
if ($user) {
// user stored successfully
$response["success"] = 1;
$response["uid"] = $user["unique_id"];
$response["user"]["userName"] = $user["user_name"];
$response["user"]["cin"] = $user["cin"];
$response["user"]["created_at"] = $user["created_at"];
$response["user"]["updated_at"] = $user["updated_at"];
echo json_encode($response);
} else {
// user failed to store
$response["error"] = 1;
$response["error_msg"] = "Error occured in Registartion";
echo json_encode($response);
}
}
} else {
echo "Invalid Request";
}
} else {

echo "Access Denied";
}
?>


Data Base:



    -- Base de données: `appactel`
--
-- Structure de la table `user_appmobile`
--

CREATE TABLE IF NOT EXISTS `user_appmobile` (
`uid` int(11) NOT NULL AUTO_INCREMENT,
`unique_id` varchar(23) NOT NULL,
`user_name` varchar(20) NOT NULL,
`cin` int(10) NOT NULL,
`password` varchar(20) NOT NULL,
`repassword` varchar(20) NOT NULL,
`salt` varchar(10) NOT NULL,
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,
PRIMARY KEY (`uid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;


the problem:



enter image description here



enter image description here



enter image description here



05-21 14:34:01.185: D/ddm-heap(223): Got feature list request
05-21 14:34:01.405: D/dalvikvm(223): GC freed 515 objects / 46800 bytes in 91ms
05-21 14:34:35.785: D/AndroidRuntime(223): Shutting down VM
05-21 14:34:35.785: W/dalvikvm(223): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
05-21 14:34:35.785: E/AndroidRuntime(223): Uncaught handler: thread main exiting due to uncaught exception
05-21 14:34:35.835: E/AndroidRuntime(223): java.lang.IllegalStateException: Could not find a method btn_valider(View) in the activity
05-21 14:34:35.835: E/AndroidRuntime(223): at android.view.View$1.onClick(View.java:2020)
05-21 14:34:35.835: E/AndroidRuntime(223): at android.view.View.performClick(View.java:2364)
05-21 14:34:35.835: E/AndroidRuntime(223): at android.view.View.onTouchEvent(View.java:4179)
05-21 14:34:35.835: E/AndroidRuntime(223): at android.widget.TextView.onTouchEvent(TextView.java:6541)
05-21 14:34:35.835: E/AndroidRuntime(223): at android.view.View.dispatchTouchEvent(View.java:3709)
05-21 14:34:35.835: E/AndroidRuntime(223): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
05-21 14:34:35.835: E/AndroidRuntime(223): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
05-21 14:34:35.835: E/AndroidRuntime(223): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
05-21 14:34:35.835: E/AndroidRuntime(223): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
05-21 14:34:35.835: E/AndroidRuntime(223): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
05-21 14:34:35.835: E/AndroidRuntime(223): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
05-21 14:34:35.835: E/AndroidRuntime(223): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
05-21 14:34:35.835: E/AndroidRuntime(223): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
05-21 14:34:35.835: E/AndroidRuntime(223): at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
05-21 14:34:35.835: E/AndroidRuntime(223): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
05-21 14:34:35.835: E/AndroidRuntime(223): at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
05-21 14:34:35.835: E/AndroidRuntime(223): at android.os.Handler.dispatchMessage(Handler.java:99)
05-21 14:34:35.835: E/AndroidRuntime(223): at android.os.Looper.loop(Looper.java:123)
05-21 14:34:35.835: E/AndroidRuntime(223): at android.app.ActivityThread.main(ActivityThread.java:4363)
05-21 14:34:35.835: E/AndroidRuntime(223): at java.lang.reflect.Method.invokeNative(Native Method)
05-21 14:34:35.835: E/AndroidRuntime(223): at java.lang.reflect.Method.invoke(Method.java:521)
05-21 14:34:35.835: E/AndroidRuntime(223): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
05-21 14:34:35.835: E/AndroidRuntime(223): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
05-21 14:34:35.835: E/AndroidRuntime(223): at dalvik.system.NativeStart.main(Native Method)
05-21 14:34:35.835: E/AndroidRuntime(223): Caused by: java.lang.NoSuchMethodException: btn_valider
05-21 14:34:35.835: E/AndroidRuntime(223): at java.lang.ClassCache.findMethodByName(ClassCache.java:308)
05-21 14:34:35.835: E/AndroidRuntime(223): at java.lang.Class.getMethod(Class.java:1014)
05-21 14:34:35.835: E/AndroidRuntime(223): at android.view.View$1.onClick(View.java:2017)
05-21 14:34:35.835: E/AndroidRuntime(223): ... 23 more
05-21 14:34:35.875: I/dalvikvm(223): threadid=7: reacting to signal 3
05-21 14:34:35.895: I/dalvikvm(223): Wrote stack trace to '/data/anr/traces.txt'
05-21 14:34:39.275: I/Process(223): Sending signal. PID: 223 SIG: 9
05-21 14:34:39.924: D/dalvikvm(232): GC freed 542 objects / 47816 bytes in 84ms
05-21 14:35:15.314: W/ActivityThread(254): Application tn.pack.ordre is waiting for the debugger on port 8100...
05-21 14:35:15.326: I/System.out(254): Sending WAIT chunk
05-21 14:35:15.878: I/dalvikvm(254): Debugger is active
05-21 14:35:16.005: I/System.out(254): Debugger has connected
05-21 14:35:16.005: I/System.out(254): waiting for debugger to settle...
05-21 14:35:16.215: I/System.out(254): waiting for debugger to settle...
05-21 14:35:16.443: I/System.out(254): waiting for debugger to settle...
05-21 14:35:16.645: I/System.out(254): waiting for debugger to settle...
05-21 14:35:16.866: I/System.out(254): waiting for debugger to settle...
05-21 14:35:17.126: I/System.out(254): waiting for debugger to settle...
05-21 14:35:17.348: I/System.out(254): waiting for debugger to settle...
05-21 14:35:17.585: I/System.out(254): waiting for debugger to settle...
05-21 14:35:17.829: I/System.out(254): waiting for debugger to settle...
05-21 14:35:18.077: I/System.out(254): waiting for debugger to settle...
05-21 14:35:18.300: I/System.out(254): waiting for debugger to settle...
05-21 14:35:18.511: I/System.out(254): waiting for debugger to settle...
05-21 14:35:18.721: I/System.out(254): waiting for debugger to settle...
05-21 14:35:18.930: I/System.out(254): waiting for debugger to settle...
05-21 14:35:19.159: I/System.out(254): waiting for debugger to settle...
05-21 14:35:19.366: I/System.out(254): waiting for debugger to settle...
05-21 14:35:19.576: I/System.out(254): waiting for debugger to settle...
05-21 14:35:19.795: I/System.out(254): debugger has settled (1483)




Compare Lists with custom objects, which have a common superclass

I have a Metamodel that's built like this:



class ModelElement
{
string id;
}

class Package : ModelElement
{
List<Package> nestedPackages;
List<Class> ownedClasses;
}

class Class : ModelElement
{
}


Now I've built two Models and I want to check if they're identical. I'd like to compare the ID's of the Elements and I don't want to write a method for any type of Element.



Package a; //pretend both have classes
Package b; //and nested packages
compare(a.nestedPackages, b.nestedPackages);
compare(a.ownedClasses; b.OwnedClasses);


Since Class and Package both inherit from ModelElement, both have IDs. So I want to write a Function "compare" which compares the IDs. I thought of using Generics but the generic datatype doesn't have the attribute "id". Any ideas?





Image format to put inside PDF's to have fast rendering

I would like to know which image format inside PDF's is rendered fastest. I tested mupdf code and I figured out that image decoding takes an important part in rendering time. So I would like to know if there are image formats that would not impact very much on cpu load.





C macro: how do I concatenate a name and a number which is result of a math operation (done also by preprocessor)?

Consider the following code:



1. #define SUFFIX 5-5
2. #define XFUNC_0( x ) (100 * x)
3. #define XFUNC_1( x ) (101 * x)
4. #define XFUNC_2( x ) (102 * x)
5. #define CATX( x, y ) x##y
6. #define CAT( x, y ) CATX( x, y )
7. #define XFUNC CAT( XFUNC_, SUFFIX )
8. #if XFUNC(2) == 200
...... etc
N.

How to access an association in view from one POCO with several references to another

Sorry about the title; couldn't think of a better one.



Any way, I'm accessing an associated property in my view like so:



@Model.Company.CompanyName // No problems here...


The model is a viewmodel mapped to an EF POCO. The Model has several properties associated to the Company table. Only one of the properties in the model share the same name as the PK in the Company table. All the other properties reference the same table:



public class MyModelClass 
{
public int Id { get; set; }
public int CompanyId { get; set; }
public int AnotherCompanyId { get; set; } // References CompanyId
public int AndAnotherCompanyId { get; set; } // References CompanyId

public Company Company { get; set; }
}

public class Company
{
public int CompanyId { get; set; }
public string CompanyName { get; set; }
public string Address { get; set; }
}


I'm obviously missing something here.



How can I get the names of the other companies in my Model?



Any help is greatly appreciated.





You don't have permission to access /schema/beans/spring-beans-3.1.xsd on this server

I am using spring framework in one of my application. It was working fine till now. But today in morning when I tried to run my application, it was throwing errors for not able to intialise spring framework. So I tried loading xsd files in the browser but in vain because it was showing forbidden page to me. And the page contains "You don't have permission to access /schema/beans/spring-beans-3.0.xsd on this server". I even tried loading 3.1 xsd, 2.5 xsd but not able to access any of them and showing same error page.



I know, I must download xsd and put them into my classpath but i haven't done and now i got this.



Can anyone please help me out of this? Or if any body has 3.0 xsd then can you please give it to me.



I want following xsds:




  1. spring-beans-3.0.xsd

  2. spring-context-3.0.xsd

  3. spring-mvc-3.0.xsd



and xsds that are being called by the above one internally.



Thank you every one.





Iphone : Applying strechable images to a button disables it

I am sure I am doing something stupid here. I build a category on top of UIButton which I want it to take all of the background images assigned to it (different states) and convert them to stretchable versions and reapply them back to the button.



- (void)enableBackgroundImageStrechingWithLeftCapWidth:(float)leftCapWidth withTopCapHeight:(float)topCapHeight;
{

UIImage *backgroundimageNormal = [self backgroundImageForState:UIControlStateNormal];

if (backgroundimageNormal != nil)
{
UIImage *stretchImage = [backgroundimageNormal stretchableImageWithLeftCapWidth:leftCapWidth topCapHeight:topCapHeight];
[self setBackgroundImage:stretchImage forState:UIControlStateNormal];
}

UIImage *backgroundimageSelected = [self backgroundImageForState:UIControlStateSelected];

if (backgroundimageSelected != nil)
{
UIImage *stretchImage = [backgroundimageSelected stretchableImageWithLeftCapWidth:leftCapWidth topCapHeight:topCapHeight];
[self setBackgroundImage:stretchImage forState:UIControlStateSelected];
}

UIImage *backgroundimageHighlighted = [self backgroundImageForState:UIControlStateHighlighted];

if (backgroundimageHighlighted != nil)
{
UIImage *stretchImage = [backgroundimageHighlighted stretchableImageWithLeftCapWidth:leftCapWidth topCapHeight:topCapHeight];
[self setBackgroundImage:stretchImage forState:UIControlStateHighlighted];
}

UIImage *backgroundimageDisabled = [self backgroundImageForState:UIControlStateDisabled];

if (backgroundimageDisabled != nil)
{
UIImage *stretchImage = [backgroundimageDisabled stretchableImageWithLeftCapWidth:leftCapWidth topCapHeight:topCapHeight];
[self setBackgroundImage:stretchImage forState:UIControlStateDisabled];
}
}


Seems to work except the button is now not clickable





How to count items per category?

I want to make a filtering of products on a site.
Something like this:



Department
- lassics (13,395)
- Literary (111,399)
- History (68,606)
...

Format
- HTML (3,637)
- PDF (8)
- Audio CD (443)
...

Language
- English (227,175)
- German (10,843)
- French (10,488)
...


How to count products per category? A separate SQL-query for each category would be too slow because there are too many products and categories. I suggest caching is not an option too.



Maybe it makes sense to use MySQL EXPLAIN queries (though it not always provide adequate information)? Or maybe using sphinx search engine for counting?... What is the best way to do this? Thanks.





Git: how to specify file names containing octal notation on the command line

For non-ASCII characters in file names, Git will output them in octal notation. For example:



> git ls-files
"\337.txt"


If such a byte sequence does not represent a legal encoding (for the command line's current encoding), I'm not able to enter the corresponding String on command line. How can I still invoke Git commands on these files? Obviously, using the String which is displayed by git ls-files does not work:



> git rm "\337.txt"
fatal: pathspec '337.txt' did not match any files


Tested on Windows, with msysgit 1.7.10 (git version 1.7.10.msysgit.1)





How to tell gcc to stop using built-in functions?

I am using my own modified glibc. I saw in the compiled code that compiler was not using many standard library functions from my glibc when I linked with it. Then I put -fno-builtin flag. Things got better and I could see that many functions which were not taken from glibc were now taken from there, such as malloc.



However, still for many functions, such as mmap, the compiler is using some built-in-code. Now how can I ask the compiler to please exclusively use the code from glibc rather than using its built-in-functions?