python

Python Maths

So I have been doing algebra and I was asked to solve some equations. But I got stuck on two of them. I employed the help of Python to find my answer.

My first problem was  16 - 2x = 19 - 5x. I needed to find x. I had a fair idea that the answer would be x = 1 but I wanted to make sure, so I asked my computer with this script:

>>> x = 0
>>> while True:
...     outa = 16 -2*x
...     outb = 19 -5*x
...     if(outa == outb):
...             print x
...     x += 1
... 
1
^CTraceback (most recent call last):
  File "<stdin>", line 4, in <module>
KeyboardInterrupt

As you can see, I was right, the answer was 1 (or more precisely x = 1).

My second problem was 3(x + 2) = 2(x - 5). Now, I had no idea what this was going to be, so I asked Python yet again with this script:

>>> x = 0
>>> while True:
...     outa = 3*(x+2)
...     outb = 2*(x-5)
...     if(outa == outb):
...             print x
...     x += 1
... 
^CTraceback (most recent call last):
  File "<stdin>", line 2, in <module>
KeyboardInterrupt

Uhh, that didn’t work. The script had been running for about while and still hadn’t told me anything! I tried again, except modified the script to use negative numbers instead of positive numbers:

>>> x = 0
>>> while True:
...     outa = 3*(x+2)
...     outb = 2*(x-5)
...     if(outa == outb):
...             print x
...     x -= 1
... 
-16
^CTraceback (most recent call last):
  File "<stdin>", line 2, in <module>
KeyboardInterrupt

There it is! x = -16.

I had been told Python can be a handy pocket calculator but I didn’t know it could be this handy!

Microsoft Attacking Google With Scroogled Campaign

So, some of you may have seen Microsoft’s video on YouTube attacking Google.

I don’t like Google or Microsoft and persionally I find this whole thing disgusting. In these videos on YouTube (of all services for Microsoft to post and attack video about Google, it was YouTube) Microsoft goes on about how Google spies on your emails, and gives app developers information about horrible things like your age and your home town.

One of the ads are posted below. It portrays Google spying on your mail so it can place an advert around it. It then shows Microsoft (Outlook) doing the polar opposite.

This is pathetic.

Scroogled.com is a page that is obviously owned by Microsoft (It says so in the footer but the tacky metro theme is apparent from the start).

I don’t like Microsoft or Google. I don’t like Google because they do spy on you, even if it is automated. I don’t like Microsoft because I’m sure they do the same.

Microsoft makes money by selling an overly priced operating system that hardly ever works correctly.

Google makes money by giving people a free service they can use but showing people ads. When someone clicks on an ad Google makes money. So obviously Google would want to show the most relevant ads to people. It means people are more likely to click (this makes Google happy), and people are more likely to be interested in something that is targeted for what they are writing about (this makes the people that are paying Google to show their ad happy).

Now, If you are like me and don’t like Microsoft or Google, there is good news!

With these services and programs you can log out of Google and shut down Windows for good. For a search engine Duck Duck Go is completely anonymous (and unaffected by Heartbleed).

I haven’t found a good email service yet, I use my hosting for email.

For an operating system you have many options. Ubuntu is what I use on my computer and I love it. Kubuntu is the same as Ubuntu but using a KDE desktop environment, for people that like the integration of Mac OSX you might like Kubuntu. I myself am actually thinking about using Kubuntu on my laptop. If your computer is not very powerful, would run Windows XP but not 7 then you will want Lubuntu. Lubuntu is a light version of Ubuntu perfect for low power computers. Finally there is Elementary OS, this OS looks similar to Mac OSX. It is simple elegant and does what it should.

All of these systems are Linux, Ubuntu is based of a system called Debian, Debian is based of Linux. Kubuntu, Lubuntu and Elementary are all based off Ubuntu. So they all work similarly.

Its up to you to decide what would work best for you.

Personal note: I was rather angry at my findings about what Microsoft has been up to, but now after remembering Linux and recommending some distributions, all that went away!

Twitter card on your your website

Example of twitter card

Floating head guy’s tweet

You know those little descriptions underneath a tweet that you get sometimes? There is a name for those, they are called Twitter cards! To get a twitter card you must first add the Twitter code to your website or blog.

It’s not quite as easy as that though, you need to send your website to Twitter for approval. You can’t just bung a few Twitter meta tags and expect it to show up on a tweet!

Twitter card code

Here comes the code. Twitter cards use meta tags to get the information, if you go to the Twitter cards dev page, you can set up your card there. You need to sign into Twitter though, and it doesn’t work in Firefox, it works in webkit based browsers like Safari, Chromium, or if you are very desperate Google Chrome.

