Tuesday, August 21, 2012

Downcast Is an Incredible Podcast Downloader, Player, and Manager for iPhone

Apple's built-in iPod app has always left something to be desired when dealing with podcasts, as downloads are still aren't automatic and there are very few features dedicated to podcast listening in the first place. Downcast is the podcatcher and player that the built-in app ought to be, adding a bunch of great new features that make it the perfect alternative.

Unlike the iPod app, you can search for and add podcasts directly from the app. New episodes download automatically (even in the background, on newer devices), and you can manually download older episodes as well. You don't have to download if you don't want to—you can just stream an episode if that's better for you. If you can't find the podcast you're looking for via search, it can be added manually with a URL. When listening you have the same playback controls you have in any app, along with the ability to vary your scrubbing speed. Additionally you get AirPlay support for both audio and video, the option to rename podcasts (for when they have really long, annoying names), set a sleep timer, and a lot more.

What's probably one of the coolest features, however, is the gesture support. If you're in bed, in the car, or just can't really look at your iPhone's screen, you can use Downcast's gestures to toggle playback, move back and forward in the podcast, and mark an episode as played or unplayed.

If you're a heavy podcast listener, it's definitely worth the $2. The only downside is that it doesn't integrate directly with the iPod app, but that's not Downcast's fault and a very minor inconvenience when compared to all the great things it can do.

Monday, August 6, 2012

Five More Tips for the Downcast

After I wrote last week’s post, Lift Up the Downcast, I thought of a few more things that are important to consider when trying to overcome a difficult time in your life.
  1. Go see your doctor. Get a physical to check for any physical problems, and talk to him or her about how you are doing. It is very common for an illness or untreated condition to affect every part of you, including your energy level and outlook on life in general. They will collect some labs to look for things like low iron, an out-of-whack thyroid, or abnormally high white cell count (indicates that your body is fighting an infection somewhere). The doctor should be able to work with you to identify ways for you to improve your physical health. This in turn will improve your mental/emotional/spiritual health, or at least give you the energy to keep working.
  2. Get some exercise. I know, the dreaded E-word. But I’m living proof that being more active will truly help you feel better. Last summer, I went to yoga classes and started jogging with our new dog. She needed the exercise, so she was built-in accountability. I just couldn’t ignore her pathetic whines for a morning walk! All in all, I felt, physically, really good through the summer and into the fall. I was in the best shape of my married life and all the activity helped me sleep well. All of this made it much easier to grieve well. Then, October. It was the first anniversary of Ellie’s death, and at the same time, both my youngest and I caught a vicious flu. That began a series of illnesses in our family that, combined with an unusually bad winter, kept me indoors and away from the gym for six months. I have been quite amazed at how bad I feel when I don’t exercise. My sleep is poor, my energy levels is the pits, my ability to focus is shot, and my spirits have been so very low.
    Now that the sun is coming up earlier (at least, until March 14 *grrrrr* when, thanks to the genius who invented daylight savings time, we have to turn our clocks forward. But. I’m. Not. Bitter.), snow doesn’t cover my running path, and the air is warmer, I hope to get back out with our dog again.
    Exercise can be very simple and low-tech. Turn on one of those free PBS workout shows in the morning and start moving in the privacy of your own home. Or get a treadmill or stationary bike off Craig’s List. Take a walk. Find someone to go with you for accountability and good conversation.
    If you want to try jogging, sign up for a race. Many worthy causes have fund-raising races all over the country. My first race raised money for women’s health, and I walked about half of it…but I finished! It’s amazing how motivating it is to have a goal like that to work towards. My husband and I are excited to participate in a 5K fundraiser for a wheelchair-accessible playground in our city. My goal is to run the whole thing, even if my pace is terrible!
  3. Do some homework if you are considering trying supplements and/or prescription medications. If you’ve tried everything else and you just can’t get over the hump, it might be worth trying a medication. Again, talk with your doctor about this. They will help you select the best things to try and often have non-prescription options as well. Taking a pill, whether it is an antidepressant or an herbal remedy, is not going to make you happy. These treatments are designed to help you climb out of a pit just enough to try some of these other suggestions, which are much better long-term solutions.

    Be sure to ask your doctor and pharmacy about how various things interact.
    Tell them everything you are taking, including herbals and home remedies, because some things are very dangerous to combine. And if you think you need to change something because it isn’t working, don’t just stop cold-turkey! Call your doctor or pharmacist to see if you need to wean yourself off or if it is safe to just stop. The best advice I was given about trying meds? Do only one thing at a time, and give it at least a month before changing anything. Otherwise you won’t know what helped and what didn’t.

  4. Find out what things push you over the edge and avoid them until you are stronger. I work part-time at the hospital where Ellie received treatment from 3 days old until her death. Going to work triggers memories. Many of those memories are good — we met some incredible people at the hospital. But it is exhausting, and often I’m blindsided by a memory or a flood of emotions at the most inopportune time. And there are certain aspects of my job that I simply cannot do right now. They are too painful and too emotionally-charged for me to handle professionally. I am so thankful for understanding coworkers and boss who are more than willing to adjust responsibilities so that I can avoid those things for now.
  5. Give yourself some cushion. As I’ve wrestled through this difficult winter, I realized that my weeks are so tightly-scheduled that I have no slack at all for bad days. But I’ve realized that bad days will come. You know the kind: it’s all you can do to get the kids fed, dressed, and to school, and when you finish that, you collapse on the couch for hours. Forget laundry, paying bills, washing dishes, cleaning house, grocery shopping. When that happens, I’ve realized that it’s time to remove some things and/or ask for help. In my case, we’ve decided to cut back my work schedule from two days per week to one day per week. If that doesn’t give me enough, we’ll consider something else.
