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.

Wednesday, December 30, 2015

The strange case of the alien worshipers

When I heard that some people believe that an alien dropped our souls in a volcano and that he will be back someday to collect us I thought “how weird”!
Then I thought that's not too different from what Christians believe.  An alien made this world so he could create life that would adore and worship him.  He destroyed the world a couple of times just because he didn't like how his creations turned out.  He made a bet with a fallen Angel, another alien race, that Job would love him no matter how bad he made his life.  This alien killed Job's wife and kids, and all his livestock, gave him diseases and turned everyone against him.  Just to prove to this other alien that Job would love and worship him forever.   He destroyed two cities because Lot couldn't find a good man. Then he turned Lot's wife into salt because she turned to look at the devastation.   Aliens called angels are sent down to earth, from his world called Heaven,  to teach us stuff and tell us when bad stuff is going to happen.  The Alien 'GOD' ordered Moses to kill all tribes that have non-believers and inspect their girls to see if they have known man. In public in front of everyone Moses strips the clothes off young girls and checks their virginity.  He kills all the women that have know man.  THAT'S suppose to be normal for Christians.
This Alien found a preteen virgin and made her pregnant with his spirit.  The child is born in a lowly manger and is told he is the King of the Jews, who reject and kill him!  He comes back from the dead, creepy, and become their Deity.  His followers cover the world and kill non-believers for a couple thousand years until the current followers no longer 'follow his words' yet still try to kill non-believers!
His message of Love and Peaceful co-habitation are lost and all that is left is several cults that disagree with each other over what he said, while blowing up clinics and shooting non-believers that perform legal operations.  Still they all believe that they are the chosen ones that will be swept away to Heaven while the rest of the world burns in the fiery ruins of the earth.  I think about some of this and am disgusted by their behavior.  Love and Peaceful co-habitation once meant with everyone but now it means with others that agree with their version of this story. To hell, a hot and bad place, with anyone that disagrees with them.  I may have skipped a few bits along the way but just this bit makes me sick.  How can anyone follow this nonsense with an open mind and still believe it????
If you are still reading this then you must be special!  This is why I can not believe in this nonsense. How about you?  Have you thought about what it would be like to live without Gods?  Without judgment?  Free to explore the world and think about new things, to create things.  Maybe create new life that has never been seen on earth, so I have someone to worship me.  I do this in my computer create new code, that's what we are is code called DNA.  What if I code a new life-form?  Would these Christians kill me because I do not follow their restrictions against almost every form of scientific study.  I wish to live in a world where I can be naked all the time and sex is thought of s natural.  A place where religion is a private thing and no-one needs fear the beliefs of others.  Share this if you agree that people should not be prisoners of a religion that they do not believe in!

Sunday, November 22, 2015

How time has warped the minds of this mighty secular nation!

How have we allowed the Christians to derail the Constitution and pervert this mighty secular nation?

The First Amendment to the Constitution grants Americans the "freedom from religious persecution" and yet the Christians have perverted this Amendment to mean "freedom of religious".  A subtle yet important difference exists that can not be allowed by the free people of this mighty secular nation.  In "freedom from religious persecution" every citizen is protected from religious persecution and the other has come to mean that the government can not control the actions of individuals claiming religious authority.  The intent was to protect from religion those that seek such protection from religious laws that are in conflict with national or state laws.  No citizen shall be held to answer to a religious authority expect by choice and that no religious authority shall hold power over the people of this mighty secular nation.  If a citizen chooses to reject the faith of their parents or community such citizen has the protection of the First Amendment to the Constitution and can not be compelled to return to that religion.  The citizen has the right to live either in that community or to leave to establish a new home free from persecution.  No citizen shall be marked or harassed by others that seek to compel them to except a religion not of their own choosing by protection of the First Amendment to the Constitution.  Any citizen calling for such markings or refusal to allow others to live their lives free from such religious persecution is in conflict with the Constitution and hence The Federal Laws of this mighty secular nation.  No religious test or requirement shall be enforceable upon an application for citizenship under the protection of the First Amendment to the Constitution.

On a historical note: Ten years after the Constitutional Convention ended, this mighty secular nation assured the world that the United States was a secular state, and that its negotiations would adhere to the rule of law, not the dictates of the Christian faith.  According to Frank Lambert, Professor of History at Purdue University, the assurances in Article 11 of The Treaty of Tripoli were "intended to allay the fears of the Muslim state by insisting that religion would not govern how the treaty was interpreted and enforced. John Adams and the Senate made clear that the pact was between two sovereign states, not between two religious powers.

