Sunday, 1 September 2013

Using HTML5 and CSS display 2 images level with each other, and each with a list below

Using HTML5 and CSS display 2 images level with each other, and each with
a list below

I'm new to CSS. I want to code a page in HTML5 that has 2 rather large
images of equal size and level with each other and with space between
them. I also want a left-margin between the left image and the left edge
of the page.
Directly below each image there will be an unnumbered list of 6 or so
items. Would someone be so kind as to draft the code for this? I know one
way to use CSS for spacing the images:
img { margin-right: 38px; margin-left: 50px; }
But what to do about the lists?
Thanks

Saturday, 31 August 2013

Backbone JS: My view is not being considered a constructor. Why?

Backbone JS: My view is not being considered a constructor. Why?

The error in my console says that app.ItemView is not a constructor.
Another post said that the type of the view should be a function. When I
check the type it is undefined, but I have no idea why.
Any insight would be greatly appreciated.
Here is the code:
var app = app || {};
$(function(){
app.items = [
new app.Item({ name: 'Abe Lincoln', details: 'Is he that guy from
that new reality show?'}),
new app.Item({ name: 'Captain Planet', details: 'He is our hero'}),
new app.Item({ name: 'Karthus', details: 'Press R'}),
new app.Item({ name: 'Your Mom', details: 'She misses me'}),
new app.Item({ name: 'Teddy Roosevelt', details: 'Makes the most
interesting man in the world look boring'})
];
app.itemsCollection = new app.ItemCollection(app.items),
app.itemsCollectionView = new app.ListView({collection:
app.itemsCollection});
Backbone.history.start();
});
app.Item = Backbone.Model.extend({
defaults: {
name: 'name not given',
details: 'no details available'
}
});
app.ListView = Backbone.View.extend({
el: '#the-list',
initialize: function(){
this.render();
},
render: function(){
//alert("the size of collection is: "+this.collection.size());
this.collection.forEach(function(item){
this.addOne(item);
}, this);
},
//create an itemview for a model, and add it to the list view
addOne:function(item){
alert(typeof(app.ItemView));
var itemViewInst = new app.ItemView({model: item});
this.$el.append(itemViewInst.render().el);
}
});
app.ItemView = Backbone.View.extend({
tagName: 'li',
template: _.template($('#list-item-template').html()),
render: function(){
this.$el.html(this.template(this.model.toJSON()));
return this;
}
});
app.ItemCollection = Backbone.Collection.extend({
model: app.Item,
//url: '/something'
});
app.AppRouter = (Backbone.Router.extend({
routes: {
"" : "defaultView",
"details/:id" : "details"
},
defaultView: function(){
//render the collection to the page
},
details: function(id){
}
}));

Inserting Data into MySql from php

Inserting Data into MySql from php

I'm new to php and have been going through tutorials, and have hit a
stump, where I can't seem to find what I'm doing wrong in my code, I
welcome any and all assist, the code below is meant to insert data
previously collected into a table that has those fields outline, in
phpmyadmin:
$SQL = "INSERT INTO users ( 'username', 'password', 'email_address',
'date_of_birth', 'first_name', 'last_name', 'phone', 'address', 'city',
'userlevel') values ('" + $username + "', '" + $password + "', '" +
$email_address + "', '" + $date_of_birth + "', '" + $first_name + "', '"
+ $last_name + "', '" + $phone + "', '" + $address + "', '" + $city + "',
'" + $userlevel + "')";
And then to run that code:
mysql_query($SQL); mysql_close($db_handle); print "Records added to the
database";
I'm not 100% sure whether its the layout or not, for inserting variable
data into MySql, also their is no errors about connecting to the database,
furthermore the print at the end of the function runs, therefore it is not
getting an error and stopping before running the code above.
Once again thank you and all assistance is welcome.

Select2 - different color of selected tags

Select2 - different color of selected tags

I have a script analysing the tags IDs selected in Bootstrap Select2 and
I'm trying to change a color of a tag in case of a condtion. Here is what
I have:
$('#email_from).on('change', function(e) {
if (e.added) {
last = e.val.length-1;
$.ajax( {
type: 'POST',
url: 'email.informer.php',
data: 'email_id=' + e.val[last],
success: function(data) {
if (data == 0) {
$('.select2-search-choice:not(.selected_clr)',
this).addClass('selected_clr');
}
},
dataType: 'html'
});
}
});
And I have css file with:
li.selected_clr {
background-color: #633421 !important;
}
I read a hint here but it doesn't work. No class gets added. If I replace
it with:
$('.select2-search-choice).addClass('selected_clr');
then it works, but it changes color of all the tags while I need to do it
only with the last one entered.

Reading comma separated tuples from a file in python

Reading comma separated tuples from a file in python

I am trying to read from a file with several tuples separated by commas. A
sample input file looks like:
(0, 0), (0, 2), (0, 4), (-1, -1), (0, -2), (1, -1), (-1, -3),
(-1, 1), (-1, 3), (1, 1), (1, 3), (1, 5), (2, 0), (2, 2), (3, 3),
(2, 4), (3, 5), (4, 4), (5, 3), (6, 4), (5, 5), (7, 5)
After reading from this file, I need a tuple like this:
G = ((0, 0), (0, 2), (0, 4), (-1, -1), (0, -2), (1, -1), (-1, -3), \
(-1, 1), (-1, 3), (1, 1), (1, 3), (1, 5), (2, 0), (2, 2), (3, 3), \
(2, 4), (3, 5), (4, 4), (5, 3), (6, 4), (5, 5), (7, 5))
How this can be done efficiently? Regards.

Adding up numbers in custom fields on a monthly basis

Adding up numbers in custom fields on a monthly basis

Every time i help out a client with a request i make a new post on my
wordpress-site. I write a little text about what the problem was, assign
the post to the clients own specific category and i fill inn the number of
minutes it took me to accomplish the request. The number of minutes i
insert in a custom field (using the advanced custom field plugin).
Then, i bill my client on a monthly basis according to how long time i
have spent solving request.
I have accomplished to query out the number of minutes for each
request/post and add up the total number of minutes. But here comes my
problem:
I would like the query to check out which month the post was published in,
and add up totals on a monthly basis. So lets say i helped a client like
this:
JANUARY
request took me 60 minutes
request took me 30 minutes
FEBRUARY
request took me 45 minutes
request took me 15 minutes
Then i would like to query out two seperate boxes saying You spent 90
minutes on requests in january You spent 60 minutes on requests in
february
Anyone able to solve this problem for me?
Anders

JSF and applicationscoped bean connection(Publish/Subscribe)

JSF and applicationscoped bean connection(Publish/Subscribe)

I want to create simple web application which will be work similarly to
publish/subscribe mechanism. I have applicationScoped bean that contains
list of strings and xhtml where i display this strings as a table. Now i
want to add something like listener and when list of string in
applicationScoped bean will change my table also should change. How can i
achieve this ?