I am no professional, so please don’t take these as the definitive truth on depression. I offer them up as ideas picked up along my own struggle in hopes that they encourage you to keep going, keep trying, and most importantly, get help.

Friday, July 20, 2012

Upcasting, downcasting 

Upcasting and downcasting are important part of Java, which allow us to build complicated programs using simple syntax, and gives us great advantages, like Polymorphism or grouping different objects. Java permits an object of a subclass type to be treated as an object of any superclass type. This is called upcasting. Upcasting is done automatically, while downcasting must be manually done by the programmer, and I'm going to give my best to explain why is that so.

Upcasting and downcasting are
NOT like casting primitives from one to other, and i believe that's what causes a lot of confusion, when programmer starts to learn casting objects.

Throughout this tutorial i'm going to use Animal hierarchy to explain how class hierarchy works.


Inheritance


Posted Image

What we have here, is a simplified version of an Animal Hierarchy. You can see, that Cat and Dog are both Mammals, which extends from Animal, which silently extends from Object. By silently, i mean, that Java automatically extends every class from Object class, which isn't extended from something else, so everything is an Object (except primitives).

Now, if you ask - is Cat an Object - It doesn't extend Object, it extends Mammal?

By inheritance Cat gets all the properties its ancestors have. Object is Cat's grand grandparent, which means Cat is also an Object. Cat is also an Animal and a Mammal, which logically means - if Mammals possess mammary glands and Animals are living beings, then Cat also has mammary glands and is living being.

What this means for a programmer, is that we don't need to write for every possible Animal, that it has health. We just need to write it once, and every Animal gets it through inheritance.

Consider the following example:

class Animal {
        int health = 100;
}
class Mammal extends Animal { }
class Cat extends Mammal { }
class Dog extends Mammal { }
public class Test {      
         public static void main(String[] args) {
                 Cat c = new Cat();
                 System.out.println(c.health);
                 Dog d = new Dog();
                 System.out.println(d.health);
         }  } 

When running the Test class, it will print "100" and "100" to the console, because both, Cat and Dog inherited the "health" from Animal class.

Upcasting and downcasting

First, you must understand, that by casting you are not actually changing the object itself, you are just labeling it differently.
For example, if you create a Cat and upcast it to Animal, then the object doesn't stop from being a Cat. It's still a Cat, but it's just treated as any other Animal and it's Cat properties are hidden until it's downcasted to a Cat again.
Let's look at object's code before and after upcasting:
        Cat c = new Cat();
        System.out.println(c);
        Mammal m = c; // upcasting
        System.out.println(m);
        
        /*
        This printed:
                Cat@a90653
                Cat@a90653
        */      

As you can see, Cat is still exactly the same Cat after upcasting, it didn't change to a Mammal, it's just being labeled Mammal right now. This is allowed, because Cat is a Mammal.