After selecting a card type, enter your information (not everything is required) into the fields down the side. After entering your information, scroll down to the bottom and click “Update Preview”. Below the preview will be the code you need to paste into your <head> tag.

If you are not interested in adding a Twitter card to WordPress, scroll down to the heading “Verifying your site”.

How add a Twitter card to WordPress

I’m thinking you won’t want to go to the Twitter card web page every time you write a blog, there is a great SEO plugin that has Twitter card functionality! Its the Yoast SEO plugin.

These cards have a “website Twitter account” field and a “author Twitter account” field. The website account is the Twitter account for the website, the author account is the Twitter account of the author. Both accounts get a credit on the card.

To set up the website’s Twitter account, go to the SEO menu on the sidebar of the WordPress backend. Then go to Social. Scroll near the bottom. Make sure the checkbox labelled “” is checked. In the box below it, type the website’s Twitter username (without the @) and click “Save Settings”.

Each author should have their own WordPress login for the blog. In their profile will be two places where they can enter their Twitter username, tell them to enter it into both (again without the @).

The title of the Twitter card will be the title of the post, and the description will be the same as the meta description. The image shown will be the featured image. If you have posts without a featured image, you may want to set a default image in the “SEO -> Social” menu.

Verifying your site

So, now that we have got the Twitter code on our site, we can submit it to Twitter. To do that go back to the Twitter cards dev page and click “Validate and apply”.

There will be a box where you can enter a URL – DO NOT just enter your domain, it must be a page with the Twitter card on it. For example, a blog post. If you enter a URL without a Twitter card on it, the validator will say, no card found here…

After entering your URL and clicking “Go!” you should get a preview of the card (if you are using a webkit browser). Next all you need to do is click “Request Approval”. Twitter will then ask you for some contact, and website information. Fill out the boxes and send off your approval.

It can take Twitter a few days to get back to you, so take a rest. You will be emailed after Twitter look at your website!

I used this method, if you want to test it, tweet this blog post!

Animation in CSS, Animate your website

CSS stands for Cascading Style Sheet, it is a format that tells the web browser how to display the page. In CSS3 you can add transitions and effects to a page with only a little CSS and sometimes JavaScript. Animation in CSS can make your website look more professional, it can also look tacky. Animated CSS means not having to load JQuery on your website for an effect, however It may not be compatible with all browsers (most work though).

Examples of Animation in CSS

If you go to my website often then you will know I like the “fade in with slide down” effect – you should have seen it when you loaded this page. If you didn’t then you may be using an unsupported browser, though some computers aren’t powerful enough to display the effects properly. Here is an Example of a pure CSS div fade in.

If you want the HTML and CSS for the above page, it’s here:

<p>
This example uses pure CSS, and will fade in a div over 20 seconds.
</p>
<style type="text/css">
.fade1{
    animation: fadeani 20s; /* All modern browsers that obey the W3C standerds SHOULD obey this */
    -moz-animation: fadeani 20s; /* Firefox Compat */
    -webkit-animation: fadeani 20s; /* Safari & Chrome Compat */
    -o-animation: fadeani 20s; /* Opera Compat */
}
/* The actual fade */
@keyframes fadeani { /* W3C */
    from {
        opacity:0;
    }
    to {
        opacity:1;

    }
}
@-moz-keyframes fadeani { /* Firefox */
    from {
        opacity:0;
    }
    to {
        opacity:1;

    }
}
@-webkit-keyframes fadeani { /* Safari & Chrome */
    from {
        opacity:0;
    }
    to {
        opacity:1;

    }
}
@-o-keyframes fadeani { /* Opera */
    from {
        opacity:0;
    }
    to {
        opacity:1;

    }
}
</style>
<div id="example1">
<p>
Div content, Div content, Div content, Div content, Div content, Div content, Div content, Div content, Div content, Div content, Div content!!!
</p>
</div>

So that is how you do a fade in on a div.

What else can I do with CSS Animation

If you bring in an element of JavaScript, the world is your oyster! You can make things expand on click and fade on, well whatever you wanted!

You could make an Ubuntu style notification display, by using the following code, but before we get to that, do you want to see an example of that? (For those of you who do not use Ubuntu, you should run you mouse over the black box on the example page)

HTML, CSS and Javascript:

