Monday, 19 August 2013

Display message in Knocout.js

Display message in Knocout.js

I have button called Fact. I want it to display message "true" when
someone clicks it. My HTML looks like this:
<div id="option">
<button data-bind="click: displayMessage">Fact</button>
<div data-bind="if: displayMessage">You are right.</div>
My Javascript is this:
ko.applyBindings({
displayMessage: ko.observable(false)
});
However, this is not working. Can someone please help.

EncryptedDataBagItem.load produces 'cannot convert nil into String'

EncryptedDataBagItem.load produces 'cannot convert nil into String'

I'm following the method described in this post for creating a DNS record
for a new server as Chef provisions it. I've created an encrypted data bag
item for my AWS credentials:
$ knife data bag show passwords aws --secret-file
.chef/encryted_data_bag_secret
aws_access_key: <my_access_key>
aws_secret_key: <my_secret_key>
id: aws
However, when I run the chef client, this line...
aws_creds = Chef::EncryptedDataBagItem.load('passwords', 'aws')
produces this error:
TypeError: can't convert nil into String
I've tried searching for the error, but while I can see evidence that
other people have encountered this, it's not clear what their problem was
or how it was resolved. What's going on here, and how can I fix it?

jqGrid TableDnD issue

jqGrid TableDnD issue

