Friday, May 27, 2016

An example of Zenity and the MySql query in C++

/*
 * ALfred Haines Copyright 2013
 *
 * This example of Zenity and the MySql query
 * Both must be installed
 *
 *
 * g++  cpp/main.cpp -Wno-deprecated -Wno-write-strings  -DQT_SQL_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/include/mysql -I/usr/include/mysql++ -L/usr/lib  -L/usr/lib -lpthread  -I../ cpp/dr01.cpp -lmysqlpp -lmysqlclient -lnsl -lz -lm -o dr01
 *
 * you must setup a connection file for this to access MySql
 * I call mine con.cpp and it is in my cpp folder
 * it will define
 * SERVER="localhost",USER="root",PASSWORD="",DATABASE="DBase"
 *
 *
 *
*
#include "sstream>"
#include "boost/tokenizer.hpp>"
#include "boost/iostreams/device/file.hpp>"
#include "boost/iostreams/stream.hpp>"
#include "boost/algorithm/string/replace.hpp>"
#include "vector>"
#include "mysql.h>"
#include "con.cpp" // MySQL password File
#include "stdio.h>"
#include "iostream>"
#include "cstdlib>"
#include "string>"

using namespace std;
MYSQL *connection, mysql;
MYSQL_RES *result;
MYSQL_ROW row;
int query_state;

#define N_MOVIES 300
#define N_ReGen 12

struct drs_t {
  string name ;
  int id ;
} actor [N_ReGen];

struct movies_t {
  string title;
  int year;
} films [N_MOVIES];

void printmovie (movies_t movie);
std::string exec(char* cmd);

int main() {
    string rs ; string re ;
    mysql_init(&mysql);
//connection = mysql_real_connect(&mysql,"host","user","password","database",0,0,0);
connection = mysql_real_connect(&mysql,SERVER ,USER ,PASSWORD ,DATABASE ,0,0,0);
if (connection == NULL) {
cout << mysql_error(&mysql) << endl;
return 1;
}
string tm ; int c = 0 ;
query_state = mysql_query(connection, "select * FROM drs ");
if (query_state !=0) {
cout << mysql_error(connection) << endl;
return 1;
}
string cm = "ans=$(zenity  --list  --height 400 --width 350  --text \"Choose a Doctor\" --radiolist --column \"Pick\" --column \"Num\" --column \"Name\"";
result = mysql_store_result(connection);
while ( ( row = mysql_fetch_row(result)) != NULL ) {

tm = " ";
tm.append( "FALSE \"" );
tm.append( row[0] );
tm.append( "\" \"");
tm.append( row[1] );
tm.append( "\" ");
cm.append( tm );
}

cm.append( " ); echo $ans" );
cm.erase(remove( cm.begin(), cm.end(), '`' ),cm.end());
char* cmd = strdup(cm.c_str());
re = exec( cmd);

// string j = "select * FROM drwho WHERE intid = 1";
// string j = "select  drs.name, drwho.*  FROM drwho, drs   WHERE drwho.intid = 1";
//sprintf(qu,"%s" , "select  drs.name, drwho.*  FROM drwho, drs   WHERE drs.id = " );

string j = "select * FROM drwho WHERE dr = ";
j.append(re);

query_state = mysql_query(connection, j.c_str());
if (query_state !=0) {
cout << mysql_error(connection) << endl;
return 1;
}
cm = "ans=$(zenity  --list  --height 400 --width 350  --text \"Choose an Episode \" --radiolist --column \"Pick\" --column \"Num\" --column \"Name\"";
result = mysql_store_result(connection);
while ( ( row = mysql_fetch_row(result)) != NULL ) {
// cout << row[6] << endl;
tm = " ";
tm.append( "FALSE \"" );
tm.append( row[0] );
tm.append( "\" \"");
tm.append( row[4] );
tm.append( "\" ");
cm.append( tm );
}
cm.append( " ); echo $ans" );
cm.erase(remove( cm.begin(), cm.end(), '`' ),cm.end());
cmd = strdup(cm.c_str());
re = exec( cmd);
j = "select * FROM drwho WHERE intid = ";
j.append(re);
query_state = mysql_query(connection, j.c_str() );
if (query_state !=0) {
cout << mysql_error(connection) << endl;
return 1;
}
cm = "echo ";
result = mysql_store_result(connection);
while ( ( row = mysql_fetch_row(result)) != NULL ) {
// cout << row[6] << endl;
tm = " ";
tm.append( "\"");
tm.append( row[5] );
tm.append( "\" ");
cm.append( tm );
}
cm.append( "  | zenity --text-info --height 300 --width 650 " );
cm.erase(remove( cm.begin(), cm.end(), '`' ),cm.end());
cmd = strdup(cm.c_str());
re = exec( cmd);
mysql_free_result(result);
mysql_close(connection);
return 0;
}

std::string exec(char* cmd)
  {
    FILE* pipe = popen(cmd, "r");
    if (!pipe) return "ERROR";
    char buffer[128];
    std::string result = "";
    while(!feof(pipe)) {
    if(fgets(buffer, 128, pipe) != NULL)
    result += buffer;
    }
    pclose(pipe);
    return result;
}
void printmovie (movies_t movie)
{
  cout << movie.title;
  cout << " (" << movie.year << ")\n";
}

Tuesday, March 29, 2016

Trump's road to greatness!

What is it with Americans for Trump?  I sort of see the appeal for a person that says what he thinks but does he really have to say everything that comes to his mind?  I remember growing up with people like this.  I have even, at times, been guilty of saying hurtful things without thinking but I grew-up.  There is this thing we do where we catch ourselves before we say something we may regret later.  This thing is missing in Trump, so he just spouts out whatever pops into his head. Some of what comes out sounds reasonable until you put it through the reality checker to see if it is possible.  Some of it sounds dumb even to low IQ voters...
The dumbest is the wall, one foot higher then the great wall of China, the billions of dollars that this would cost could fix or replace every broken bridge in the US.  He says he will make Mexico pay for it but that just isn't going to happen. If you believe that they will pay for it then your more delusional then Trump.  No either we will have to pay for it or it wont be built, end of story!
How about, "If I become president, we're all going to be saying 'Merry Christmas' again."?  Well not everybody is Christian and some people might resist this small piece of bullcrap.  What is he going to do, throw all non-Christian in jail?  Our prison system is already over-burdened from the failed drug war.  Any law forcing people to say 'Merry Christmas' would be unconstitutional.  So this is just not happening!
He said he would "Get rid of Common Core" and the Federal Dept of Education.  This sounds confusing because if he wants to make the US great again we need better education.  If we go back to a system where every school sets their own standards then fake religious charter schools can teach any nonsense they want.  While their students suffer because they wont be prepared for college. I feel that the Common Core should be harder and include Art &; Music. How can we be great if our students fall behind in the global arena.   This is not the right direction toward greatest!
How about doing away with the Environmental Protection Agency?  Towns across America like Flint Mi. are unable to drink their water due to population, even with regulation.  Many of Trump supporters aren't old enough to remember the dark clouds of smoke over most major cities.  The untreated water and the harmful chemicals like DDT and asbestos or lead in the paint. The air is cleaner and most of the water is drinkable! So maybe the EPA has done more good then harm, so far.  Look at countries without such regulation, China; India; Africa, all finding it hard to breath on most days.  That's his idea of the road to greatest?
What about, "Defund Planned Parenthood"?  This is just stupid and will result in the worst health crisis America has ever seen.  PP clinics aren't abortion clinics, in some cases they have been the only health care that poor women have available.  In many states that allow doctors to refuse Medi-Aid participating doctors are few and far apart.  In Pa. I had to travel 16 miles to see a doctor because local doctors did not accept state insurance.  This is just an attack by the religious haters that feel they must control the lives of non-believers.  Trump must accept this for what it is, A HATE CRIME against people who believe differently from him!
What about the countless number of ways he says he will violate the constitution by denying rights to Muslim Americans and "Target and kill the relatives of terrorists"?  Should you be killed if a family member commits a crime that had nothing to do with you?  On and on the madness just pours out of this man.  The things he says about other nations are insane not presidential.
He has strange ideas of foreign policy like, putting the "hedge fund manager Carl Icahn in charge of trade negotiations with China and Japan" instead of in jail where he belongs. On and on the madness continues. If this man weren't wealthy he would be in a mental hospital where he couldn't hurt himself or others.  Trump is not right for America and can never make the US great again.
There is one good idea among the madness, End birthright citizenship, yes a citizen test should be required at birth so that wackos like Trump can be denied citizenship before they can screw up our country!  Why should losers become citizens just because they were born here! Under the strict immigration laws that Trump favors the Drumpf family never would have been allowed into the country in the first place!

Tuesday, January 19, 2016

I guess I have to stop watching documentaries

I think I have to stop watching documentaries.  The ones I have watched lately just make me sad.  "terms and conditions may apply" and "the propaganda game", both on Netflix, show disturbing views of our lives and the lives of people in N.Korea respectively.  "Terms" asks the question ' if you knew that your personal data was being given to the government would you say so much?'  Facebook; Twitter; and other social media sites are the NSA's best source of info on your life.  People don't just give social media their info they brag about what they do!  The NSA loves social media and the fools that tell all. On the other side of the privacy game is "the propaganda game" which tells how misinformation is the only information we get about N. Korea.  Both were frightening views of what a government does to its people.
I for one am afraid of both views but being brain washed to think our system is the best is the most disturbing.  The best system should be one that allows their people to think what they want and have the freedom to say it.  Without fear of incarceration or financial reprisals.  "Terms" tells how a seventh grader was detained by the Secret Service for comments on social media about how the President "had better be careful" because of the "suicide bombers".  Not that he was making a threat, only small talk about the dangers and he was detained!  Watch the show.  It will scare most people out of using social media.
What would it take to get people to share just a little bit less about their every move?  Do you need a shock like having your child detained by the Secret Service or having your credit reduced because you shopped at Wal-Mart?  Yes, having your credit reduced because of where you shopped!  What about being put on a no-fly list because of statements you made to a friend on Facebook?  Could you be a victim of a government pre-crime unit that has predicted that you are likely to commit a crime?  not that you have but that you might, based on something you said in jest.  Would you want to live in a country where jokes are illegal?
I want to see a watchdog program that watches the government and posts their abuses on a website, exposing them in the light.  BUT how can we trust that government moles wont control that program?  Using it to further spread misinformation! Aw crap it disturbs me too much to think about!
I guess I have to stop watching documentaries.