by Jonny | Apr 2, 2013 | Updates
I haven’t really bought anything nice lately and that’s due to me, well, not having much money… actually, more than anything I don’t want to cut into my savings until I can find a job when I go back to the UK.
I bought a nice pair of shoes as my old shoes weren’t in the best condition. My old pair had really worn down. First of all there’s a hole located on the front of my left side shoe. Secondly, on both of the inner-heels of my shoes the material has worn away, which means that every time I walk, the back part of my foot keeps rubbing against the plastic-type material where padding and material should be. – It causes minor discomfort and to get around this issue I simply lodged a sock in the round-hole type shape that has formed. It gets tiresome doing that everyday, so a new pair of shoes were in order and now I’m good.
However, I have realised that I can only do that for so long, and if I’m going to buy a pair of new shoes, I might as well buy it in Taiwan considering it’s more expensive in the UK to buy nice shoes. I think if I had bought shoes like this in the UK, it would have cost £85 or more. In Taiwan the pair of shoes I bought only cost me £35, which is a massive saving.
Here are the pics:
I also bought a new Logitech camera and I used that camera to take the pictures with; aside from the webcam itself, I used my phone. It’s pretty good and I’ve tested the quality of it over the internet and its pretty damn good. It sure beats the webcam that is integrated on my laptop, which is a 1 megapixel (Not sure on the video recording resolution, and I’m too lazy to look it up) camera in comparison to my new 720p camera that can take shots at 5 megapixels! 🙂 – I, for some reason, didn’t change the settings to take 5MP pictures, so the pictures I’ve uploaded aren’t of the highest quality.
by Jonny | Apr 1, 2013 | Updates
I’ve changed the design, yet again, as I wasn’t happy with the previous design.
The real reason I changed designs was due to the bad SEO that the other design had and it seemed that it was over-bloated more than anything without giving any real reward in terms of search engine optimization. It’s definitely a nice design and everything, but the SEO aspect fails in that regard. The new design on the other hand has many more options to feature articles that are hidden from the front-page, thus any hidden articles are also shown on the front-page and receive more attention thus will rank higher in search engine results.
Photography website update
I have also updated my photography website; although, that still need working on. I’m almost finished in completing it, but I’m quite sad with the result that I’m getting as the theme I am using wasn’t not built with photography in-mind. It’s hard to say, but the previous design that I was using is specifically for photography-type websites. Unfortunately, this web design is not. I’m pondering on whether to switch back or not. I think I’ll be able to tweak it and work with it to make things work! Either way, please visit this part of the site! – I’ve tried my best to make it look similar to my blog.
Jonathan Jones is an avid blogger, and a friendly guy! He also likes to type in third person because it makes it seem like there is more than one person running this site, thus concluding that he would in the future like to be a businessman.
by Jonny | Mar 16, 2013 | Updates
From yesterday to now I’ve been spending time on a new look for my blog. I think I’ve done a decent job and I like the new look and theme that is designed by a group called Elegant Themes. (I use their themes for all of my blogs as they look superb)
This is 2013 now and this place needs more organisation and a better look. Which is why I’ve also introduced two new categories and they are: Travel & Programming. I have also introduced a coding resources page with resources to where I’ve linked to other sites where you can learn how to code in various programming languages, which is what I’ve been doing recently.
Slowness
I realise that the site is slow and I’ll be honest by saying I have no idea why.
It’s nothing to do with the theme as the previous theme I was using was also having similar issues where the page would load only half-way and you could literally just the logo and maybe some content. I’m unsure as to whether that is my web host or because of something else. However, this blog is on a shared environment along with my other blogs and possibly with a load of other customers on the same server. But the thing to note is that on my other blogs I have not encountered this issues where everything is loading slowly.
It is definitely a buzz-kill as I don’t want to browse my blog anymore. I’ve optimized the MySQL database, deleted a tonne of spam comments and I have also disabled all plugins to no effect.
Hopefully I can sort out this slow loading issue.
by Jonny | Mar 14, 2013 | Updates
I’ve now moved onto exercise 19.
def cheese_and_crackers(cheese_count, boxes_of_crackers):
print "You have %d cheeses!" % cheese_count
print "You have %d boxes of crackers!" % boxes_of_crackers
print "Man that's enough for a party!"
print "Get a blanket. \n"
print "We can just give the function numbers directly:"
cheese_and_crackers(20, 30)
print "OR, we can use variables from our script:"
amount_of_cheese = 10
amount_of_crackers = 50
cheese_and_crackers(amount_of_cheese, amount_of_crackers)
print "We can even do math inside too:"
cheese_and_crackers(10 + 20, 5 + 6)
print "And we can combine the two, variables and math:"
cheese_and_crackers(amount_of_cheese + 100, amount_of_crackers + 1000)
Explaining each line
Line 1
On line 1 we have the start of the mini-script (“def”) and then we have cheese_and_crackers which is the function that will be used throughout the rest of the script. For this first function/mini-script we have “cheese_count” and “boxes_of_crackers”) inside the parenthesis. We’ll use these on lines 2 and 3.
Lines 2 – 8
On line 2 we have %d that uses “% cheese_count” and that “name” is on line 1; the same goes with line 2. The other lines are too basic to explain, so I’m just going to skip to line 8, which is where the data is pulled when executing/running the file, so that line 8 “cheese_and_crackers(20, 30)” with the numbers corresponding and displaying when the file is executed.
Lines 10 – 14
The more direct way of imputing numbers is using variables and in this case we declare the numbers after creating a variable name then after the equation mark we enter the value (Lines 11 – 12). So we can re-use the function data from “cheese_and_crackers” we use it when calling for the variables so it re-uses the data in lines 1 – 3; however, uses the values within the variables and not the values in line 8.
After explaining all those lines, the rest of the lines make sense now and I feel I have a clear grasp of it now.
Output in Windows Powershell:
We can just give the function numbers directly:
You have 20 cheeses!
You have 30 boxes of crackers!
Man that's enough for a party!
Get a blanket.
OR, we can use variables from our script:
You have 10 cheeses!
You have 50 boxes of crackers!
Man that's enough for a party!
Get a blanket.
We can even do math inside too:
You have 30 cheeses!
You have 11 boxes of crackers!
Man that's enough for a party!
Get a blanket.
And we can combine the two, variables and math:
You have 110 cheeses!
You have 1050 boxes of crackers!
Man that's enough for a party!
Get a blanket.
Next step
So, after learning and studying this, I moved onto the next step. The next step was creating something of my own and seeing if it would work. Since I like the raw_input() function, as you can add user input functionality, I tried and succeeded in adapting raw_input() with a def function.
Here’s what I got:
def hello_world(name, country, favcountry, favgame, languages):
print "\n"
print "This is how you responded to those questions:\n"
print "Your first name is: %r" % (name)
print "Your country of origin is: %r" % (country)
print "Your favourite country is: %r" % (favcountry)
print "Your favourite game is: %r" % (favgame)
print "You said you can speak these languages: %r" % (languages)
print "That's all! \n"
print "Please answer the following questions."
hello_world(raw_input("First name: "),
raw_input("Your country of origin: "),
raw_input("What's favourite country?: "),
raw_input("What's favourite game?: "),
raw_input("What languages can you speak? (Separate with a comma): ")
)
It works and it isn’t too shabby. However, according to this exercise I have to use 10 other functions in the same file to show that I really know how to use this newly learnt method and probably to practice other functions other than those I’ve been using for a long time! I’ve only used one type of function which is raw_input(); however, I’m a little tired of this exercise so I’m going to move onto exercise 20 and I’ll return to this exercise, if need be it!
by Jonny | Mar 14, 2013 | Updates
I found this exercise to be quite comforting; however, at first I was a little confused when presented with all that new code that I had never seen before. In this exercise it teaches you about the “def” (Define) and creating functions (Mini-scripts).
To overcome my confusion, I typed the whole thing out and ran it in Windows Powershell. Then for extra practice I created another file and typed each function one by one and changed those functions to get an idea on what each and every thing does.
Here’s my code:
# FUNCTION 1
def print_two(*args):
arg1, arg2, arg3 = args
print "arg1: %r, arg2: %r, arg3: %r" % (arg1, arg2, arg3)
print_two("Hello","Mr","Python")
# FUNCTION 2
def print_two_again(arg1, arg2):
print "arg1: %r, arg2: %r" % (arg1, arg2)
print_two_again("Hello2","World!")
# FUNCTION 3
def print_none():
print "Nothing here."
print_none()
I only modified it slightly, for testing purposes, and then tested each and everyone of them. It’s quite fascinating how it works and it has got me more interested in learning as it’s a really simple way of explaining these various different methods of displaying data in Python.
Instead of using argv or variables to display strings, you can simply create functions which, I guess, organises the code; I suspect.
by Jonny | Mar 14, 2013 | Updates
I’m currently working/studying exercise 17 from Learn Python the Hard Way. In this exercise I learned two new things, and those two reasons are why I created this new category which will cater for my programming experiences, as opposed to me creating hundreds of pages and having my navigation bar up-top filled with drop down menus on the “code” navigation link.
As for my programming abilities so far, I’ve been typing out every single piece of code in this eBook by hand (As requested by the author) with no copy and pasting whatsoever! I’m quite proud of that actually.
Anyways, in the exercise it states that I need to condense the following code:
from sys import argv
from os.path import exists
script, from_file, to_file = argv
print "Copying from %s to %s" % (from_file, to_file)
# we could do these two on one line too, how?
in_file = open(from_file)
indata = in_file.read()
print "The input file is %d bytes long" % len(indata)
print "Does the output file exist? %r" % exists(to_file)
print "Ready, hit RETURN to continue, CTRL-C to abort."
raw_input()
out_file = open(to_file, 'w')
out_file.write(indata)
print "Alright, all done."
out_file.close()
To this:
from sys import argv; from os.path import exists; script, from_file, to_file = argv; print "Copying from %s to %s" % (from_file, to_file); in_file = open(from_file).read(); print "The input file is %d bytes long" % len(in_file); print "Does the output file exist? %r" % exists(to_file); print "Ready, hit RETURN to continue, CTRL-C to abort."; raw_input(); out_file = open(to_file, 'w').write(in_file); print "Alright, all done."
# we could do these two on one line too, how?
# indata = in_file.read()
# out_file.write(in_file)
# out_file.close()
# in_file.close()
As you can see I condensed the code to just one line with semi-colons, and I hashed out the code that wasn’t needed for the operation that the code is to do. It still works and copies from one file to the other.
I got rid of close() as I’m still not sure yet what purpose that serves in relation to this, though I’m assuming I can just add this to the end; though it’s throwing up errors. I’m just looking to progress onward and if I run into an issue like that I’ll have a sit down and think about solving it or asking on websites designed for these types of issues.
I also combined from the original code in line 18 and 19 to this:
out_file = open(to_file, ‘w’).write(in_file)
Not sure if that is correct; however, the script is still functioning and does its’ job.
I’m sure if an expert Python programmer came and saw this they would faint, but I’m still trying to learn and I know I have a long road ahead of me.
New Parameters & Formatters
import exists – This will confirm whether a file exists or not. If a file exists it will report back with True, if the file doesn’t exist it will report back with False. In Windows Powershell, it outputs the following:
Does the out-put file exist? True
len() – (length) This will measure the length of a file. In the above example the output in Windows Powershell is:
The input file is 686 bytes long