Skip to content

What is Version Management and why do you need it?

Before version management, people had to create backups for their source code. But that in itself presents a couple of problems:

1. Disk space. Your mileage may vary, but the bigger the system, the larger the code base.
2. Maintenance. It’s a nightmare when you want to revert to a certain state of a system with some new features intact. It’s like a brand new coding exercise again.
3. Working in a team takes longer. Why? People have to get the code manually that’s done by others, say in a shared folder. Heck, some even rely on external storage devices just to get the latest code from their teammate.
4. Organizational nightmare. Hey, do you remember what you did in this class here and in this webpage over there? Yeah, sure, you can do a list of everything you did, but let’s see you keep that up for multiple changes.

Thank the programming gods then that version management was created!

Nah, I’m ending this post here. I have to dive in first to SVN and Git(maybe some more version management tools too) before I can write something more substantial. There. :)

Hello World in Java with Threads

I’ll be starting my self study with threads, but here’s something I did without any knowledge of threading: Hello world in Java using Threads! It’s like magic, but real! Or not. At least it’s digital. :)

public class HelloThread {
	public static void main(String[] args) throws InterruptedException {
			long time = 1000;
			Thread.sleep(time);
			System.out.println("Hello world!");
			Thread.sleep(time);
			System.out.println("The world is an apple!");
			Thread.sleep(time);
			System.out.println("That is connected by a thread!");
			for(int x = 0; x < 3; x++){
				Thread.sleep(time);
				System.out.println(".");
			}
			Thread.sleep(time);
			System.out.println("That is all! :)");
			
	}
}

Hello World in Javascript

<html>
<head>
<script language ='javascript'>
alert("Hello world!");
</script>
</head>
<body>
</body>
</html>

Yeah… it’s one of those days.

Simple Anagrams in Python

What are anagrams?

From Wikipedia:

An anagram is a type of word play, the result of rearranging the letters of a word or phrase to produce a new word or phrase, using all the original letters exactly once; for example orchestra can be rearranged into carthorse.

So I made a simple implementation in Python based on this blog post’s requirements:

The challenge is fairly simple: given a file containing one word per line, print out all the combinations of words that are anagrams; each line in the output contains all the words from the input that are anagrams of each other. For example, your program might include in its output:

  kinship pinkish
  enlist inlets listen silent
  boaster boaters borates
  fresher refresh
  sinks skins
  knits stink
  rots sort

Sadly, I couldn’t access his word list so I’m using the words from this site.

Here’s the code:

f = open('listOfAnagrams.txt','r')
l = [line.replace('\n','') for line in f.readlines()]
anagrams = []
anagram = ''
startTime = clock()
for x in l:
		if x not in anagrams:
			for y in l:
				if y not in anagrams and x != y:
					if ''.join(sorted(x)) == ''.join(sorted(y)):
						if x not in anagrams:
							anagrams.append(x)
                        anagrams.append(y)
                        if len(anagram.split(' ')) > 1:
                            anagram = anagram + ' ' + y
                        else:
                            anagram = x + ' ' +  y
            if len(anagram.split(' ')) > 1:
                    print anagram
            anagram = ''
    f.close()

Output:

acer acre care
acers acres cares carse escar serac
aces aesc case ceas
aches chase
acme came
acned caned dance
act cat
acts cast cats

Sadly, it isn’t optimized to my liking. For 1500 something words it runs for 5 seconds. That would probably be remedied once I graduate from noob level. There. :)

FizzBuzz in Java

public class FizzBuzz {
	public static void main(String[] args) {
		for(int x = 1; x < 101; x++){
			if( x%3==0 || x%5==0){
				if( x%3==0){
					System.out.print("FIZZ");
				}
				if( x%5==0) {
					System.out.print("BUZZ");
				}
			} else {
				System.out.print(x);
			}
			System.out.println();
		}
	}

Yep. I’m running out of stuff to write about. :)

Regarding FizzBuzz, here are two interesting articles about it:

Using FizzBuzz to Find Developers who Grok Coding

Why Can’t Programmers.. Program?

Got those stuff from the Wikipedia article about FizzBuzz.

I just learned FizzBuzz is actually BizzBuzz. Oh well.

 

Checking if Input is a Number in Python

Here are four easy ways to check if something is a number in Python:

Catching an exception:

def checkIfNumber(input):
    try:
            int(input)
            return True
    except ValueError:
            return False

>>> inputValid == False:
>>> while inputValid == False:
...     inputValid = checkIfNumber(input("Enter a number!"))
...
Enter a number!'a'
Enter a number!'ca'
Enter a number!'apple'
Enter a number!'number'
Enter a number!1
#thing terminates

Checking for the type:

>>> inputN = ""
>>> while type(inputN) != int:
...     inputN = input("Hey, gimme a number!")
...
Hey, gimme a number!'asd'
Hey, gimme a number!'dsa'
Hey, gimme a number!'one'
Hey, gimme a number!'uno'
Hey, gimme a number!1
>>> inputN
1

Checking if the input multiplied by zero equals to zero.(Python allows multiplying stuff to 0, with different results based on the type you’re multiplying with, without throwing an exception):

>>> inputN = ""
>>> while 0 * inputN != 0:
...     inputN = input("Come on! Number!")
...
Come on! Number!'zero'
Come on! Number!'one'
Come on! Number!'two'
Come on! Number!1234
>>> inputN
1234

Last one is checking by the String function isdigit. To use this, your inputs should be type String:

>>> inputN = ""
>>> while inputN.isdigit() == False:
...     inputN = str(input("NUMBER!!"))
...
NUMBER!!'uno'
NUMBER!!'dos'
NUMBER!!'tres'
#We enter a number without quotes
NUMBER!!1234
>>> inputN
1234

#Another run
NUMBER!!'cinco'
NUMBER!!'9876'
>>> inputN
9876

Know another way to do it? Let me know. :)

Hello World in Java

Looks like I haven’t done this yet, and I’ve done one on Python. So here goes!

public class HelloWorld{
	public static void main(String[] args){
		System.out.println("Hello World! I'm Java!");
	}
}

:)

Follow

Get every new post delivered to your Inbox.

Join 185 other followers