I created a table using jqGrid Plugin for jQuery and relying on following
demo, I want to drag and drop the rows of my table. Demo:
http://trirand.com/blog/jqgrid/jqgrid.html (New in version 3.3 -> Row Drag
and Drop)
When I try to drag a row, I get the error "TypeError: e is null" in
firebug. I searched for a solution to this problem but I didn't find
anything in this case... Moreover I tried to use the same version of
jQuery and jQueryUI as shown in the example above, but it doesn't fix the
problem. The new release of jQuery TableDnD (version 0.7) was not helpful,
too Any idea to fix this problem?
My code:
<script type="text/javascript" src="js/jquery-1.9.1.js"></script>
<script type="text/javascript" src="js/jqueryUI-1.10.3.js"></script>
<script type="text/javascript" src="js/jquery.ui.datepicker-de.js"></script>
<script type="text/javascript"
src="js/jqGrid/i18n/grid.locale-de.js"></script>
<script type="text/javascript" src="js/jqGrid/jqGrid-4.5.2.js"></script>
<script type="text/javascript" src="js/plugins/jqTableDnD-0.5.js"></script>
<link type="text/css" rel="stylesheet"
href="css/cupertino/jquery-ui-1.10.3.css"/>
<link type="text/css" rel="stylesheet" href="css/ui.jqgrid.css" />
<link type="text/css" rel="stylesheet" href="css/ui.multiselect.css" />
<table id="grid"></table>
<div id="navi"></div>
<script type="text/javascript">
$(document).ready(function() {
$("#grid").tableDnD({scrollAmount:0});
$("#grid").jqGrid({
colNames:["Artnr", "Bezeichnung", "Angebot (Position)",
"Enddatum Startseite", "Eigener Bestand", "Versandlager
Bestand"],
colModel:[
{name:"artnr", index:"artnr", align:"center", width:75,
sortable:false, formatter:formatPic},
{name:"benennung", index:"benennung", width:400,
sortable:false, formatter:formatLink }
...
],
datatype: "json",
editurl: "edit.php",
height: "auto",
mtype: "POST",
pager: "#navi",
rowNum: 20,
sortname: "angebot",
sortorder: "asc",
url: "load.php",
viewrecords: true,
gridComplete: function() {
$("#_empty","#grid").addClass("nodrag nodrop");
$("#grid").tableDnDUpdate();
}
}).navGrid ('#navi',
{view:false,edit:false,add:false,del:true,search:false}, {}, {},
{}, {}, {} )
});
function formatPic(cellVal, options, rowObject) {
return "<htmltag title=\""+ cellVal +"\" class=\"tooltip\">"+
cellVal +"</htmltag>";
}
function formatLink(cellVal, options, rowObject) {
return "<a href=\"../details.php?art=" + rowObject[0] + "\"
target=\"_blank\">"+ cellVal +"</a>";
}
</script>
Thanks in advance!

Sunday, 18 August 2013

Adding new element to page with PHP

Adding new element to page with PHP

I'm setting up a registration page, and I'm adding checks right now for
forms that are left empty.
Here's the HTML I have for the username form:
<label>Username</label>
<div class="form-group">
<input name="username" maxlength="25" class="span-default" type="text"
placeholder="Choose a username">
</div>
And the PHP I have:
$username = $_POST['username'];
if(empty($username)) {
// todo
}
What I need for the "todo" portion of the PHP to do is to add a new line
under the input form in the HTML, like this:
<label>Username</label>
<div class="form-group">
<input name="username" maxlength="25" class="span-default" type="text"
placeholder="Choose a username">
<div class="form-warning">This username is already taken!</div>
</div>
How can I do this?

How is kerning encoded on embedded Adobe Type 1 fonts in PDF files?

How is kerning encoded on embedded Adobe Type 1 fonts in PDF files?

Adobe PDF reference talks about /Widths array and /FontFile stream, but
Adobe Type 1 font programs (.pfb or .pfa files) don't include font
metrics; they are included in font metric files (.afm or .pfm files) but
these are not embedded in PDF file.
PDF can just encode char width metrics or it can encode kerning pair too?
How?

SBT Broken Pipe

SBT Broken Pipe

I've been avoiding using SBT since the support in intellij for maven has
always been far superior, plus I don't see much advantage in SBT; but I
figure why fight the masses.
So one of my open source projects I've converted over to SBT. Now when I
run tests (approx 1000 test cases), I get OOMs. Ok so I've tried
fork in Test := true
javaOptions in Test ++= Seq("-Xmx2048m", "-XX:MaxPermSize")
Ok so my OOMs go away but now I get
sbt.ForkMain$Run$RunAborted: java.net.SocketException: Broken pipe
at sbt.ForkMain$Run.write(ForkMain.java:114)
at sbt.ForkMain$Run$1.info(ForkMain.java:132)
Seems to be in different places each time.
These tests all pass if I'm building via maven (scala test maven plugin).
Help me Obi-wan or SBT lovers.

How to use @RequestBody with a JSONP request?

How to use @RequestBody with a JSONP request?

I am trying to perform an ajax request using the jsonp data type due to
cross domain issues in a clustered environment.
I can make jsonp requests to methods mapped with no @RequestBody
parameters, but when I do try to implement a RequestMapping with a
@RequestBody parameter I get a 415 Unsupported Media Type error.
Usually when I get this problem it is due to some property not mapping
correctly between the json object posted and the Java object it is mapped
to in Spring. But the only discrepency I can find is that using jsonp it
adds a parm named callback and one with the name of an underscore "_"
So I added the tag @JsonIgnoreProperties(ignoreUnknown = true) to my Java
object and figured that should solve that, however it is still throwing
this error.
Is there anything else I need to do?
$.ajax({
url : 'http://blah/blah.html',
data : { abc : '123' }, (I also tried to JSON.stringify the object but
no difference)
dataType : 'jsonp',
success : function(response) {
alert('ok '+JSON.stringify(response));
},
fail : function(response) {
alert('error'+JSON.stringify(response));
}
});
The Spring controller is:
@RequestMapping({ "blah/blah" })
@ResponseBody
public ReturnObject getBlahBlah (@RequestBody MyObject obj) throws
Exception {
}
The parameter object is:
@JsonIgnoreProperties(ignoreUnknown = true)
public class MyObject {
private String abc;
// getter and setter for abc auto generated by MyEclipse
}
I have a breakpoint on the Controller method which is never hit.