Ref:
Art. 11. of The Treaty of Tripoli as presented to the Senate by President John Adams;
As the Government of the United States of America is not, in any sense, founded on the Christian religion; as it has in itself no character of enmity against the laws, religion, or tranquility, of Mussulmen (Muslims); and as the said States never entered into any war or act of hostility against any Mahometan (Mohammedan) nation, it is declared by the parties that no pretext arising from religious opinions shall ever produce an interruption of the harmony existing between the two countries.

Saturday, November 21, 2015

Holiday advice that you didn't ask for!

A major cause of holiday upset is when one party has expectations but never voices them, expecting another to 'just know' what the first party was thinking. Good trick if it can be done but mind reading does not really exist!

We assume people will do things the same way we do, such as be on time for appointments, pay their fair share in a restaurant, and tell us in advance if they’re going to miss a deadline—because that’s what we do. We don’t tell people what we expect from them, because we don’t think we need to.
It’s a little like being frustrated that you were hoping for a new iPad for your birthday but not telling anyone, and then being annoyed when you receive a series of coffee-table books that will go straight to your re-gifting shelf.
you: “How could he not know I wanted an iPad?”
the Voice of reason: “Because you never told him.”
you: “But I shouldn’t have to tell him. He should just know.”
the Voice of reason: “Expecting people to know what you want without telling them is insane."

Do not go insane on the ones you love. Share your thoughts, hopes and dreams. You will be rewarded

heart emoticon

Monday, November 2, 2015

Plan ahead. What can it hurt?

I was recently looking for a TV show called Earth2 and was amazed by the great number of disaster movies.  Why are humans so obsessed with disaster movies?  Could it be that they don't realize that the Earth has been here for 4+ billion years (not 6 thousand years) and will most likely exist for another 4+ billion years?!?! What most likely will be the case is that there will be another mass extinction event in which Humans, as we know them, will cease to exist.  Look around at the people in your circle, how many of these idiots do you see surviving a MEE?  How many of you know how to make fire, without a lighter?  How many people can find food or fresh water in a flooded Mega-city?  Are you prepared for a world without electricity or super-mega-stores?  When was the last time you hunted for a live animal for food (not sport)?
You my friend may be ill prepared for what is to come the day after tomorrow.  Your life expectancy is not looking very good if Hackers shut down the power grid. I doubt that more than a small percentage of you will last out a month without cars; smart-phones; or the Internet.  Maybe it’s time to use that selfie-stick to take a picture of your back-side as you kiss it goodbye! Try going one week-end without touching anything electric.  It isn’t going to happen, not in my lifetime anyway.  If you’re like me and you’re feeling a little concerned about global climate change maybe you should stock up on a few survival tools.  There is a solution to the problems that will be here in your lifetime but can you; will you prepare!  What could it hurt to have a portable drinking water filter or some camping gear in a bag, ready to bug out.  AND if you don’t need it you can leave it to the kids that will have to live in a climate so radically different than ours.  You could just deny the scientific facts  that the climate is changing and hide your head up your arse like the Republican party. That way the survivors won't have to worry about what will happen to your unprepared arse, they can just watch you as scramble for food in the empty super-mega-stores.  Maybe the really smart ones will sell you some scrapes at a few hundred dollars a pound.  If you have any money after the banks fail and the ATM’s are under water.  I don’t see it happening and if you think i’ll share, think again.  I’ll be selling drinking water from my water purification system if you got the gold.  Because gold will be the new money and if you don’t have any you can find out if it’s true that man can not live 100 hours without fresh water.  I will gladly help you test that scientific fact.  

Plan ahead.  What can it hurt to spend a few hundred in the sporting goods department now and not have to go without!  If you live by the coast owning a row boat couldn’t hurt either.  If you really need those electric toys then get a hand cranked generator and a few dozen rechargeable batteries.  On eBay you can get a battery charger that turns salt water into electricity for less than $20 or a few solar cell battery packs for around $40.  Chemical heaters, thermal undies and bug nets are a good start toward survival preparedness.  A bug-out bag with two weeks of freeze-dried food and many survival tools cost around $200-$300.  I recommend the best that you can afford and keep the bag in a closet by the door with your cross-bow.  It will not cost a lot to be prepared and if a superstorm hits you will look like a genius instead of the fool in a Red Cross shelter.  

Plan ahead and hope for the best but expect the worst!