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

Monday, 30 September 2013

Stuck in grub rescue limbo- Please help

Stuck in grub rescue limbo- Please help

I installed ubuntu about a year ago and yesterday I deleted the partition
because my parents were annoyed with the startup menu. I didn't know I had
to fix the mbr.
Now every time I try to boot the computer the grub menu pops up and says
that the partition cannot be found. I made an ubuntu dvd but it doesn't
turn on automatically and I have no clue how to do it manually.
Please help me, I have no clue what to do.
Could someone atleast tell me how to retrieve data or documents.

How iPhone 5S can have such a big aperture=?iso-8859-1?Q?=3F_f/2.2=3F_=96_photo.stackexchange.com?=

How iPhone 5S can have such a big aperture? f/2.2? – photo.stackexchange.com

I thought that in order to have a big aperture such as f/2.2 a big amount
of light should be able to enter to the sensor and in order to do it, a
big lens was needed. How is it possible that in the …

Is there an awk one-liner or two-liner for doing this? [merge lines and add column values]

Is there an awk one-liner or two-liner for doing this? [merge lines and
add column values]

So I have a laaaaaaaarge file like this:
Item|Cost1|Cost2
Pizza|50|25
Sugar|100|100
Spices|100|200
Pizza|100|25
Sugar|200|100
Pizza|50|100
I want to add all Cost1s and Cost2s for a particular item and produce a
merged output.
I've written a python code to do this,
item_dict = {}
for line in file:
fields = line.split('|')
item = fields[0]
cost1 = fields[1]
cost2 = fields[2]
if item_dict.has_key(item):
item_dict[item][0] += int(cost1)
item_dict[item][1] += int(cost2)
else:
item_dict[item] = [int(cost1),int(cost2)]
for key, val in item_dict.items():
print key,"|".join(val)
Is there anyway to do this very efficiently and quickly in awk or using
any other wizardry?
Or can I make my python more elegant and faster?
Expected Output
Pizza|200|150
Sugar|300|200
Spices|100|200

mySql: getting latest transaction made for a row from another table

mySql: getting latest transaction made for a row from another table

I'm trying to query for the last transaction made for each item on
tbl_invty that doesn't have the transaction type "Idle" from table
tbl_trans. The multiplicity of transactions is confusing me on getting my
query right and all I was able to do so far was joining the two tables
below on tbl_invty.code=tbl_trans.code. How do I go about this so I could
output only rows 2 and 3 from tbl_invty joined with rows 5 and 8 from
tbl_trans based on the column code?
tbl_invty
+------+-------------+
| CODE | DESCRIPTION |
+------+-------------+
| 1 | abc |
| 2 | bbb |
| 3 | cdf |
+------+-------------+
tbl_trans
+----------+------+--------+------------+
| TRANS_ID | CODE | TYPE | TRANS_DATE |
+----------+------+--------+------------+
| 1 | 1 | NEW | 2012-09-29 |
| 2 | 1 | UPDATE | 2012-09-30 |
| 3 | 1 | IDLE | 2012-09-30 |
| 4 | 2 | NEW | 2012-09-29 |
| 5 | 2 | UPDATE | 2012-09-30 |
| 6 | 3 | NEW | 2012-09-29 |
| 7 | 3 | UPDATE | 2012-09-30 |
| 8 | 3 | UPDATE | 2012-09-30 |
+----------+------+--------+------------+

Sunday, 29 September 2013

Whats the right way to publish an Alpha / Beta Android App?

Whats the right way to publish an Alpha / Beta Android App?

I'm just getting started with writing Android apps.
I have something I want to make available to a few interested testers, but
I'm a long way from having an app. ready for the general public.
How do I make it available for testers without putting it on Play?

To null check or not to do a null check?

To null check or not to do a null check?

