Showing posts with label automate. Show all posts
Showing posts with label automate. Show all posts

2014-12-05

Level Up - Android Studio: How to Boost Productivity By Auto-Generating Getters and Setters

A best practice in Java is to encapsulate field variables by making them private and creating a "getter" and "setter" for each of them, as needed. Doing this with many fields can be a lot of boilerplate code to write. But, thankfully, modern IDEs, like Android Studio provide ways to auto-generate code so that you don't have to manually write it.

For example, if you have a class like the following:

public class MyClass {
    private int mId;
    private String mName;
}

Instead of manually writing each accessor (getter) and mutator (setter), go to the menu and click Code->Generate.. (hotkey `alt+insert), then choose the "Getter and Setter" option.

Done. That was fast. And, it will be just as fast with 20+ fields also.

But, wait! By default, Android Studio will include that "m" prefix (stands for "member" variable) in each of the generated method names, so you'll have method names like "setmId" and "getmId". There is a quick permanent fix for this also!

Go to File->Settings->Code Style->Java->Code Generation, then type a single "m" into the "Field", "Name prefix" field. Hit apply, then you are gone. All future code generations will take those "m" prefixes for field into account. Here's a screenshot to what this sentence means visually.

So easy to save a lot of time with Android Studio

That's it for this post. There are lots of other useful code generators also. If you are doing mindless work, it's probably been automated (or should be). ;)

~ Danial Goodwin ~



2014-02-20

Experience Publishing to Different App Platforms

Q: How do you gain experience in publishing apps to a certain platform?
A: You create 100 apps and publish them.

Q: How do you lose experience in publishing apps to a certain platform?
A: You create 100 apps and publish them. (Details below)

I don't think anybody actually asks the second question (but I just did!). Anyways, after the first few publishes, programmers/hackers get tired of the same routines. Our jobs are basically to automate things and makes things easier!

So, that's what I did and am doing. I'm starting to automate the entire process of publishing an app. There is this great tool that is a high-level scripting language called AutoHotkey. With it, I can easily open any program programatically, and send any keyboard and mouse commands that I want to the program. Basically, a macro builder for the entire end-user operating system.

About half of the process is automated now. I'm about halfway to my personal goal of 100 apps. My goal would be to make the entire process from app file to publish a one-click process. I know it's possible, and it'll be fun to build.

Once the process is all automated, I can be free to forget the process and start thinking of other abstractions to make.

;)
~ Danial Goodwin ~



2013-09-27

Share: What is so great about Computer Science?

"I don't know of any other discipline that makes you feel so much like a wizard. Even engineering doesn't really feel that way, because you actually have to do real work fitting things together and what not.

In contrast, when you program something, you're basically just muttering incantations and casting spells. Do it right, and incredible stuff just springs to life.

And the stuff you're manipulating is almost dreamlike. Take a simple bug fix, for example. The concept doesn't quite exist in other forms of engineering, because if you're building something physical, even a small design flaw is difficult to fix. You have to take it apart, whack stuff into position, and usually you just wind up realizing that it would be easier to rebuild everything from scratch.

Whereas for a computer scientist, that's normal. Change a few things here and there, and bam - your updated program bursts into existence. You can do this because manufacturing software is easy (compile and run, or some equivalent) - almost all the work and difficulty is in thinking of it and designing it. It's basically an abstract mental construct.

Also, if you're a lazy bum like me, you'll fit right in. All computer scientists worth their salt have a massive hatred of tedium. That's why we always want to automate and generalize everything! Repetitive boring work is for machines.

Case in point: I recently had to enter a bunch of data on a website. There was no nice bulk upload facility, so I was reduced to painstakingly copying and pasting stuff from my file into their forms. After doing this for about a minute, I came to my senses and remembered that I wasn't a Muggle.
 
Less than an hour later, I had a program that just mimicked all my copy/paste actions hundreds of times faster than me. Hours of tedious error-prone work turned into a few minutes. As a bonus, it impressed the hell out of people who passed by and saw me reading a book while a bunch of text fields magically filled themselves on the screen. (I may have put in a slight time delay just for fun...)

Like I said, CS makes you a wizard."

Source: Quora's Nadeem Mohsin


2013-07-14

How To Programmatically Batch Resize A Folder Of Images

(This post gives a walkthrough on how to automatically resize a bunch of pictures at once. I provide four different ways to do the resizing, in order of least optimal to most optimal IMO. There may be more ways for programmatically resizing, but I'll most likely be using the fourth method below all of the time.)

1. ImageMagick
2. IrfanView
    2.1. Benefits
    2.2. Limitations
    2.3. Walkthrough
3. Photoshop's Automate Batch
    3.1. Benefits
    3.2. Limitations
    3.3. Walkthrough
4. Photoshop's Scripts Image Processor
    4.1. Benefits
    4.2. Limitations
    4.3. Walkthrough

--

1. ImageMagick: Allows you to run image processing in a Windows command windows. So, you must be comfortable creating BAT (batch) files. I did not use this method, but here's the documentation for batch resizing this way: http://www.imagemagick.org/Usage/windows/

FOR %a in (*.jpg) DO convert %a -resize 50% small_%a
ImageMagick Example

2. IrfanView: When I tried this method, I got the feeling this tool was very old, but it still seems to be regularly updated. Also, IrfanView has many image manipulation features available for it. Many of them seem useful, but this time I was only interested in the resize feature.
2.1. Benefits: Very lightweight program at 2MB.
2.2. Limitations: When I tried to batch resize, each of the images lost their alpha transparencies, and the backgrounds all turned black.
2.3. Walkthrough: Drag a selection of images into the screen, then in the menu bar, choose Image-->Resize/Resample
IrfanView: Program when opened

IrfanView: Menu bar --> Image --> Resize/Resample

3. Photoshop's Scripts Image Processor:
3.1. Benefits: Quick to being resizing without having to setup anything else.
3.2. Limitations: Only resizes to JPG, PSD, or TIFF files. There was no option to save as PNG, which is what I needed.
3.2. Walkthrough: Menu bar --> File --> Scripts --> Image Processor. Then the window that pops up allows you to choose the folder of images you want to manipulate and where to save them.
Photoshop's Scripts Image Processor

4. Photoshop's Automate Batch: Basically, with this method, you change one image whatever way you want to, then record those steps, then you are able to perform all of those steps for a folder of images.
4.1. Benefits: Very versatile! The recorded actions you create will always be available in the future, and easy to manipulate for future projects.
4.2. Limitations: Just requires a little more setup before starting the batch image process.
4.3. Walkthrough:
Step 1. Open Action Window.
Photoshop: Open Action Window

Step 2. Create New Action. Before you can record some actions, you must have an image open. It doesn't matter if it is just a new blank image, or one you would eventually edit anyways. One other useful feature is the ability to stop and record actions at any time.
Photoshop: Create New Action
Photoshop: Saved New Action. List of available actions.

Step 3. Open Batch Window.
Photoshop: Open Batch Window

Step 4. Setup and Start Batch Command. In the first section (Play), choose the action you would like to perform to all your images that you will choose in the second section (Source). In the third section (Destination), you can either replace all of the images or save the manipulated images in a new folder. After all that, choose the "OK" button located at the top right.
Photoshop: Setup Batch Command

Feel free to post any questions or comments about programmatically resizing many images.
~ Simply Advanced ~



2012-12-21

New Android App: LTE Discovery

Published new Android app, LTE Discovery!

It automates discovery of new LTE coverage for Sprint, AT&T, Verizon. It automatically cycles airplane mode every thirty seconds in order to detect the faster network. If you don't have this app, then your phone will only check once every thirty minutes.

Current features include:
 - Audible notification
 - Record of discovered LTE GPS coordinates
 - Works with the screen off

https://play.google.com/store/apps/details?id=net.simplyadvanced.ltediscovery

~ Simply Advanced ~