Thursday, 3 October 2013

string size is equal to number of characters

string size is equal to number of characters

I was making a basic program of strings and did this. there is a string
int this way
#include<stdio.h>
int main()
{
char str[7]="network";
printf("%s",str);
return 0;
}
It prints network.In my view it should not print network or some garbage
value should be printed because '\0' does not end this character array. So
how it got printed?there were no warning or errors too.

Wednesday, 2 October 2013

Setting a knockout observable using sammy for routing

Setting a knockout observable using sammy for routing

I have a SPA using knockout JS for data binding and sammy for routing. I
have a deck of cards that I am trying to have a dynamic routing to. My
problem is that it doesn't work when I try to set a knockout observable
from the routing function in sammy.
My HTML, where I try to bind the name of the deck, looks like this:
<!-- Create Deck -->
<div id="createDeck" class="page" style="display:none;">
<input type="text" class="form-control" placeholder="Untitled
Deck..." data-bind="value: $root.deck.name" />
</div>
<script type="text/javascript" src="lib/jquery-1.9.1.js"></script>
<script type="text/javascript" src="lib/knockout-2.3.0.js"></script>
<script type="text/javascript" src="lib/bootstrap.min.js"></script>
<script type="text/javascript" src="lib/sammy.js"></script>
<script type="text/javascript" src="js/Models/Deck.js"></script>
<script type="text/javascript" src="js/Models/Card.js"></script>
<script type="text/javascript" src="js/ViewModels/DeckViewModel.js"></script>
<script type="text/javascript" src="js/ViewModels/CardViewModel.js"></script>
<script type="text/javascript" src="js/routing.js"></script>
The Deck.js and DeckViewModel.js looks like below
function Deck(deckid, name, cards) {
var self = this;
self.id = deckid;
self.name = name;
self.cards = cards;
}
function DeckViewModel(deck, cards) {
var self = this;
self.deck = ko.observable(deck);
self.cards = ko.observableArray(cards);
self.goToCard = function (card) { location.hash = card.deckid + '/' +
card.id };
}
// Bind
var element = $('#createDeck')[0];
var deckView = new DeckViewModel(null, null);
ko.applyBindings(deckView, element);
Finally, in my routing I try to create a new Deck, like this:
// Client-side routes
(function ($) {
var app = $.sammy('#content', function () {
this.get('#deck/:id', function (context) {
showPage("createDeck", ": Create Deck");
console.log(this.params.id);
deckView.deck = new Deck(1, "test", null);
console.log(deckView.deck);
});
});
$(function () {
app.run('#/');
});
})(jQuery);
function showPage(pageID, subHeader) {
// Hide all pages
$(".page").hide();
// Show the given page
$("#" + pageID).show();
// change the sub header
$("#subHeader").text(subHeader);
}
As you can see, I'm trying to create a test deck with the name 'test', but
the binding <input type="text" class="form-control" placeholder="Untitled
Deck..." data-bind="value: $root.deck.name" /> seems to bind the letter
'c'.
I'm at a loss, please help.
I tried to make a jsfiddle to demonstrate my problem

Maximum volume of parallelepiped

Maximum volume of parallelepiped

Find the dimensions of the parallelepiped of maximum volume circumscribed
by a sphere of radius R.
I would normally be familiar with this using lagrange multipliers, but how
do I do this? It probably helps that I do not know the volume of a
parallelepiped. Thanks!

Automatically resize JInternalFrame according to the screen resolution

Automatically resize JInternalFrame according to the screen resolution

I am developing the MDI application. JFrame as main window and
JInternalFrame as child windows. How can I make sure that my internal
frame has to re-size automatically when I increase/decrease the screen
resolution.
Scenario: Internal frame is in restore mode and occupied the complete
desktop size.
Now when I increase the screen resolution, I am able to see the additional
desktop area that is not occupied by the internal frame.
Is there any way to auto re-size the internal frame according to resolution?

Print a sequence of numbers using recursion - javascript

Print a sequence of numbers using recursion - javascript

I have this function which prints the numbers from 1 to n in a triangle
like way
function printNumbers(n){
var result = "";
var counter = 1;
while (counter <= n) {
result += counter;
console.log(result);
counter = counter + 1;
}
}
console.log(printNumbers(4));
the result looks like this
1
12
123
1234
I need pointer on how to do this using recursion, because I am new to
programing an I don't have a clue on how to do it.

Tuesday, 1 October 2013

CakePHP select field does not populate

CakePHP select field does not populate

