Tuesday, April 10, 2012

How can I display a UIBarButtonItem without a border?

In IB I can select a UIBarButtonItem, set it to Plain, Custom and apply an Image and it looks fine in a UIToolbar or UINavigationBar.



When I try to do this in code, I get a border:



backButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"arrowBack"] 
style:UIBarButtonItemStylePlain
target:self
action:@selector(backButtonClicked:)];


How can I get a UIBarButtonItem without a border? I want it to be Plain and Custom





Difference among Comet servers and XMPP servers

In my next planned project I suppose to implement an online classroom website in which I want to share a black board (Say a simple text area) among the Tutor and the participating online students {These all are logined through the website}. Whatever the text Tutor writes over the Black board has to be seen by the other participants in Real-time.



I want to use Java as my development platform.



To implement this I started googling on PUSH technology. I read that XMPP implementation servers and XMPP libraries can be used to implement near-realtime applications like collaberative applications/mutiparty games/IM applications etc.,
But I also read about BlazeDS usage for real-time and low-lattency web applications.



My questions are,




  1. what is the difference among these XMPP java based implementation and BlazeDS? Is not both the techs final goal is to achieve low-lattency web apps using PUSH technology?


  2. What is the difference among Comet servers and XMPP Servers? Do they just differ in the way they implement the PUSH technology or any thing else?




I am confused. Please someone explain me these little more so that I will know what I do before I do the things and where to start on next in my project.



Thanks





jquery validation word count integration

How can I integrate word count into bassistance.de validation? For example, i dont want people to enter more than 50 words, and it should show an error to indicate it.



<form action="done.php" method="post" id="mainform"  class="validate">
<textarea name="message" rows="4" id="message" class="required" ></textarea>
</form>


Here is all I have, but i dont know where to go from here



$(document).ready( function() {
$("form.validate").validate({
submitHandler: function(form) {
form.submit();
}
})


});



any assistance here would be appreciated, i'm not familiar with this plugin at all.





Signature method in xml signature

In signature method in xml signature you have specify in this format : SignatureMethod.RSA_SHA1 but when using normal signature you just do



Cipher c1=Cipher.getInstance("RSA");


So what is the difference between these two?





Get Canvas coordinates after scaling up/down or dragging in android

I'm developing an application in which I'm pasting images, doing drawing and painting on canvas. This app can also Scale up/down the canvas or drag it to different location.
My problem is: I can't get the correct canvas coordinates after scaling or dragging the canvas. I want to draw finger paint after the canvas is scaled or dragged but unable to retrieve the right place where i've touched..:(
Also I'm new bee. Here is the code.



@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);

canvas.save();
//canvas.translate(mPosX, mPosY);
canvas.scale(mScaleFactor, mScaleFactor, super.getWidth() * 0.5f,
super.getHeight() * 0.5f);
mIcon.draw(canvas);
for (Path path : listPath) {
canvas.drawPath(path, paint);
}
canvas.restore();
}

public TouchExampleView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);

}

@Override
public boolean onTouchEvent(MotionEvent ev) {
// Let the ScaleGestureDetector inspect all events.
mScaleDetector.onTouchEvent(ev);

final int action = ev.getAction();
switch (action & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN: {
final float x = ev.getX();
final float y = ev.getY();

mLastTouchX = x;
mLastTouchY = y;
mActivePointerId = ev.getPointerId(0);
break;
}

case MotionEvent.ACTION_MOVE: {
final int pointerIndex = ev.findPointerIndex(mActivePointerId);
final float x = ev.getX(pointerIndex);
final float y = ev.getY(pointerIndex);

// Only move if the ScaleGestureDetector isn't processing a gesture.
if (!mScaleDetector.isInProgress()) {
final float dx = x - mLastTouchX;
final float dy = y - mLastTouchY;

mPosX += dx;
mPosY += dy;

invalidate();
}

mLastTouchX = x;
mLastTouchY = y;

break;
}

case MotionEvent.ACTION_UP: {
mActivePointerId = INVALID_POINTER_ID;
break;
}

case MotionEvent.ACTION_CANCEL: {
mActivePointerId = INVALID_POINTER_ID;
break;
}

case MotionEvent.ACTION_POINTER_UP: {
final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
final int pointerId = ev.getPointerId(pointerIndex);
if (pointerId == mActivePointerId) {
// This was our active pointer going up. Choose a new
// active pointer and adjust accordingly.
final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
mLastTouchX = ev.getX(newPointerIndex);
mLastTouchY = ev.getY(newPointerIndex);
mActivePointerId = ev.getPointerId(newPointerIndex);
}
break;
}
}

float objectNewX,objectNewY;
if (mScaleFactor >= 1) {
objectNewX = ev.getX() + (ev.getX() - super.getWidth() * 0.5f) * (mScaleFactor - 1);
objectNewY = ev.getY() + (ev.getY() - super.getHeight() * 0.5f) * (mScaleFactor - 1);
} else {
objectNewX = ev.getX() - (ev.getX() - super.getWidth() * 0.5f) * (1 - mScaleFactor);
objectNewY = ev.getY() - (ev.getY() - super.getHeight() * 0.5f) * (1 - mScaleFactor);
}

if (ev.getAction() == MotionEvent.ACTION_DOWN) {
path = new Path();
path.moveTo(objectNewX,objectNewY);
path.lineTo(objectNewX,objectNewY);
} else if (ev.getAction() == MotionEvent.ACTION_MOVE) {
path.lineTo(objectNewX,objectNewY);
listPath.add(path);
} else if (ev.getAction() == MotionEvent.ACTION_UP) {
path.lineTo(objectNewX,objectNewY);
listPath.add(path);
}

return true;
}

