Browsed by
Category: How To

YouTube: Something went wrong. Tap to retry.

YouTube: Something went wrong. Tap to retry.

YouTube videos won’t play on iPad!

For the past two weeks my kids have had trouble watching YouTube videos on their iPads. It works for a while, then they see a message after the video’s ads play saying, “YouTube: Something went wrong. Tap to retry.” This issue has been prompting YouTube iPad users to “Tap to retry” for years.

The only solution for making the YouTube app work on their iPads has been to completely reset their “Network Settings.” I’ve googled this issue 20 times, but haven’t seen a solution, so here’s what I did:

YouTube bloody you logo

Read More Read More

Mac Dad’s adventures in PC gaming: Rust on Steam

Mac Dad’s adventures in PC gaming: Rust on Steam

Attn: All Mac Dads

If your kids ask for a PC for gaming, just tell them you can’t afford it. It won’t be a lie, specifically, considering how much time you have to spend updating drivers and frameworks.

Rust PC Game LogoTonight my oldest wanted to try out a PC game called Rust. According to Steam’s Rust page, “The only aim in Rust is to survive. To do this you will need to overcome struggles such as hunger, thirst and cold. Build a fire. Build a shelter. Kill animals for meat. Protect yourself from other players, and kill them for meat. Create alliances with other players and form a town. Whatever it takes to survive.”

Sounds legit, right? I added funds to his Steam account, and told him to go ahead. Just kidding! PC gaming is so complicated that you can’t simply shove money into an account and say “go!” So after an hour of typing in passwords, birthdates, logging out, logging back in, putting my birthdate in instead of his, logging out again and then back in, I finally got through it all and then, stopped dead in my tracks by some pop-up window installer called something like “Super Easy Don’t Cheat Installer.

Read More Read More

How to run PHP scripts in Xcode Mac OS X applications

How to run PHP scripts in Xcode Mac OS X applications

Picking a starting point

I spent a lot of time looking around the web for instructions on how to execute PHP scripts in Xcode applilcations only to find a whole lot of nothing. I knew it could be done since there are several apps in the Mac App Store that allow you to interpret PHP on the fly, so I set out to do it without the help I believed I needed. It turns out to be one of the easiest things I’ve done in Objective-C.

There is an update to this post where I’ve done the same thing using modern Swift and incorporated a very basic syntax highlighter.

Swift PHP Runner

The first thing I did was to download the JavaScript Interpreter sample code from the Apple developer site for reference. It’s old code and doesn’t compile readily on a 64 bit system with the OS X Lion SDK, so to get it to run I had to change the target to fit my system as shown below. Xcode will also ask you if you want to update the code to current standards – go ahead and do that.

Xcode screenshot

Getting Objective-C to execute PHP scripts

Next, I changed the code to skip the JavaScript interpreter and use PHP instead. This involves the NSTask Class from the Foundation Framework. Luckily the Foundation Framework is already included in the JSInterpreter sample code. While we’re talking about included Frameworks, you can go ahead and remove the reference to the JavaScript Framework now. To get rid of the red squiggly lines and error messages, delete the #import directive at the top of the MyController.m file along with all of the code inside the evaluateScript method.

Next, I searched for a way to run a command line script similar to “> php testing.php” that would allow me to execute a script and see its output. As always, Stack Overflow came to my rescue. I took the basics of the code there and went to (not very much) work.

First, I had to replace the NSTask LaunchPath with the php binary executable on my system, which is at /usr/bin/php.

Next I had to replace the arguments with the code I wanted to run, which was at ~/tonyj/Sites/harikari/test/testing.php – a script that simply echos “Hello world!” To keep from having to alter the existing code too much, I put in the whole path but left out the filename so that I could type it into the input field of the original application and have it executed when I clicked the button.

That’s it. I built and ran the application and I had a window with an input field and an output filed. I typed the name of my script into the input field and, ta-da!, “Hello world!” appeared in the output field.

[asa]032188728X[/asa]

A standalone application?

Next I wanted to see if I could make the whole thing a standalone application. This being my first attempt at writing a Mac OS X application in Xcode, I had no idea where to start. So I just went for it. I added my PHP binary to my application (File -> Add Files to JSInterpreter) and then added my script to the project. I wasn’t quite sure what the path was going to be for either of them in the application bundle, so I went back to Stack Overflow to find out about [NSBundle mainBundle] resourcePath] as a method for getting the path to the inside of your application, wherever it may be.

It worked!

With one caveat: I haven’t worked through all of the details yet, so I’m sure there are some dependencies in the PHP binary that my system provides in the place that PHP is looking for them. But I’m confident that it would not be difficult to find and eliminate or compensate for them.

