Archive

Archive for the ‘Miscellaneous’ Category

Early-outs for n00bs

November 26th, 2011 No comments

Sometimes I see people code something up like the following:

void AwesomeFunc( void )
{
    if( var == 3 )
    {
        if( var2 == 4 )
        {
            if( var4 == "napkin" )
            {
                if( var5 == 8495 )
                {
                    g_flag = true;
                }
                else
                {
                    Debug.Log( "var5 wasn't 8495" );
                }
            }
            else
            {
                Debug.Log( "var4 was not napkin" );
            }
        }
        else
        {
            Debug.Log( "var2 wasn't 4" );
        }
    }
    else
    {
        Debug.Log( "var wasn't 3" );
    }
}

Read more…

Categories: Blog, Tips 'n Tricks Tags: ,

Const qualifier reminder

November 7th, 2011 No comments

Just a reminder how const-ness works. If I remember correctly.

// These two lines are the same type
// const and int can be switched around and the result is the same.
const int i;
int const j;

// If the word "const" follows the "*", it affects the pointer
int* const k;

// Both the pointer and the int are const
const int* const m;

// Same as line above, it just looks weird
int const * const n;

// Does the const affect the pointer or the int? The int..
int const * p;
Categories: Blog, Miscellaneous, Tips 'n Tricks Tags: ,

Spiced Apple Smoothie

August 28th, 2011 No comments

2 apples peeled & chopped
2 banannas
2 cups of ice
3/4 cup apple juice
6 oz. of vanilla yogurt
3 tbsp brown sugar
1-2 tsp of cinnamon
Blend all together in blender
For garnish, add whipped cream, cinnamon, & an apple slice.

Categories: Blog, Food Recipes Tags: ,

Math trickery for 1D & 2D arrays

August 14th, 2011 No comments

Once upon a time, there was a language that didn’t have 2 dimensional arrays. This greatly upset the programmer. Fortunately, the programmer was swift in the art of arithmetic and overcame this obstacle easily.

Lets say for example, we only have access to a 1 dimensional array data structure and it has 50 elements in it.

int data[50];

Lets break this array up into 10 rows and 5 columns to make a grid. So how do we get access to a position say data[4][3]?
There are two things I’m going to teach you now:
1) Retrieve the column & row numbers from a linear index counter.
2) Retrieve the index from a row & column numbers.

Read more…

Categories: Articles, Blog, Miscellaneous Tags: , ,

Quick vim tip

July 6th, 2011 No comments

I’ve always used the “w” key to go forward a word when highlighting stuff. There’s a problem with this though when you want to just copy a single word.

Lets say you have the sentence “you are a car.” Let’s also assume you have placed your cursor on the letter “a” in “are.”

And we want to highlight the word “are.” So we press “vw”. When you press the letter “w”, it highlights the following: “are a”. Note that it includes a space and the letter a.

So the letter “w” is the wrong key to use, so what is the key to go to the end of the word instead?

It’s the letter: e

Categories: Blog, Tips 'n Tricks Tags:

Books I’ve read in 2011

July 6th, 2011 No comments

1) 4/5 Who wants to be a millionaire? (978-1883589875)

This book was a pretty good book for what it is. It’s a very small book, so you really can’t expect much. It’s catered towards teenagers in school and you can read it in about a day. The contents are about how to save up for retirement, basically. If you do it soon enough, and correctly, you can have about a million dollars or more. The critical ideas are: mutual funds, 401Ks, roth IRAs, and insurance.  I recommend it if you don’t know anything about finances or about where to put your money. Even if you don’t have any money, you can still save up, but the key is to do it early enough (when you’re young).

2) 3/5 The Complete Idiot’s Guide to String Theory (978-1592577026)

Amazingly, there aren’t any equations. There are good and bad parts and I get lots quite often. Mainly when he says “The blank-blank theory says this”… But doesn’t leave any references to say why, because I don’t know where he gets quite a few of his statements. The author is probably correct, because I don’t know any better. On a good note, the appendix has a wealth of really good links and info if you want more info. Overall, so far, it’s ok. But there’s got to be a book that explains it better. It does make some things clearer though, but I guess it’s just piecing things together piece by piece, but you will probably need other resources to complete the picture. This book just feels like a bunch of random physics statements thrown together.

3) IN PROGRESS 5/5 The Holy Bible

I won’t be reading all of it, but I will be reading all of the main narrative books that go through the main story. So far, the story is very unique and inspiring. You can’t really attempt to understand it by yourself unless you’re a history buff and know what was going on in the time period. Also knowing which books were written in which time period is very helpful as well. Who was in world power, where the old nations were located, etc. I have quite a few resources and help to figure things out, so if a regular person picked up the bible and started reading it, they’d most likely miss a good portion of the important things that require an understanding of real history. This will always be “in progress.”

 