private class ScaleListener extends
ScaleGestureDetector.SimpleOnScaleGestureListener {
@Override
public boolean onScale(ScaleGestureDetector detector) {
mScaleFactor *= detector.getScaleFactor();

// Don't let the object get too small or too large.
mScaleFactor = Math.max(0.1f, Math.min(mScaleFactor, 5.0f));

invalidate();
return true;
}
}




Twitter integration with rails 3 app

I want to login using twiter app for that i used gem 'omniauth-twitter' now please tell me whats app url in twitter when i want to use localhost:3000 i gave http://0.0.0.0:3000 as url



and in call back url my index page
like



localhost:3000/index
my app not able to redirect to twiiter page on click on this link
http://localhost:3000/auth/twitter



please some body help me .....





SharePoint 2010: formula that counts number of months till end of year

I am looking for a formula, that will count number of remaining months from a specific date (date field chosen by user) till end of 2012 year.



Platform is SharePoint Server 2010



Example:




  • User will choose date 14.4.2012

  • Another field will return number 9 in calculated formula





UTF-8 Server.UrlEncode problem in ASP Classic

I'm having a bit of bother URL encoding a string of UTF-8 encoded text to pass over HTTP. I am using Server.URlEncode in classic ASP (vbscript) to do the encoding on the "é" character.



It produces the following string,



%C3%83%C2%A9



The system I am talking to over HTTP is PHP however and it cannot decode this string. Using a PHP encoder at http://www.albionresearch.com/misc/urlencode.php the same character encoded using the PHP URL encoding method comes out as,



%E9



Does anyone know how I can successfully encode my UTF-8 encoded strings in my ASP so that the PHP system can successfully decode them?





Best way to mix polymorphic association and hierarchies?

Assuming the base table design (no. 3) from this link:



What is the best way to implement Polymorphic Association in SQL Server?



enter image description here



I would like to add (to the object table) a ObjectType and a parentObjectID for each object.ObjectID. I need this because I have objects that are children to other objects. These child objects can have child objects only of different types.



So is it a good idea to put the names of the tables in the objectType column? This may be bad for security to store some of the schema in a table... Any other approach that I can use?



Here is an example :



Table Posts -> id | ObjectID(fk ref. Object.OnjectID) | Content

Table Comments -> id | ObjectID(fk ref. Object) | Posted_on_ObjectID(fk ref. Object.ObjectID) | Content



Basically posts and comments will be unique entities in Object super table . But because the comments can be made only for post entities and not for comments entities i have to store the types for each entity(ObjectID).





undefined variable php updating mysql data

This is the code for attempting to do a update on mysql data errors stating undefined variable


mysql_connect ("localhost", "root", "");
mysql_select_db("supplierdetails");
$con = mysql_connect("localhost", "root", "");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
//Run a query
$result = mysql_query ("SELECT * FROM users WHERE id= '$id'");
while ($row = mysql_fetch_array($result))
{
$username=$row['username'];
$password=$row['password'];
}
$query = "UPDATE users SET username = '$username', password = '$password' WHERE id = '$id'";
$result = @mysql_query($query);
//Check whether the query was successful or not
if($result) {
header("message= Users Updated");
}else {
die("Query failed");
}
?>




How to extract content from facebook using R

I want to extract the facebook updates messages using R, but I'm having some trouble. I tried following the tutorials given in http://www.brocktibert.com/blog/2012/01/19/358/ but I am getting the following error



$error$type
[1] "OAuthException"
$error$code
[1] 190


Is there another way to extract messages from facebook?





Duplicate a javascript prototype instance?

I'm given an instance "aNode" of a prototype called "Node". Following this discussion (http://stackoverflow.com/questions/728360/copying-an-object-in-javascript), I attempt to:



var newNode = clone(aNode);


The clone function goes like:



function clone(obj) {
if (null == obj || "object" != typeof obj) return obj;
var copy = obj.constructor();
for (var attr in obj) {
if (obj.hasOwnProperty(attr)) copy[attr] = obj[attr];
}
return copy;
}


Despite obj.consturctor() properly refers to aNode's constructor, copy is "underfined". Can't find why :(



Is this method wrong, or am I missing something :) ?



Thanks,
J.





Levenshtein distance in regular expression

is there possiblity how to include levenshtein distance in regular expression query?



Except making union between permutations. Like searching "hello" with L.d. 1



.ello | h.llo | he.lo | hel.o | hell.


