Saturday, 14 September 2013

why keyup don't fire with backspace in my case?

why keyup don't fire with backspace in my case?

I try to only let the user to register if they filled all of the fields
correctly.
I check whether the field has a valid class to determine whether all are
valid or not. Then using the on() to bind keyup focusout, i hide the
fakeButton and show the real working button.
var $inputs = $("input[type=text], input[type=password]");
$inputs.on("keyup focusout", function(){
if ( $inputs.filter('.valid').length === 4 ) {
$("#fakeButton").hide();
$("#send").css("display","block");
}else{
$("#fakeButton").show();
$("#send").css("display","none");
}
});
my partial html
<div>
<input type="button" id="fakeButton" value="Register"/>
<input type="button" id="send" name="send" value="Register"/>
</div>
the result: it's working fine when i fill up the field accordingly, from
top to bottom.. but something wrong when i go back and hit backspace on
the field, the class valid go away, the event don't show the fake button,
it delay.. (i need to focus or keyup one more time then it work)
http://www.photojoiner.net/JoinedImages/b2c0b64d-8da8-400a-a133-fec190bd6a83.jpg

Make customView scrollable when drew line became more than View size

Make customView scrollable when drew line became more than View size

I am using a custom View and plotting line of double size of Custom View
Following is my Custom View in xml
<HorizontalScrollView
android:layout_width="780dp"
android:layout_height="300dp"
android:layout_x="20dp"
android:layout_y="180dp">
<com.cdl.mircam.ScrollLineView
android:id="@+id/RectroGraphView"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
>
</com.cdl.mircam.ScrollLineView>
And this is my ScrollLineView view class code. As you can see my line is
more than double size of custom view. but when I am running it is not even
plotting any line.
I want whenever my line goes out of size, custom view has to be scrollable.
public ScrollLineView(Context context, AttributeSet attrs)
{
super(context, attrs);
pTestPaint.setColor(Color.RED);
setHorizontalScrollBarEnabled(true);
setWillNotDraw(false);
}
@Override
protected void onDraw(Canvas StoredPlotCanvas)
{
super.onDraw(StoredPlotCanvas);
StoredPlotCanvas.drawLine(0, 150, 2500, 150, pTestPaint);
StoredPlotCanvas.drawLine(0, 200, 1000, 200, pTestPaint);
}
Any help?

Using layoutparams in relativeLayout with dp

Using layoutparams in relativeLayout with dp

I m making an app and i want to be able to move a view using its margins
dynamically. I tried using this :
RelativeLayout.LayoutParams params =
(RelativeLayout.LayoutParams)cover.getLayoutParams();
params.leftMargin= 470;
params.topMargin= 20;
cover.setLayoutParams(params); (cover is an ImageView)
The problem with this code its that it uses px instead of dp. I also tried
using DisplayMetrics to convert my px values to dp but failed . Can you
help me ?

Friday, 13 September 2013

Single lettered function names in jquery/json?

Single lettered function names in jquery/json?

Can someone please explain what this code does. The thing that I found
most irritating about this function is its single-lettered name. How can i
know what is the purpose of this function and what invokes this funciton.
function i() {
$(".main_section").delegate(".saveExam", "click", function () {
ename = $("#addmore").val();
$.ajax({
url: "saveNewExam.php",
type: "POST",
data: {
examId: ename
},
dataType: "html",
success: function (e) {}
});
window.location.reload()
})
}

OpenOffice Calc Stock Chart Type 1: data do not appear

OpenOffice Calc Stock Chart Type 1: data do not appear

I want to create a Stock Chart of Type 1 in OpenOffice Calc. In this
variant, supposedly, each line represents just the range between the low
and high prices, so you should only need two data columns, plus perhaps a
column to serve as labels. In order to learn how this works, I tried
copying the contents exactly from the sample spreadsheet on the OpenOffice
Calc help page for Stock Charts, leaving out the column labels, which are
as follows: Transaction volume, Opening price, Low (bottom price), High
(top price), Closing price. I reproduce my spreadsheet below.
Monday 2500 20 15 25 17
Tuesday 3500 32 22 37 30
Wednesday 1000 15 15 17 17
Thursday 2200 40 30 47 35
Friday 4600 27 20 32 31
I made sure that the numerical data columns all had the right format (I
think): I checked "Format Cells" and found that every cell was set as
Number/General. All the numbers were automatically right-aligned.
If I highlighted all six columns and five rows in the spreadsheet and
selected Insert -> Chart and chose Stock Chart, I would get a visible
display in my chart for Type 2, 3, or 4, but not 1. I also tried only
highlighting the "low" and "high" columns (and only the five rows with
data), but I still got an empty Type 1 chart. The scale demarcations
appear on the left, with horizontal lines (and the scale seems to be
correct), but there are no lines representing the data themselves.
I tried this whole procedure and had the identical results both in
OpenOffice 3 and OpenOffice 4. This is on Mac OS X 10.8.4.
What am I doing wrong? Thanks!

How do I save, fetch and manage a nested collection with backbone and marionette?

How do I save, fetch and manage a nested collection with backbone and
marionette?

I've looked through all the existing information about this, and just
can't get find a complete example or get my head around it - I'm new to
backbone/marionette.
I am using localstorage for persistence. I have a collection of game
models, each game model contains a collection of scorecard models as an
attribute.
var GameList = (function(){
return Backbone.Collection.extend({
model: Game,
localStorage: new Backbone.LocalStorage('datastore')});
var Game = Backbone.Model.extend({
localStorage: new Backbone.LocalStorage('datastore'),
defaults: {
name : '',
scorecards: new ScorecardList(),
created : 0
},
initialize : function() {
if (this.isNew()) this.set('created', Date.now());
}
});
I fetch the game collection when the app starts and render a list of games.
// Populate the main gamelist here
app.gameList = new GameList();
app.gameList.fetch();
When a game is clicked I pass the game id to a route that does a get of
the scorecard collection for that game and I render a list of scorecards.
So far so good.
game: function(param){
var g = app.gameList.get(param);
var m = new Backbone.Model({showBack:true,showSettings:true,title:
g.get('name')});
var header = new Header({model:m});
app.layout.header.show(header);
app.layout.main.show(new ScorecardListCompositeView({
collection : new ScorecardList(g.get('scorecards')),
model: g,
transitionIn: "fade",
transitionOut: "fade"
}));
The issue I'm having is that I cannot seem to find the right way to then
create a new scorecard within the scorecard collection and save it so that
the scorecard, scorecard collection and game collection are all in sync.
addPlayer: function () {
var s = new Scorecard({playerName:this.ui.playerName.val()});
this.collection.add(s);
//this.model.set({ scorecards: this.collection });
this.model.save({wait:true});
this.hideAddForm();
// NO IDEA WHAT TO DO HERE TO ENSURE CHANGES ARE REFLECTED??
}
It would be much appreciated if someone could point me to an example of
this to look at, I can't really post a fiddle without reworking everything
so I'm hoping this is enough to go on and I can figure it out with a
little nudge via an example.

How do I use MCRYPT in PHP to encode AES128 with IV?

How do I use MCRYPT in PHP to encode AES128 with IV?

Here is what I got:
$username = "username";
$password = "password";
$companyID = "companyID";
function encodeAES($u, $p, $c){
$original = "$u,$p,$c";
$key = "myKey";
$IV = "00000000";
return rtrim(base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key,
$original, MCRYPT_MODE_CBC, $IV)), "\0\3");
}
Error is:
Fatal error: Call to undefined function mcrypt_encrypt() on line 9
print encodeAES($username, $password, $companyID);