Note that, even though they are both Mammals, Cat cannot be cast to a Dog. Following picture might make it a bit more clear.
Posted Image

Although there's no need to for programmer to upcast manually, it's allowed to do.
Consider the following example:

        Mammal m = (Mammal)new Cat();

is equal to

        Mammal m = new Cat();

But downcasting must always be done manually:

        Cat c1 = new Cat();              
        Animal a = c1;           //automatic upcasting to Animal
        Cat c2 = (Cat) a;       //manual downcasting back to a Cat

Why is that so, that upcasting is automatical, but downcasting must be manual? Well, you see, upcasting can never fail. But if you have a group of different Animals and want to downcast them all to a Cat, then there's a chance, that some of these Animals are actually Dogs, and process fails, by throwing ClassCastException.
This is where is should introduce an useful feature called "instanceof", which tests if an object is instance of some Class.
Consider the following example:

        Cat c1 = new Cat();              
        Animal a = c1;           //upcasting to Animal
        if(a instanceof Cat){ // testing if the Animal is a Cat
                System.out.println("It's a Cat! Now i can safely downcast it to a Cat, without a fear of failure.");            
                Cat c2 = (Cat)a;
        }       

Note, that casting can't always be done in both ways. If you are creating a Mammal, by calling "new Mammal()", you a creating a Object that is a Mammal, but it cannot be downcasted to Dog or Cat, because it's neither of them.
For example:
        Mammal m = new Mammal();
        Cat c = (Cat)m;

Such code passes compiling, but throws  "java.lang.ClassCastException: Mammal cannot be cast to Cat" exception during running, because im trying to cast a Mammal, which is not a Cat, to a Cat.

General idea behind casting, is that, which object is which. You should ask, is Cat a Mammal? Yes, it is - that means, it can be cast.
Is Mammal a Cat? No it isn't - it cannot be cast.
Is Cat a Dog? No, it cannot be cast.
Important: Do not confuse variables with instances here. Cat from Mammal Variable can be cast to a Cat, but Mammal from Mammal variable cannot be cast to a Cat.

Cats cant purr, while being labeled something else
If you upcast an object, it will lose all it's properties, which were inherited from below it's current position. For example, if you cast a Cat to an Animal, it will lose properties inherited from Mammal and Cat. Note, that data will not be lost, you just can't use it, until you downcast the object to the right level.
Why is it like that? If you have a group of Animals, then you can't be sure which ones can meow() and which ones can bark(). That is why you can't make Animal do things, that are only specific for Dogs or Cats.
Posted Image

However the problem above is not an obstacle, if you choose to use polymorphism. Polymorphism uses automatic downcast during method calls. I'm not going to go into details with this one, so i'm referring to Polymorphism tutorial by Turk4n: http://forum.codecal...lymorphism.html
Posted Image

Upcasting during method calling

The beauty of casting is that programmer can make general methods, which can take a lot of different classes as an argument.
For example:

        public static void stroke(Animal a){
                System.out.println("you stroke the "+a);
        }

This method can have what ever Animal or it's subclass as an argument. For example calling:

        Cat c = new Cat();               
        Dog d = new Dog();               
        stroke(c); // automatic upcast to an Animal
        stroke(d); // automatic upcast to an Animal

..is a correct code.

Posted Image

however, if you have a Cat, that is currently being held by Animal variable, then this variable cannot be argument for a method, that expects only Cats, even though we currently have a instance of Cat  - manual downcasting must be done before that.

Posted Image

About variables

Variables can hold instance of objects that are equal or are hierarchically below them. For example Cat c; can hold instances of Cat and anything that is extended from a Cat. Animal can hold Animal, Mammal, etc..
Remember, that instances will always be upcasted to the variable level.

"I really need to make a Dog out of my Cat!"

Well, you can't do it by casting. However, objects are nothing else, but few methods and fields. That means, you can make a new dog out of your Cat's data.

Let's say you have a Cat class:

class Cat extends Mammal {
        Color furColor;
        int numberOfLives;
        int speed;
        int balance;
        int kittens = 0;
          
        Cat(Color f, int n, int s, int b){
                this.furColor = f;
                this.numberOfLives = n;
                this.speed = s;
                this.balance = b;                 
        }         }

and a Dog class.

