Tuesday, May 22, 2012

Asking git to look for different key other than id_rsa

I not sure why but even though I mention properly in ssh config to look for identity file with name viren.pub for github



git still considering id_rsa as default and it does not seem to work unless an until i rename viren.pub and viren to id_rsa.pub and id_rsa



Here my ssh config look like



Host [Amazon server]
Hostname github.com
User git
IdentityFile /root/.ssh/viren


Can anyone help





Grab euro dollar conversion rate in Java

I have an application that has to convert dollar to euro and vice versa. Is there an interface or API I can use to grab the current conversion rate?





Issue on a do-while form in Strings

Ok, i'm a student in his first experiences with programmaing so be kind ;) this is the correct code to print "n" times a string on screen...



#include <stdio.h>
#include <string.h>

#define MAX 80+1+1 /* 80+\n+ */

int main(void)
{
char message[MAX];
int i, n;

/* input phase */
printf("Input message: ");
i = 0;
do {
scanf("%c", &message[i]);
} while (message[i++] != '\n');
message[i] = '';

printf("Number of repetitions: ");
scanf("%d", &n);

/* output phase */
for (i=0; i<n; i++) {
printf("%s", message);
}

return 0;
}


why in the do-while form he needs to check if message[i++] != '\n' and not just message[i] != '\n'??





Making multiple query to mysql in one java event

I'm having and error when trying to make multiple queries in one event. I have a table where I have a list of all the films with the main actor, producer, genre etc.



The actor, producers and genres are stocked as an int which in another table refers to a String. I'm therefore making multiple queries to print out all the data in a textarea.
However i keep getting the error



Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at tp2.MainPage.jList1ValueChanged(MainPage.java:231)
at tp2.MainPage.access$300(MainPage.java:24)
at tp2.MainPage$4.valueChanged(MainPage.java:106)


I refered to all the lines mentioned, line 24 and 106 are generated by netbeans so i doubt the error comes from there. Line 231 is mentioned in the code below.



    private void jList1ValueChanged(javax.swing.event.ListSelectionEvent evt) {
String npays = "null",titre= "null",nacteurPrincipal= "null",oscar= "null",realisateur= "null";
try {
String url = "jdbc:mysql://localhost/mycinema";
Class.forName("com.mysql.jdbc.Driver");
Connection connexion = DriverManager.getConnection(url, "root", "");
Statement inst = connexion.createStatement();
titre = jList1.getSelectedValue().toString(); //LINE 231
ResultSet resultat = inst.executeQuery("SELECT * FROM film WHERE titre = '" + titre + "'");
while (resultat.next()) {
npays = resultat.getString("npays");
realisateur = resultat.getString("realisateur");
nacteurPrincipal = resultat.getString("nacteurPrincipal");
oscar = resultat.getString("oscar");
}
resultat = inst.executeQuery("SELECT * FROM pays WHERE npays =" + npays);
while (resultat.next()) {
npays = resultat.getString("nom");
}

resultat = inst.executeQuery("SELECT * FROM acteur WHERE nacteur =" + nacteurPrincipal);
while (resultat.next()) {
nacteurPrincipal = resultat.getString("prenom") + resultat.getString("nom");
}

jTextArea3.setText(titre + " : un film par " + realisateur + "\n" + npays);
} catch (ClassNotFoundException ex) {
Logger.getLogger(MainPage.class.getName()).log(Level.SEVERE, null, ex);
} catch (SQLException ex) {
Logger.getLogger(MainPage.class.getName()).log(Level.SEVERE, null, ex);
}
}


If somebody can spot my error pleas point in out thankyou :)



P.S the variables are in french. srry for that :/





Issue on a do-while form in Strings

Ok, i'm a student in his first experiences with programmaing so be kind ;) this is the correct code to print "n" times a string on screen...



#include <stdio.h>
#include <string.h>

#define MAX 80+1+1 /* 80+\n+ */

int main(void)
{
char message[MAX];
int i, n;

/* input phase */
printf("Input message: ");
i = 0;
do {
scanf("%c", &message[i]);
} while (message[i++] != '\n');
message[i] = '';

printf("Number of repetitions: ");
scanf("%d", &n);

/* output phase */
for (i=0; i<n; i++) {
printf("%s", message);
}

return 0;
}


why in the do-while form he needs to check if message[i++] != '\n' and not just message[i] != '\n'??





.htaccess mod_rewrite pretty URLs with subdomain

I'm trying to get my URLs from this:



hxxp://m.newsite.com/index.php?id=12345



To this:



hxxp://m.newsite.com/12345



The trouble I have is I have a shared hosting account and I'm hosting a new domain, so the above URL w/subdomain is technically accessible from:



hxxp://www.originalsite.com/newsite.com/mobile



I've tried a variety of different combinations for mod_rewrite, but I'm afraid I'm just not there! Help!





Wednesday, May 16, 2012

Specified cast is not valid when getting Datatable Column Value

The above error message appears when I am trying to get Column Value from Datatable.



This is what I find in the stacktrace:




System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext()

at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable
1
source)




 and this in the TargetSite when debugging:



{ Boolean b__0(System.Data.DataRow)}




Here is my code:
DataTable hr = new DataTable();



            hr.Columns.Add("BookingDate");
hr.Columns.Add("BookingId");
hr.Columns.Add("BookingSource");
hr.Columns.Add("CheckInDate");
hr.Columns.Add("CheckOutDate");


for (int i = 0; i < gmisc.GetModifiedBookings(gmoreq).Bookings.Length; i++)
{
hr.Rows.Add();
hr.Rows[i]["BookingDate"] = Convert.ToDateTime(gmisc.GetModifiedBookings(gmoreq).Bookings[i].BookingDate.ToString());
hr.Rows[i]["BookingId"] = Convert.ToInt64(gmisc.GetModifiedBookings(gmoreq).Bookings[i].BookingId.ToString());
hr.Rows[i]["BookingSource"] = gmisc.GetModifiedBookings(gmoreq).Bookings[i].BookingSource.ToString();
hr.Rows[i]["CheckInDate"] = Convert.ToDateTime(gmisc.GetModifiedBookings(gmoreq).Bookings[i].CheckInDate.ToString());
hr.Rows[i]["CheckOutDate"] = Convert.ToDateTime(gmisc.GetModifiedBookings(gmoreq).Bookings[i].CheckOutDate.ToString());



}
Int64 BookingId = (from DataRow dr in hr.Rows
where (Int64)dr["BookingId"] == BookId
select (Int64)dr["BookingId"]).FirstOrDefault();
TextBox1.Text = Convert.ToString(BookingId);


Where did I go wrong, if somebody can please tell me.