I'm Using cakePHP 2.3.8
I have two tables: application, computer_application. The relationship is
one application hasMany computer_application, foreign key is
application_id
in my ComputerApplication model:
class ComputerApplication extends AppModel{
public $name = "ComputerApplication";
public $useTable = "computer_application";
var $belongsTo = array(
'Computer' => array(
'className' => 'Computer',
'foreignKey' => 'computer_id',
'dependent' => true
),
'Application' => array(
'className' => 'Application',
'foreignKey' => 'application_id',
'dependent' => true
)
);
}
In my ComputerApplication controller. HERE I INITIALIZE THE POPULATION OF
DROPDOWN in **add** function
public function add($id=null) {
if (!$id) {
throw new NotFoundException(__('Invalid post'));
}
$this->set('computerApplications',
$this->ComputerApplication->Application->find('list',
array('fields' => array('description') ) ) );
}
Now In my Add View
echo $this->Form->create("computerApplication");
echo $this->Form->input('application_id',array('empty'=>''));
echo $this->Form->end('Save Post');
My problem is that it won't populate the select input. This is the first
time I used 2 words in table [computer_application] using cake since I
don't have problem populating other table with just one word. Just help me
identify which I need to tweak for it to populate.

Angularjs: directive defined controllers communicating with child directives

Angularjs: directive defined controllers communicating with child directives

I think I'm missing something when it comes to directives interacting with
internal controllers. The API documentation is pretty poor on the Angular
site. As far as I can tell, in order to access a controller located within
a parent directive you simply need to set require: '^parentDirective' and
add a fourth argument to the link: attribute on the child directive.
I am unable to access the controller with either $scope or the fourth
argument (I'm using $ctrls).
I wish to be able to push data to an injected service on the parent
directive.
Service:
app.service( 'injectedService', function() {
var service = {
spies: [],
addSpy: function( spy ) {
service.spies.push( spy );
}
};
return service;
});
Parent directive:
app.directive ( 'parentDirective', [ '$window', 'injectedService',
function( $window, injectedService ) {
return {
restrict: 'A',
controller: function( $scope ) {
$scope.test = 'hello';
$scope.addSpy = injectedService.addSpy;
},
link: function( $scope, $element, $attrs ) {
console.log( $scope.test ); //hello
}
};
}]);
Child directive:
app.directive( 'childDirective', [ function() {
return {
restrict: 'A',
require: '^parentDirective',
link: function( $scope, $element, $attrs, $ctrls ){
console.log( $scope.test ); //undefined
console.log( $ctrls.test ); //undefined
console.log( $ctrls.$scope.test ); //undefined
$scope.addSpy({
id: 'test'
}); //error: $ctrls/$scope.addSpy not a function
}
};
}]);

Switching from Windows Server to NAS

Switching from Windows Server to NAS

so I recently started my new job as an IT specialist in a small media
agency (~6-8 people). We currently struggle with the server crashing
occasionally (within 4h - 48h) probably due to a hdd / hardware raid
fault. Since we have a relatively large image database (~6TB), network- as
well as data-reliability has a high priority.
I am currently thinking about switching to two NAS (w/ raid5/6) since I do
not really see the need of an actual server with Windows Server 2008
having ~12TB disk space in RAID 6. We have a Seagate Blackarmor 400 NAS
with 4x2TB in RAID 5. This NAS also has 2x1 Gbit/s network connectivity,
which would perfectly fit the requirements.
With these specs, I do not see the need of a "regular" Windows server but
I am not sure about the NAS performance or the temperature getting too
high in case of high access.
I would be glad to hear any suggestion about this.
Thanks!

Uncertain about Uniformizing Elements of Elliptic Curves.

Uncertain about Uniformizing Elements of Elliptic Curves.

pI am following a subject on Elliptic Curves and have come accross the
notion of a uniformizer. Wikipedia tells me that an element is a
uniformizer of a Discrete Valuation Ring, if it generates the (only)
maximal ideal. This seems sort of clear, but I have no idea how to apply
it to elliptic curves. Consider the following question:/p pLet $k$ a
field, $C: y^2=x$ a smooth curve in $\mathbb{A}^2$ and $P=(\alpha,\beta)$
a point in $C(k)$. Furthermore suppose that the characteristic of $k\neq
2$. Show that $x-\alpha$ is a uniformizing element of $P$ if and only if
$P\neq (0,0)$./p pNow this is not even intuitively clear to me. The ideal
we want to look at is $(y-\beta,x-\alpha)$ I suppose, since this maps
$k[x,y]/(y^2-x)$ to $0\in k$, but how do I show that
$(y-\beta,x-\alpha)=(x-\alpha)$ iff $P\neq (0,0)$?/p pI also cannot find
any information about such problems anywhere (I have the book Rational
points on elliptic curves by Silvermann, but it has nothing about
uniformizers)./p pI would appreciate some explanation (or a solution with
an explanation so I can apply this to other problems) or a reference to a
book which explains this to somebody who has not heard about Discrete
Valuation Rings or Uniformizers before./p pEDIT: This is still not clear
to me, I tried finding info in the recommended book, but it still doesn't
offer enough information. Could anybody be so helpful to explain how to
find uniformizers for such functions?/p