class Dog extends Mammal {
        Color furColor;   
        int speed;
        int barkVolume;
        int puppies = 0;
          
        Dog(Color f, int n, int s, int b){
                this.furColor = f;                
                this.speed = s;
                this.barkVolume = b;              
        }         }

and you want to make a Dog out of the Cat. All you need to do, is, place a method inside of the Cat class, that converts the fields and returns a new Dog based on that.

        public Dog toDog(int barkVolume){                 
                Dog d = new Dog(furColor, speed, barkVolume);
                d.puppies = kittens;
                return d;                 
        }

As you can see, they don't match that well, so some fields were inconvertible, and some data had to be made from scratch. Notice, that numberOfLives and Balance were not converted, and barkVolume was completely new data. If you have 2 Classes, that match perfectly, then hurray, but it rarely happens.
conversion can now be called from where ever you need:

        Cat c = new Cat(Color.black, 9, 20, 40);
        Dog d = c.toDog(50);

 

Monday, June 25, 2012

How to Downcast in VB.NET

Visual Basic (VB) is a computer programming language and integrated development environment (IDE) developed by Microsoft based on the Basic computer language. The .NET version allows programmers to create programs for the .NET Framework. Downcasting, as it refers to programming, is the process of refining a reference from a derived class to its base class. Downcasting is mostly seen in C++, C# and Java programming languages, but it can also be done in VB.NET. In VB.NET, casting is usually automatic once an object has been assigned to a variable. However, you can turn off the automatic casting function and specify the downcasting in the VB.NET code. 

Instructions:

1. Open VB.NET or Visual Basic 2010. The .NET version of the IDE is the first to use the .NET Framework. The 2010 version also allows for programming with the .NET Framework. Choose to open an existing project or start a new one from the Welcome screen.

2. Click on the "View" menu item and then "Code" to open the Code Editor. You can also right-click anywhere on a form and then "View Code" to also open the Code Editor.

3. Change the "Option Strict" property to "On" at the top of the VB.NET code by adding the following line:

"Option Strict On"

This turns off the automatic casting function in VB.NET and ensures that the only casting that will be done will be specified by the programmer.

4. Use the "DirectCast" operator to do explicit casting. Also, use the "GetType" operator to ensure that the object that you are working with is valid for downcasting. For instance, if you want to do downcasting on a text box, the code will be:

"Dim x As System.Type

x = txtExample.GetType()

MessageBox.Show(x.FullName)

If TypeOf x Is TextBox Then

x = DirectCast(txtExample, TextBox)

End If"

5. Click on the "Save" icon to save the changes to the code.

 


 

Thursday, June 7, 2012

Psalm 42:5, 42:11 and 43:5 all say the same thing.

Why are you downcast, O my soul?
Why so disturbed within me?
Put your hope in God,
for I will yet praise him,
my Savior and my God.
I’ve recently be trying to impart wisdom to my teenage daughter. As most of you know, imparting wisdom is a difficult thing for most of us. However, unfortunate or not, most of us have plenty of experience to reach back to which helps us offer up the “life-type” of wisdom. In the end, I guess this type of wisdom is more real than anything else we could use.
If you’ve ever heard my college time stories, then you’ve heard all of the gory detail of how I basically just threw away a 4 Year Air Force scholarship. It was a difficult time in life of going from being a teenager with no real responsibilities to becoming the adult we all have to become whether we want to or not.
During this time, the enemy threw plenty of ideas, philosophies and “new” thoughts on religion my way in order to dissuade me from following the Truth. This came through other people sharing their philosophies with me, through the many new and different churches I tried out, and through fellow college mates. The one thing that seemed to pull me through all of this were the verses mentioned above.

There were times I could not feel God or sense God. I was not experiencing His power or presence. I felt all alone. And the temptation to follow some of the “new” thoughts or paths was there as well. It was then the Holy Spirit gave me these 3 verses. If you will notice, they all say the same thing. And God said it to me 3 times that day so I would hear what He was trying to say.

No matter what I was going through, no matter how bleak things seemed, no matter how confused I was or lost I seemed … I only had to look back on my life and remember the times where God was more real than ever … and this enabled me to remember and believe those times would once again be true in my life.

I will YET praise HIM …
Things will always get bad at times in life. Ours is to remember that God is God during the bad times just as well as the good times. Ours is to be faithful to Him no matter what.