Here is a code authored by Josh bloch, ( Linkedlist.java)
* @throws NullPointerException if the specified collection is null
*/
public boolean addAll(int index, Collection<? extends E> c) {
checkPositionIndex(index);
Object[] a = c.toArray();
int numNew = a.length;
if (numNew == 0)
return false;
Node<E> pred, succ;
if (index == size) {
succ = null;
pred = last;
} else {
succ = node(index);
pred = succ.prev;
}
Here I dont see any null ptr check for Collection c. On contrary effective
java very much stresses on parameter validation, emphasizing null pointer
check. If an invalid parameter value is passed to a method and the method
checks its parameters before execution, it will fail quickly and cleanly
with an appropriate exception.
I need to know what I am missing ? In other words why did he not do a null
check for addAll function ?

gcc make install error

gcc make install error

I try to compile gcc with make install and it gives me this:
make[1]: Entering directory `/media/BOSS/sources/gcc-build'
/bin/bash ../gcc-4.8.1/mkinstalldirs /tools /tools
/bin/bash: line 3: cd: ./fixincludes: No such file or directory
make[1]: *** [install-fixincludes] Error 1
make[1]: Leaving directory `/media/BOSS/sources/gcc-build'
make: *** [install] Error 2
I am currently compiling it for lfs also I am in a seprate directory on a
32 bit computer

Splicing together symbols with Scala macros

Splicing together symbols with Scala macros

I am trying to call a specialized collections library like FastUtil or
Trove from generic Scala code. I would like to implement something like
def openHashMap[@specialized K, @specialized V]: ${K}2${V}OpenHashMap =
new ${K}2${V}OpenHashMap()
Where the $(X} is just my notation for text substitution like shells, so
that openHashMap[Long, Double] would return a Long2DoubleOpenHashMap the
type would be known at compile time. Is this possible with Scala macros.
If so, which flavour? I know there are def macros, implicit macros, fundep
materialization, macro annotations, type macros (now discontinued) ... and
I think these are different in plain Scala-2.10, 2.10 macro paradise and
Scala-2.11. Which, if any, of these are appropriate for this?

Saturday, 28 September 2013

CodeAcademy: Just Averages

CodeAcademy: Just Averages

Thanks for your help in advance. I'm trying to get a weighted average of
these students test scores but I get the following error message from
CodeAcademy "Oops, try again! Does your get_average function take exactly
one parameter (a student)? Your code threw a "string indices must be
integers, not str" error." What are they talking about?
Specifically, I'm trying to get the average function to work.
lloyd = {
"name": "Lloyd",
"homework": [90.0, 97.0, 75.0, 92.0],
"quizzes": [88.0, 40.0, 94.0],
"tests": [75.0, 90.0]
}
alice = {
"name": "Alice",
"homework": [100.0, 92.0, 98.0, 100.0],
"quizzes": [82.0, 83.0, 91.0],
"tests": [89.0, 97.0]
}
tyler = {
"name": "Tyler",
"homework": [0.0, 87.0, 75.0, 22.0],
"quizzes": [0.0, 75.0, 78.0],
"tests": [100.0, 100.0]
}
def average(some):
return sum(some)/len(some)
students = [lloyd, alice, tyler]
def get_class_average(students):
total = 0
for student in students:
total += average(student['homework'])
return float(total) / len(students)
homework_average = get_class_average(students)
def get_average(students):
total = 0
for student in students:
total += average(student['homework'])*.1 + .6*
average(student['tests']) + .3 * average(student['quizzes'])
return (total) /len(students)
print get_average(students)
print homework_average

Overwrite all prints at the same place in perl

Overwrite all prints at the same place in perl

I want overwrite my all print result at the same place . It should not
scroll. and I want it infinite time. For that I have used while(1) and it
is working properly. But the problem is every time I print the statement ,
it scrolls down and that I want to change. I want it to print it or you
could say overwrite it at the same place.
Could some please help me with this??
I also tried to use \r in both print statements but it only updates the
last print statement at the same place.
while(1)
{
.... // some lines of code //
print("\n******** Interrupts *********\n");
for($k=0; $k<$t_intr; $k++)
{
$intr_diff = $total_intr_curr[$k] - $total_intr_prev[$k];
#push(@intr_diff_arr,$intr_diff);
print("Intr : $intr_diff\n"); // want to update this print at same
place //
}
print("\n******** Context switches *********\n");
for($l=0; $l<$t_ctxt; $l++)
{
$cntx_min = 0;
$ctxt_diff = $total_ctxt_curr - $total_ctxt_prev;
push(@ctxt_diff_arr,$ctxt_diff);
$min = min @ctxt_diff_arr;
$max = max @ctxt_diff_arr;
print("Ctxt : $ctxt_diff Minimum : $min Maximum : $max\n"); // want to
update this print also at same place //
}
}// infinite while loop end //
Thank you.

Convert ascii characters to normal text

Convert ascii characters to normal text

I have text like this:
&#8216;The zoom animations everywhere on the new iOS 7 are literally
making me nauseous and giving me a headache,&#8217;wroteforumuser
Ensorceled.
I understand that #8216 is an ASCII character.How can i convert it to
normal characters without using .replace which is cumbersome.