this is a lot stupid and un-usable for larger numbers of L.d.





Maven dependency: exclude one class

For example I have dependency



<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.5.6</version>
</dependency>


Can I exclude one class, for example org/slf4j/Marker.class ?





Nvidia Cuda video encoder - output frame size

I am using the Nvidia cuda video encoder nvcuvenc, and until now I was not able to encode an H.264 video with an output frame size different from the input frame size.



My question : did anyone use this encoder with an output frame size different from the input frame size successfully?



More details :



The sample is the following "C:\ProgramData\NVIDIA Corporation\NVIDIA GPU Computing SDK 4.0\C\src\cudaEncode" , and the encoding works fine for the default config file "704x480-h264" with the plush video. But the other config files (720x480-h264 for example) don't work and don't seem to be correct because the input size is different than the actual video in the sample. (I tested with other videos as well, but had no luck)



To be precise : sometimes the encoder crashes with an access violation, sometimes it encodes but the result is messed up.





C++ Read Access violation error

I am currently getting an "0xC0000005: Access violation reading location 0xcccccce0." error and I have tried diagnose the problem...I think the problem comes in when my rule of 3 that I have defined comes in play and points me to here.



size_type size() const
{ // return length of sequence
return (this->_Mysize); <---------------------this line
}


I'm actually not sure if there is any problem at all, I have been dwelling on this for days on end.



here is my rule of three



ArrayStorage::ArrayStorage(){
myArray = new string[7079];
}

ArrayStorage::~ArrayStorage(){
delete[] _data;
delete[] myArray;
}

ArrayStorage::ArrayStorage(const ArrayStorage &A) {
_size = A.size();
_data = new string [size()];
for (int i = 0; i < size(); ++i)
_data[i] = A[i];
}

ArrayStorage& ArrayStorage::operator=(const ArrayStorage &A){
if (this != &A) {
delete [] _data;
_size = A.size();
_data = new string [A.size()];
for (int i = 0; i < size(); ++i) {
_data[i] = A[i];
}
}
return *this;
}

const string& ArrayStorage::operator[](int i) const{
assert((i >= 0) && (i < size()));
return _data[i];
}

string& ArrayStorage::operator[](int i){
assert((i >= 0) && (i < size()));
return _data[i];
}




bxSlider plugin not loading the classes

I am using bxSlider plugin on my site it is working fine on my local machine but on my staging server it is not working the problem is i think it is not loading the classes because I cant see the bx-wrapper, bx-window etc classes on my staging server while these class comes on my local machine.
The jquery.bxSlider.min.js is there in js folder on staging server
Anyone has any idea why its not working ?



Thanks in advance





Why eval is not working in this snippet?

I would like to know whats wrong with following JavaScript code -



<html>
<script type="text/javascript">

var p = eval('new { "Color":"Red"}');

alert(p.Color);
</script>
</html>


It is giving me JavaScript error as -



Message: Object doesn't support this action
Line: 4
Char: 1
Code: 0
URI: file:///C:/Users/276822/Desktop/b.html




Association of User and Post

Please Im trying to create an application where i can post like twitter, but i was the users name to be posted under their respective posts



My Post_controller looks like this



def index
@posts = Post.all(:order => "created_at DESC")
@users = User.find(:all)
#@user_id = current_user.find(params[:id])

respond_to do |format|
format.html
end
end



def create
@post = current_user.posts.create(:message => params[:message])
@user.id = current_user.username
end


the models both have the correct association and tables are having User_id as primary on User table and Foreign on the Post Table, how do i create a method to be a able to have my index view show the post and name.`





compare two successive rows - group by

i have a model as below



ID     Date                    BoitierNumber
1 07/04/2012 14:01:46 1
2 07/04/2012 14:01:50 2
3 07/04/2012 14:01:50 3
4 07/04/2012 14:01:56 1
5 07/04/2012 14:02:06 1
6 07/04/2012 14:02:10 2


I have grouped rows by (BoitierNumber)



*boitier Number 1

1 07/04/2012 14:01:46
4 07/04/2012 14:01:56
5 07/04/2012 14:02:06

*boitier Number 2

2 07/04/2012 14:01:50
6 07/04/2012 14:02:10

*boitier Number 3

3 07/04/2012 14:01:50


To do this i have used this code



var groups = context.Essais.GroupBy(p => p.BoitierNumber)
.Select(g => new { GroupName = g.Key, Members = g });

foreach (var g in groups)
{
Console.WriteLine("Members of {0}", g.GroupName);

foreach (var member in g.Members.OrderBy(x=>x.Id))
{
Console.WriteLine("{0} {1}", member.Id,member.Date);
}

}


For the moment everything works fine
now i want to compare the date of two successives grouped rows
if row[i].date>row[i-1].date i will delete row[i-1]



*boitier Number 1

1 07/04/2012 14:01:46
4 07/04/2012 14:01:56

boitier Number 1 ---> Date of row of Id 4 > Date of row of ID 1
then i will delete row of ID 1


Please Help, i don't know how to do this ?