<div id="example1" onmouseover="mover();" onmouseout="mout();">
<p>
Example text goes here,<br/>(I can't afford latin filler text)</p>
</div>
<p>
This example uses CSS and Javascript to make an Ubuntu style notification... Sort of...
</p>
<style type="text/css">
.notify{
	-moz-border-radius: 15px; /* Give it rounded look in older firefoxes */
	border-radius: 15px; /* Give it rounded look in everything except IE */
	float: right; /* Make it sit to the side */
	background-color: #000000; /* Make it black */
	opacity: 0.8; /* Make it slightly transparent */ 

	-moz-transition: all 1s; /* Make any change in javascript fade (older firefox compat)*/
	-webkit-transition: all 1s;  /* Safari & Chrome */
	-ms-transition: all 1s;  /* Internet explorer? */
	-o-transition: all 1s;  /* Opera */
	transition: all 1s; /* W3C (works with newer firefoxes) */

	width: 300px;
}
</style>

<script type="text/javascript">
function mover(){ //Called on mouse over
	var obj = document.getElementById('example1'); //Get our element
	obj.style.opacity = 0.2; //Set opacity to 0.2 (CSS will fade this for us)
}
function mout(){ //Called on mouse out
	var obj = document.getElementById('example1'); //Get element again
	obj.style.opacity = 0.8; //Fade back
}
</script>

(Yes I know, “firefoxes” is not a word, I just thought it would be funny)

So that is an example of using Javascript with CSS. Animation in CSS can be used to give your website, web app, online wizard or anything else you could think of a nice dynamic feel! But it can also be used on events too, so you could make text change color when something is finished.

Animation in CSS is more than just fades

You can do much more with CSS animation than just a mere fade. You can use (almost) every CSS property available, there are some that will not transition though.

Have a tinker and I’m sure you will find a transition that looks great on your website! It does not have to be on page load, (though I like the load effect on my website) it can be on anything you want. Experiment and try different things! Make the web more “fluid” and less “rigid” in feel.

Change blogger’s title template

First, why would I want to change the title template?

Good question, let me answer it with another question. When you search the internet (be it with Google or DuckDuckGo) and see a result, what is the first part of the title you read? The first part of the title of course! So, would you want the name of your blog first or the name of your post first?

If you look at the title of this post (yes I know I’m not using blogger) you will see that I have the post name and then the site name.

Change blogger's title template | PC Thingz

When someone sees that they know from the start that its about “changing blogger’s title template” however if you have it formatted as “Blog Title | Post Title” then it will show as follows:

PC Thingz | Change blogger's title template

Though knowing your blog name is important, the user just wants to find what they are looking for. It may not seem like much, they only have to read two words, but they want to find their content as fast as possible, and it may “help” them click on your post. (Tell me the truth, what one would you rather click?)

Changing the title template

This is the part where I tell you what to do. In your blog overview, click on template.

blogger-dash

Blogger’s blog overview page

Then, there should be a button underneath the live preview on your blog labelled “Edit HTML”. Click that, and find the part that says <title><data:blog.pageTitle/></title>. Delete the entire “<title><data:blog.pageTitle/></title>” out of the code and insert the following code:

<b:if cond='data:blog.pageType == "item"'>
<title><data:blog.pageName/> | <data:blog.title/></title>
<b:else/>
<title><data:blog.pageTitle/></title> </b:if>
code highlight

The part you need to replace is highlighted in blue (Click to enlarge)

What does the code do?

The code you have pasted into the template will find out if the user is viewing a post or the main page. If the user is viewing the main page then it just display the blog title, if the user is viewing a post then it displays the title in the “Post Name | Blog Name” format.
(instead of the default “Blog Name: Post Name” format)

You’re done!

You have now set up blogger to display the title in a more user friendly and search engine friendly way! This won’t bag you millions of views, but people will like the look of your links more!

PS: Your search engine result will not update until the web bots visit your website again.

Progress Bar in PHP

Now, first to clarify, this is not a progress bar like in an application, but a progress bar for a web wizard…

Have you ever found yourself making a wizard in PHP, and making the h2 tag “Step 2/5″? Do you want a way to show the user all the steps, while still letting them know what step they are on? If you said yes to both of those questions then I have another, do you think this looks good?

pbar
Sorry for sounding like an infomercial but, if you like the look of that, what if I told you that you could have this on your own website for free?

This is a PHP script I have made, it shows your progress through a wizard, and even has support for errors. If you would like to see an example, look at the Progress Bar example page, it has a dummy wizard on it, and if you want to test the error stage, don’t accept the “non existent terms and conditions”. Sorry about the bad spelling on the example, I have not checked it as I was in a rush when I made it…

 

So, how do I use this in my PHP script?

First you need to include "progress-lib.php"
Then, when you get to the place where you want to add the bar, invoke progress_start(); without any args, then run add_item(str name, bool current, bool error); as many times as needed,

The add_item function takes three args, the name of the step, if that step is the current step, and if that step has an error. So you will need to run this function for each step.

When you are done adding all the steps, you must close the bar by invoking progress_finish(); without any args. You have now successfully made a progress bar.

 

What may I use this for oh mighty one?

Well, I’m glad you asked! You may use this script for commercial or non-commercial use, as long as the credit in “progress-lib.php” is not edited, modified, or removed.

 

So, where can I download it?

You can download the main script with an example script included here. If you would like to share what you are using this for, then please, feel free to comment on this post!

I’m now using WordPress

So you may have noticed that I am no longer using Blogger, well about 14 hours after this tweet,Screenshot from 2013-03-09 18:04:23 I moved to WordPress.

So I am now moving away from Google, I have stopped using Google for web search (I use DuckDuckGo now) and E-Mail (I host it on this domain), there is no way of replacing YouTube so I’ll have to keep the account but its a start. I myself don’t like Google, however that is not saying that its a bad service, its a great service! But I believe in complete privacy, and I feel I should be able to give governments my information if requested, and I would as I have nothing to hide but I don’t like the whole idea of Google doing everything, as stated here. This is all my opinion, and it is just how I feel.

Cheap HD video clips at E-Star TV

Intro

Have you ever found yourself needing a video clip of something beautiful, but searched and searched the Internet for something cheap to no avail?
Good News
Well the good news is that there is a little known business  called E-Star TV, their website is estar.co. As well as selling cheap (from $5 NZD) and sometimes even free video clips at 720p and 1080p, they also have a sound gallery, where you can download an MP3 or WAV version 
of the sound free of charge. They also have a picture gallery where you can download free photos.
If you would like to see a list of all of E-Star TV’s galleries, take a look at this, E-Star TV Galleries.
When you buy a clip from E-Star TV you only pay once, and you can use it in anything, without paying any royalties. Plus all their content so far is from New Zealand!
So take a look at the video shop with great prices at E-Star TV.

Auto mount drive (or partition) at startup in Ubuntu

Intro

Do you have a hard drive that you want to be mounted at startup?
I did too, and I got it working, thanks to these steps


What happened

I have two hard drive’s in my computer, one is an older 40GB hd (my system disk) and another is a newer 160GB hd. The older one is slow so I decided to format my computer and reinstall Ubuntu. When I was installing Ubuntu I made the entire 40GB hard drive swap space (its an old drive, and I don’t know how long it has to live) but when I finally booted into Ubuntu, it wasn’t mounted, I had to do it manually, and I don’t want to have to do that every time I turn on my computer


Steps
“Device” value highlighted
  1. Open Terminal (CTRL + ALT + T).
  2. Type sudo mkdir /media/disk and press enter.
  3. If you have more than one disks that you want to have mounted at startup run this again except with a different name
    IE.
    sudo mkdir /media/disk1 thensudo mkdir /media/disk2 etc.
  4. Open “Disks” and select the drive you want to auto mount.
  5. Click on the partition (if any) you want to auto mount.
  6. Find the value “Device” (my one was /dev/sdb2).
  7. Go back to terminal.
  8. Type  gksudo gedit /etc/fstab and wait for a text editor to come up.
  9. In the text editor press CTRL + END to go to the end of the document.
  10. Press enter 4 or 5 times.
  11. Type the “Device” value you got before from the “Disks” window (my one was /dev/sdb2).
  12. Press tab, and type the folder path we made for the device before (/media/disk).
  13. Press tab and type “defaults”.
  14. Press tab and type “0″, then press tab again and type (again) “0″.
  15. Save the file and close the text editor.
  16. Restart your computer.
  17. Open “Disks” and click your hard drive, then click the partition we are auto mounting.
  18. Click on the button with the cogs (the one below the partition part, not the one at the top of the window) and click “Edit Mount Options”.
  19. Give the device a display name (I called my one “Swap Space”).
  20. Press OK.
  21. Restart your computer then open “Disks” again, click your hard drive and partition, there should be a stop button below the partition part. You are now done and the partition will be mounted every time you start your computer. (if you see a play icon, something went wrong).

Now I can enjoy a faster computer!

Listen 2.0

It has been a long time in the making but Listen 2.0 (written in python) is finally here! The people at Mono are doing a very good job however I just couldn’t get it to work for me, so I rewrote it in python. You may have been expecting a listen 1.1 or 1.04 etc. But I want to get as far away as possible from the first release of Listen. I have uploaded the update to the fabulous guys at the Ubuntu software center. You can download the app now!

How Do I Use It?
The UI is very easy to understand, what you do is you select a device from the device dropdown and check the listen check box, when you close the application all devices will stop playing through the speakers
 

Sorry for the problems with 1.0! But to try and make up for it, here is a sneak peek at the new UI!

Listen 2.0 (Actual Size)

Much nicer than the old UI!

Listen 1.0 (Image Scaled)

Thanks for all your support!