Also, Objective-C doesn’t automatically wait for the return value from a task the way PHP does. And PHP is sometimes a little slow to respond. So you have to figure out how to make it wait around for a response from PHP and your script, especially if it’s a lengthy one. Once again, Stack Overflow helped me find information about the NSNotificationCenter. I don’t know much about it, but it basically notifies your code when the PHP output file is done loading.

Now I can load any PHP script into my application and send and receive messages to and from it. I might try adding MySQL tomorrow.

The code:

Fork me on GitHub

-(NSString *) evaluateScript:(NSString*)scriptName
{
    NSTask *task = [[NSTask alloc] init];
    NSString *taskPath =
        [NSString stringWithFormat:@"%@/%@",
        [[NSBundle mainBundle] resourcePath], @"php"];
    [task setLaunchPath: taskPath];

    NSArray *args;
    NSString* scriptPath =
        [NSString stringWithFormat:@"%@/%@",
        [[NSBundle mainBundle] resourcePath], scriptName];
    NSLog(@"script file path: %@",scriptPath);
    args = [NSArray arrayWithObjects:scriptPath, nil];
    [task setArguments: args];

    NSPipe *pipe = [NSPipe pipe];
    [task setStandardOutput: pipe];

    NSFileHandle *file = [pipe fileHandleForReading];
    [file waitForDataInBackgroundAndNotify];
    [[NSNotificationCenter defaultCenter]
 addObserver:self 
           selector:@selector(receivedData:) 
               name:NSFileHandleDataAvailableNotification 
             object:file];
    [task launch];

    NSData *data = [file readDataToEndOfFile];
    NSString *string =
        [[NSString alloc] initWithData: data
 encoding: NSUTF8StringEncoding];

    return string;
}

- (void)receivedData:(NSNotification *)notif {
    NSFileHandle *file = [notif object];
    NSData *data = [file availableData];
    NSString *str = [[NSString alloc] initWithData:data
 encoding:NSASCIIStringEncoding];
    NSLog(@"%@",str);
}

Altering the code

This is an example of how to type in the name of any file included in your project, but you may want to just execute raw PHP commands or fully integrate PHP into your app. To do this, just look at the line above where the args variable is set. You want your array to have filepath as its first element, then any arguments you want to have available in the argv[] array.

If you want to execute single PHP functions, your first arg will be “-r”, followed by the function as in the following example.

args = [NSArray arrayWithObjects:@"-r",@"is_array(array(1,2,3))", nil];
How to explain Thanksgiving to kids, adults, and the rest

How to explain Thanksgiving to kids, adults, and the rest

How to explain Thanksgiving to Kids:

When we’ve, collectively, been asked to explain Thanksgiving to kids and wanted to approach it with a modern and honest, progressive, inclusive answer, some of us have been at a loss for words. The brutality, deception, racism, and genocide are honestly too much to include in the story of an American tradition that is based on the struggles, challenges, and determination of the first and earliest European Americans. Thanksgiving is, really, some Americans’ favorite holiday.

So Let’s take a stab at a script for progressive parents faced with the challenge of explaining Thanksgiving to kids without inducing nightmares.

A long time ago, when the first Americans came from Europe, they had a really hard time surviving their first winter. The next year, they worked really hard and made friends with some of the Native Americans that lived near them. That fall, in 1621, they celebrated their hard work with a harvest festival. The settlers invited their Native American friends to join in the feast. The first Thanksgiving lasted for 3 days and everybody had plenty to eat, including turkey, cranberries and pumpkins. Every year, we celebrate Thanksgiving as a time to be thankful of all the things that we have in our lives…

More information about how to explain Thanksgiving to kids can be found here.

 

For the Adults:

The settlers at Plymouth, Massachusetts had a very tough first winter, with nearly half of the settlers dying. The next year, the remaining settlers worked very diligently to establish food stores to get them through the next winter.
Over time the tradition of thanksgiving feasts ebbed and flowed, but the slaughter of the Native Americans grew until 95% of all Native Americans were murdered, nearly 12 million innocent Native Americans.

The tradition of murder continues, the United States kills 300 million turkeys each year, 45 million are murdered to celebrate Thanksgiving alone.

Explain Thanksgiving to kidsIn the fall of 1621, these settlers held a harvest feast which lasted 3 days. As they had recently signed a peace treaty with a nearby Indian tribe, the Indians were invited and brought a lot of venison to the feast.  The next several years found the Indians more likely to be murdered by the settlers than to be invited to the fall harvest feast.

What you can do:

It is no wonder that the United States and Americans in general are considered to be more agressive and violent by much of the world. The United States is built upon the killing of innocent people and animals.

Fortunately you can make a difference. Say no to the killing and choose a vegetarian option. Think different, think Tofurky.