Categories: Blog, Books I've read, Miscellaneous Tags:

Vim tip 34534

May 23rd, 2011 No comments

I’ve been looking for a way to delete up to a character, but not including the character from within vim, and I finally figured out how to do it.
Lets say you have something like this:

big_huge_array_with_a_big_long_name[ indexThingy ] = 5;

If the cursor is at the beginning of the line, and we want to change the name of the array completely, we could type this:

df[

This will delete all the way to the bracket. Unfortunately, it deletes the bracket.
So instead, this works nicely to NOT remove the character you type:

dt[

This will delete every character up until the bracket, but leave the bracket. How nice.
So what does this “t” movement key do exactly?
It simply moves the cursor to the character right before the one specified, and it stays in “normal” mode.
If you wanted to immediately type after deleting the characters, you would use the following:

ct[

Which will delete the text, leave the “[” character, but change to insert mode right before the “[” character.

Another thing you can do is type:

de

Categories: Blog, Vim Related Tags:

Monthly vim tips

May 17th, 2011 No comments

If you want to search for the word right where your cursor is, you can do the following:

/Ctrl-r Ctrl-w

If you want to maximize your vertical or horizontal buffer splits, type one of the following:

Ctrl-w|
Ctrl-w_

If you want to equally resize all of your buffers, type the following:

Ctrl-w=

To make a vertical split a horizontal one, or visa versa, type the following:

Ctrl-w H
Ctrl-w K

To center the cursor on your screen, press:

zz

To bring up the build in “file explorer” window, type one of the following:

:E
:Ex
:n .
Categories: Blog, Vim Related Tags:

What is the difference between aggregation and composition?

May 5th, 2011 No comments

This question has bothered me for some time and I always forget. So I wrote it down here and added an answer.

Composition : An object contains another object. When the container object dies, so does the composited objects.

Aggregation : An object pseudo-contains another object (contains a pointer to it). When the container object dies, the containees do not.

class Container
{
public:
    // Composition
    Containee _c[5];

    // Aggregation
    Containee* _pc[5];
}

Sometimes aggregation is called composition when the difference doesn’t matter.
Note: In UML, aggregation is an unfilled diamond, whereas composition is a filled diamond.

References:
http://en.wikipedia.org/wiki/Object_composition#Aggregation

Resizing your vim buffer

April 28th, 2011 No comments

To resize your buffer up and down type the following:

<ctrl-w>- (that's minus)
<ctrl-w>+

To resize your buffer left and right, type the following:

<ctrl-w>< (that's a less than aligator symbol ;p )
<ctrl-w>>

You could make a mapping to do these without pressing the ctrl-w key combo first.
Something like this for the vertical stuff:

map + <c-w>+
map - <c-w>-

You have to put that in your .vimrc file.

Categories: Blog, Vim Related Tags:

How to quickly comment out entire sections of code

April 28th, 2011 No comments

Go to the first line and type the following:

^ to go to the beginning line. (probably want the top too)
Ctrl + Alt + V (to enter block highlight mode)
#j (where # is the number of lines to be commented out) Or just move the cursor manually.
I (capital i)
//
Press the esc key.
They should all be commented out now, with c++ style comments.

Categories: Blog, Vim Related Tags:

Remove trailing whitespace

April 28th, 2011 No comments

Last blog post, I mentioned you could clean up and reformat a file by using :retab.
This doesn’t remove unnecessary trailing whitespace though. To remove trailing whitespace, use the following:

:%s/\s\+$//
Categories: Blog, Vim Related Tags: ,

Quickly convert all tabs to spaces

April 26th, 2011 No comments

Make sure, in your .gvimrc file, that the following are set to your liking:

set tabstop=4
set shiftwidth=4
set softtabstop=4
set expandtab

Then type the following within vim:

:set expandtab
:retab
Categories: Blog, Vim Related Tags: , ,

A few more vim tips

April 13th, 2011 No comments

retrieves a yanked/deleted entry before the last yanked/deleted entry

"0p - used to paste after yanking
"1p - used to paste after deleting
"2p - used to paste after deleting (2nd from last)

Ex: yank/delete something, then yank/delete something else. Then type “0p or “1p

Count the number of words in the file of <word>

:%s/<word>//gn
[I (capital i) - Shows the lines containing the word under the cursor
ga - displays the ascii, hex, and octal value of the character under the cursor
g<CTRL-G> - to see technical info about the file you are in
CTRL-i & Ctrl-o : trace movements forward & backwards in the file
Categories: Vim Related Tags:

Changing text between brackets, parens, etc. quickly

March 24th, 2011 No comments

Vim tip: Move your cursor between any of set the following: (), “”, [], {}, etc.

Then type one of the following:  

yi(
di)
ci[

Or any combination. it will remove or change or yank all of the text between those braces.

Categories: Blog, Vim Related Tags: ,

How to reload your .gvimrc file without quitting gVim

March 16th, 2011 No comments

At work I modify my .gvimrc file, and it’s a big hassle to have to quit mvim (mac) and reload it. So a neat command you can do is to type this:

:source <path to .gvimrc>

This will reload your .gvimrc file without leaving gvim.
This should work with regular vim too.

Categories: Blog, Vim Related Tags: ,

Don’t get left behind

February 28th, 2011 No comments

Do you want to know what the latest trends are in game development? Do you have a fear of being left behind in the game dev industry because you don’t know what such n’ such a technique is? Is there something you can do to make sure you’re not left behind in the dust?  There is!

In this post, I’m mainly concerned with physics and graphics, but the same sort of techniques apply to other fields as well. The following items are what I do regularly to keep up to date in my field:

Read more…

Things you can do to make your code better

January 6th, 2011 No comments

I got most of this list from some other place on the internet, but I felt there could be more added to it.
I’ll continue to add to this list as I think of things or come across things.

  1. Test Driven Development Really Is Worth It
  2. Don’t Rely On Comments Too Much: Make Your Code Self-Explanatory
  3. Don’t Let Exceptions Disappear Into A Black Hole
  4. Don’t reinvent the wheel. Use libraries when possible because you know they work.
  5. Code like you will reuse the code for other projects.
  6. Learn what good design should look like an emulate it until you see why it is good design (and what you dislike about it).
  7. Too many newbies like to over-engineer just to pretend to be smart or having fun with resume-driven-development. In other words, implementing every pattern in the book or putting bayesian filters in every corner of the code should be avoided if they aren’t needed. Debugging, testing, maintenance will be all easier, not mentioning performance.
  8. Have your code reviewed often.
  9. Be wary of code smells (Class too big, method too big, method with too many arguments, Ask don’t Tell etc).
  10. Enforce standards by using checkstyle / PMD, cobertura / emma, findbugs, etc within maven build cycle to make sure code in repository is adhering to a certain quality standard.
  11. Make sure it meets the quality standard for the project.
  12. Just keep it simple. Functions should be short and sweet, and do just one thing. They should fit on one or two screenfuls of text (the ISO/ANSI screen size is 80×24, as we all know), and do one thing and do that well.
  13. Test, test, test.
  14. You will see how many times you will have to tradeoff between design and schedule. Forgive yourself but remember to refactor whenever possible.
  15. Use Standard Annotation Language (SAL) if you are using C or C++, to prevent bugs and make your code robust. It is found in the book “Writing Secure Code for Windows Vista.”
  16. Code with contracts (partially enforced with SAL).
  1. Avoid global mutable state, such as static variables and static singletons.
http://misko.hevery.com/2008/11/11/clean-code-talks-dependency-injection/
http://misko.hevery.com/2008/11/21/clean-code-talks-global-state-and-singletons/
  1. Make your methods small and well named.
http://c2.com/ppr/wiki/WikiPagesAboutRefactoring/ComposedMethod.html
http://tottinge.blogsome.com/meaningfulnames/
  1. Simple Design
http://jamesshore.com/Agile-Book/simple_design.html
  1. Adhere to SOLID Principles
http://en.wikipedia.org/wiki/Solid_(object-oriented_design)
http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod

Simple coding tips 01

November 24th, 2010 No comments

Simple tip: Naming functions

Examples:
GetName()
SetName()
DoAreaTransition()
CreateBird()
DestroyBird()

Note how each function name begins with a verb and usually, each function ends with a noun. Naming your functions this way helps you think more clearly about what you’re doing and helps other people understand your code more thoroughly.

Categories: Blog, Tips 'n Tricks Tags: ,

Two dropbox instances for one Win7 user

November 7th, 2010 No comments

I’m always afraid of websites randomly disappearing, especially when they have useful information on them. I happened to stumble across a website that explains how to set up multiple dropbox instances on a windows 7 or vista machine. I’m going to briefly just copy that info here for my own reference ( and yours :-) )

  1. Setup dropbox like normal with an account.
  2. Create a second user on your windows machine with a password.
  3. Login as that second user.
  4. Install dropbox again for that user and set it to synchronize a folder that both windows accounts can access.
  5. Log back into the original windows account.
  6. Find the dropbox.exe in the other user’s folder that you just created: c:\users\<username>appdata\roaming\dropbox\bin\dropbox.exe
  7. Make a shortcut to that .exe file somewhere.
  8. In the shortcut’s properties, change the “Target” field to something like this: runas /user:<username> /savecred C:\Users\<username>\AppData\Roaming\D ropbox\bin\Dropbox.exe
  9. Double click the shortcut, type in the password, and it should be working.
Categories: Blog, Tips 'n Tricks Tags: , ,