Sunday, 1 September 2013

why list slices in right-to-left direction returns empty list?

why list slices in right-to-left direction returns empty list?

I'm new to Python and was trying to understand list slicing.
This question might have been answered somewhere(I tried to look for
existing questions and their answers, but could not find what i was
looking for).
I've a list say, sample_list = [1,2,3,4,5,6,7].
Now , when I try to access:
print sample_list[-2:2]
or,
print sample_list[-3:-7]
In both cases, I get an empty list.
should not it print at-least [6,7] or [5,6,7] respectively, following
left-to-right convention?
I know, I'm doing something wrong semantic-wise.
(trying to print the list in right-to-left direction?)
I would like to understand the logic behind empty list. What is happening
here?
Thanks.

Some assets from SWC are not imported in Flash Builder

Some assets from SWC are not imported in Flash Builder

For almost all of my projects I export visual assets from Flash Pro to SWC
to then import them in Flash Builder. Today I stumbled across a really
bothersome problem.
Some of my assets are not being imported. I've tried clearing my projects
multiple times, restarting my Flash Builder IDE, re-exporting my SWC.
Clearly there's a problem when importing it, because when I decompiled my
SWC/library.swf, I saw that all of my assets are exported just fine. When
I decompile my output SWF I see that instead of some assets there is a red
rectangle, and some of them are just invisible.
I don't know what to think and can't figure it out. The only thing that
might be a case is the file size of the SWC (approximately 2.5 MB), and
there are almost 160 linkages in there.
I wasn't able to find anything on the internet regarding the file size
limit or anything like that.
I'm using Flash Pro CC and Flash Builder 4.7 Standard on a Mac OS X 10.8.4
These are the red boxes I'm talking about:

Margins become smaller

Margins become smaller

I want to make left and right margins on my webpage. I make a main div
element and set margins <div id = "wrap" style="display: block;
margin-left:200px;margin-right:200px;"> ... </div> . But when I resize the
page in a browser, margins become smaller. However, I need them to be
fixed,so if the content size+left margin+ right margin becomes larger than
the screen,the scroll bar must appear.

Saturday, 31 August 2013

Javascript registry for calling methods and objects

Javascript registry for calling methods and objects

I want to have an object which can act as a registry for calling functions
on it.
So far, I have been thinking of something along these lines:
var registry = new Object();
registry.doStuff = function(){ /* */ };
Is there a better way ? What about adding objects ? Ideally, I'd like to
be able to add these at run time.

AutoCad: Getting 'Invalid object array exception' in Late Binding while copying Objects

AutoCad: Getting 'Invalid object array exception' in Late Binding while
copying Objects

I have two drawings, dg1 and dg2. I have defined a block 'b1' in dg1 which
I want to copy in dg2. It works well in Early Binding but giving error
when I try code in late binding. The code in question is:
myfile.CopyObjects(objCollection, m_oActiveDoc.Blocks)
And I get exception: Invalid object array exception while I try to copy a
block in other drawing.
How do I do it in late Binding?
I am using Autocad 2009
Thanks

Undefined Variable error

Undefined Variable error

I am trying to create a simple program that calculates the amount of
calories and pounds burned for 3 activities, biking, jogging, and
swimming. I keep getting the an error Undefined variable: calcPounds.
I have the variable inside the function, but it's still telling me it's
undefined. I just started PHP this week so I'm a bit confused still.
Thank you!
PHP
function pounds_burned($calc){
$biking = 200;
$jogging = 475;
$swimming = 275;
$calories;
$pounds = 3500;
$calcPounds; // **** ASSIGNMENT MISSING HERE ****
$hoursBiking = floatval($_GET["bike"]);
$hoursJogging = floatval($_GET["jog"]);
$hoursSwimming = floatval($_GET["swim"]);
if (!is_numeric($hoursBiking) or !is_numeric($hoursJogging) or
!is_numeric($hoursSwimming)) {
echo 'Enter numeric values only' . "<br />";
}
if (empty($hoursBiking) or empty($hoursJogging) or
empty($hoursSwimming)) {
echo "All fields are required to be valid numbers!!";
echo "<p><a href=\"calories.html\">Try again?</a></p>\n";
}
else {
$calcPounds = round(($biking * $hoursBiking) +
($jogging * $hoursJogging) + ($swimming * $hourssSwimming));
}
}
echo "Number of pounds worked off is " . round($calcPounds);
$calories = $calcPounds / $pounds;
echo "Number of calories burned is " .round($calories);
?>
HTML
<form action="calorie_calc.php" method="GET" onsubmit="return
validateForm()">
<table border="0">
<tr>
<td>Enter number of hours bicycling</td>
<td><input type="text" name="bike" id="bike" size = "10" /></td>
</tr>
<tr>
<td>Enter number of hours jogging</td>
<td><input type="text" name="jog" id="jog" size = "10" /></td>
</tr>
<tr>
<tr>
<td>Enter number of hours swimming</td>
<td><input type="text" name="swim" id="swim" size = "10" /></td>
</tr>
<td><input type="submit" name="calc" id="calc" value="Compute Pounds"
/></td>
<td><input type="reset" name="resetButton" id="resetButton"
value="Reset" /></td>
</tr>
</table>
</form>

How can I show only one taxonomy from a post?

How can I show only one taxonomy from a post?

I have a custom post type and inside the custom post I have a taxonomy
named "instruments". Each post can have more than one "instrument".
But I just want to display one (or the first one) at the homepage. Like:
"Instrument A, Instrument B, Instrument C. But only show Instrument A".
Right now I'm using this code.
<?php
$terms = get_the_terms( $post->ID , 'instruments' );
foreach ( $terms as $term ) {
echo $term->name;
}
?>