Monday, 30 September 2013

To find out the minimum amount of fuel

To find out the minimum amount of fuel

There is a ship which can carry $K$ creatures at a time. There are two
types of creatures $D$ and $U$. They are to be carried from one side of
the river to the other side, with the constraint being $D$ can never be
greater than $U$ on either side of the river. The amount of fuel needed
for each trip from one side to the other side is $X$. I have to find the
minimum amount of fuel needed to carry all creatures across to the other
side. How to solve this?
example- $3, 3, 2, 10$ Output-$110$

Wifi on Lenovo N581 blocks other wifi clients

Wifi on Lenovo N581 blocks other wifi clients

I have a problem with the wifi on my new Lenovo IdeaPad N581: the wifi
works after installing the additional drivers, but when I switch it on all
other computers connected to our wifi router (the french freebox), I have
no internet access anymore.
If I boot windows it works fine. The card is a broadcom BCM4313 802.11bgn,
the driver shown by lsmod is cfg80211 or wl.

How to know the current Xpath?

How to know the current Xpath?

I am currently using a Xpath Reader to go through my xml file.
What i need is a method for knowing the current Xpath. After some search i
can't find online documentation on the methods of Xpath Reader..
Does anyone know of it?
XmlTextReader xtr = new XmlTextReader(bodyPart.Data);
XPathCollection xc = new XPathCollection();
//the code between theese two lines is not here due to its size,
//but it fills the XpathCollection
XPathReader xpr = new XPathReader(xtr, xc);
while (xpr.ReadUntilMatch())
{
//What i need is a method, to be called in the reading cycle,
//that when called returns the current Xpath.
}
Does anyone knows of it?
Thank you

Filtered arrays and since() functionality in ember-data

Filtered arrays and since() functionality in ember-data

I have a backend resource that contains user activities and in the
application I would like to present activities based on a single day's
worth of activities. I have an ArrayController called ActivitiesController
defined in the router like this:
this.resource('activities', { path: '/activities/:by_date' }, function() {
this.route('new');
});
The REST API provides the following GET method:
GET /activities/[by_date]
So far this looks pretty symmetrical and achievable but I'm running into
two problems:
Parameterized array find. Typically a parameterized route would be
serviced by a ObjectController but in this case the by_date parameter
simply reduces/filters the array of activities but it's still an array
that's returned. I'm not sure how to structure this in the model hook in
the ActivitiesRoute so that its effectively doing a "findAll" rather than
expecting a singular resultset.
Since functionality. As there is a reasonable network cost in bringing
back these arrays of activities I would like to minimize this as much as
possible and the REST API supports this by allowing for a since parameter
to be passed along with the date of the last request. This way the server
simply responds with a 304 code if no records have been updated since the
last call and if there are new records only the new records are returned.
Is there anyway to get this "out of the box" with ember-data? Does this
require building a custom Adaptor? If so, are there any open source
solutions that are available?

Sunday, 29 September 2013

consuming REST API with C#

consuming REST API with C#

I'm very new to C# and want to learn how to make HTTP requests. I want to
start really simple, although that is currently evading me. I want to just
perform a GET on, say, google.com. I created a command line application,
and have this code. Not sure at all which usings are required.
I tested it by writing to the console, and it doesn't get past the
response. Can somebody please clue me in? I'm looking to do some simple
curl type stuff to test an existing API. Thank you for your help.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.IO;
namespace APItest
{
class testClass
{
static void Main(string[] args)
{
string url = "http://www.google.com";
Console.WriteLine(url);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response =
(HttpWebResponse)request.GetResponse();
Console.ReadKey();
}
}
}

How to compare a string with a string in pointer in c++

How to compare a string with a string in pointer in c++

I am implementing linked list in c++. In that am trying to compare a data
stored in the node with a string. Here is my code:
String f;
cin>>f;
if(strcmp(temp->data,f)==0)
{ cout<<"same"; }
else
{ cout<<"not same"; }
Here is my error:
"assignment1.cc", line 160: Error: Cannot cast from std::string to const
char*.
"assignment1.cc", line 160: Error: Cannot cast from std::string to const
char*.
How to compare those two strings?

JOIN 3 tables for search

JOIN 3 tables for search

I have 3 tables: Session, Film and Vendor
Session.FilmID
Film.VendorID
Vendor.VendorName
I want to include the VendarName in the search.
Here's what I have:
sql ="SELECT SessionID, Identifier, SessionType.SessionTypeName, Film.*,
Vendor.*,
CameraID, Date FROM Session "
sql = sql + "JOIN SessionType USING (SessionTypeID) "
sql = sql + "JOIN Film USING(FilmID) "
sql = sql + "JOIN Vendor ON Film.VendorID = Vendor.VendorID "
sql = sql + "WHERE Session.Identifier LIKE ('%" + search + "%') OR "
sql = sql + "Session.Notes LIKE('%" + search + "%') OR "
sql = sql + "SessionType.SessionTypeName LIKE ('%" + search + "%') "
sql = sql + "Film.Vendor.VendorName LIKE ('%" + search + "%') "
sql = sql + "ORDER BY Identifier,SessionType.SessionTypeName"
What am I doing wrong?