Hands off that Mouse!

Four keyboard shortcuts you shouldn’t be without (and one Evernote really should implement…)

Want to know the easiest way to improve your productivity?

Stop using the mouse.

Watch an IT professional and you’ll see that their hands never leave the keyboard. They know that it takes a couple of seconds to move your hand from the keyboard to the mouse, and then to move the mouse to the right position on the screen and click. They know that the bigger the screen, the further the you have to move the mouse and the longer it takes to click. 

Learning just a few simple keyboard shortcuts can really speed things up. Here are three shortcuts you can use with Evernote and one that works everywhere.

1: Tab Switch between Applications

The first shortcut is nothing to do with Evernote; it’s something built into Macs, Windows and most Linux desktops 

Just suppose you’re surfing the web with your favourite browser (Safari, Chrome, Firefox, Edge) and you want to switch to Evernote to check something. 

Don’t reach for the mouse. Hold the Alt key on Windows or the Command (⌘)   key on Apple and then press the tab key. 

As you press tab you’ll see your current open apps appear on the screen.

Repeatedly press tab until you have selected the app you want to switch to, and then let go.

Tab switching is clever. The apps rearrange themselves every time you tab switch so that the app you last used is only ever one tab away. Try it.

Once you’ve got the hang of this you’ll wonder why you ever used the mouse.

2: Finding a Note in Evernote

You have two choices here:

Either jump to the search bar using Ctrl Command (⌃⌘)  E on Mac or Win Shift F on Windows

Or press Command (⌘) J on Mac or Ctrl Q on Windows to open the switcher.

The search bar remembers things like which notebook you’re in, the switcher does a fresh Evernote wide search with suggestions

Which is better? Why not try them both out and see which one you like?

If you want a new note: hit Command (⌘) N on Mac or Ctrl N on Windows

3: Finding something within a Note

Now that you’ve found your note, try and find a particular word within it.

First you have to jump to the note editor.   Hit tab repeatedly to get to it and then press enter.  (It has to be said, Evernote, you could come up with a better way)

After that it’s just Command (⌘) F on a Mac or Ctrl F on Windows to bring up the Find in Note dialog

4: A Bonus Shortcut

The previous shortcuts help you work in Evernote. But if all you want to do is jot down a quick note there is an even faster way: the helper.

The helper is one of the most underutilised features of the Evernote desktop

Ctrl Cmd (⌃⌘)  N on a Mac or Ctrl Alt H on Windows to bring it up. You can add a quick note here. You can even screenshot straight into Evernote

Test Yourself

Practicing the above shortcuts will help to get them into your muscle memory

Follow this link to see a copy of this page as a note. Save it Evernote.

Now, starting in another application see if you can find this elephant without using  the mouse

  1. Tab switch to Evernote (Cmd Tab or Alt Tab)
  2. Search for or switch to this note
  3. Search within the note for the word elephant

Java Course 9: Test Yourself

Write programs to do the following

  1. Prompt the user to enter the length and width of a square. Output the area of the square.
  2. Prompt the user to enter a test score. Output their grade: Under 100 – Fail, Under 120 Pass, Under 130 Merit, 130+ Distinction
  3. Use a for loop to print out the following sequence: 12, 15, 18, 21, 24, 27
  4. Use a for loop to print out the first 8 square numbers: 1,4,9,16,25,36,49,64
  5. Make a counting program. Use a do while loop to keep asking “Another?” until the user enters “n”. Output the number of times the loop repeated
  6. Create a file called names.txt containing the names John, Paul, George and Ringo. Write a program the reads in the text file and prints out the data
  7. Create a string array containing the four seasons: spring, summer, autumn and winter. Print out a random season

Extension

Write a program that prints out the verses of the song the Twelve Days of Christmas. You will get bonus marks for elegant coding.

On the first day of Christmas
my true love sent to me:
A Partridge in a Pear Tree

On the second day of Christmas
my true love sent to me:
2 Turtle Doves
and a Partridge in a Pear Tree

On the third day of Christmas
my true love sent to me:
3 French Hens
2 Turtle Doves
and a Partridge in a Pear Tree

.
.
.

On the first day of Christmas
my true love sent to me:
12 Drummers Drumming
11 Pipers Piping
10 Lords a Leaping
9 Ladies Dancing
8 Maids a Milking
7 Swans a Swimming
6 Geese a Laying
5 Golden Rings
4 Calling Birds
3 French Hens
2 Turtle Doves
and a Partridge in a Pear Tree

Python Course 6: String Handling

Sample Code

s = "This is a sample string"
print(s)
print("It contains this many characters: ", len(s))
print("Here it is in upper case...")
print(s.upper())
print("Here it is split into a list:")
words = s.split()
for word in words:
    print(word)
print("Here it is split by the letter \'a\'")
words = s.split("a")
for word in words:
    print(word)
print("Here's the characters from index 1 to 3")
print(s[1:3])
print("Here's the sample string with the letter s changed to z")
print(s.replace("s","z"))
print("And now with the letter s changed to sausage...")
print(s.replace("s","sausage"))
print("And now with the spaces removed...")
print(s.replace(" ",""))
print("Notice the original string is unchanged... ")
print(s)

Exercise

  1. Output the length of the String “I never saw a purple cow”
  2. Convert the String “I never saw a purple cow” to uppercase and output the resulting string.
  3. Use \n to create a string that prints out the words to Happy Birthday. Make it yourself (Happy Birthday dear Kevin). Print out the string
  4. Use the replace method to print out the words to Happy Birthday, this time for Mr Lightfoot
  5. Output the String “I never saw a purple cow” as a list of separate words.
  6. Output the initial letters of the String “I never saw a purple cow”
  7. Prompt the user to enter a String. Output a list of the initial letters of the words input. Example: input “British Broadcasting Corporation” output “B”,”B”,”C”.

Extension

  1. Prompt the user to enter a String. Output a String with the vowels replaced with *’s. Example: input “I never saw a purple cow” output “* n*v*r s*w * p*rpl* c*w”
  2. Prompt the user to enter a string. Output the string as separate words in alternate upper and lower case: SO it LOOKS like THIS example
  3. Output the following list as one String: words = [“Calling”, “occupants”, “of”, “interplanetary”, “craft”]
  4. Prompt the user to enter a string. Output the number of vowels in the String.
  5. A palindrome is a string that reads the same forwards and backwards. Examples are “radar” and “rotavator”. Write a program that accepts a String as input and outputs “Palindrome” if the String is a palindrome, and “Not Palindrome” otherwise.

Getting Around in Doom Emacs

The following post is part of my new Emacs Writing Setup. You can find the complete setup here on GitHub: https://github.com/ballantony/emacs-writing


A big part of writing is putting the notes I’ve made into some sort of order. I spend a lot of time joining notes together to make scenes and then rearranging those scenes. Scrivener is good at the rearranging part (I’ve written about this here.) Where Scrivener falls down is the flexibility of search. Emacs allows me to home in on a scene, an idea or a sentence almost instantly.

I copied some of my writing process from Scrivener’s model, even going as far as writing a simple Emacs Scrivener mode. Doom Emacs has rendered that unnecessary. Tools like ripgrep and consult make it far quicker to find what I’m looking for. If you’re unfamliar with the following commands, try them out. You’ll be pleased that you did.

One last thing. Doom Emacs calls different commands depending on which completion engine you’re using. This means the search syntax may vary. I use the default (vertico at the time of writing) which means that searching for apples oranges will return lines containing apples and oranges. In other words: when searching, type one word for an initial selection, then a second to narrow it down.

10.0.1 Searching in Projects

  • SPC SPC find file in project
  • SPC s p search project for text
  • SPC s P search another project for text
  • SPC s d search files in directory for text

10.0.2 Searching in Buffers

  • SPC s s helper function search for text in current buffer. Matches are displayed in another window.
  • SPC s j helper function that goes to entry in evil’s jump list
  • SPC m . Jump to org heading (uses consult-org-heading)

And don’t forget

  • C-c C-j org-goto

10.0.3 Useful Tips

  • SPC s o Search online. t will search online dictionary, T thesaurus
  • Find an unmatched quote using this regex ^[^"]*"[^"]*$

10.0.4 M-x consult-ripgrep

For a more flexible search try consult-ripgrep. It’s worth reading the documentation, but here’s a taste:

  • #alpha beta Search for alpha and beta in any order.
  • #alpha.*beta Search for alpha before beta.
  • #\(alpha\|beta\) Search for alpha or beta (Note Emacs syntax!)
  • #word -- -C3 Search for word, include 3 lines as context
  • #first#second Search for first, quick filter for second.

Java Course 8: Methods

Before you do this section, watch the videos here: https://www.dropbox.com/sh/v0xcqgjkia6brmm/AABRKcrZjwhkR1j14NsMcd4za?dl=0

Older programming languages distinguish between Functions and Procedures. Very simply, a function returns a value, a procedure does not.

Java rolls both of these into one concept: Methods. A method always has a return type. If the return type is void it is what an older language would call a procedure, otherwise it’s a function.

Here is an example method:

public void spoons (String s, int i)
Access TypeReturn TypeNameParameters
publicvoidspoons(String s, int i)

Two example Classes

public class Main {

    public static void main(String[] args)
    {
	Person p1 = new Person("Bloggs", "Joe");
	p1.setSex("M");

	Person p2 = new Person("Baker", "Jill");
	p2.setGender("F");

	p1.printPerson();
	p2.printPerson();
    }

}


public class Person {

     private String surname;
     private String forename;
     private String gender;     

    Person(String surname, String forename)
    {
	this.surname = surname;
	this.forename = forename;
    }

    public void setGender(String s)
    {
	if(!(s.equals("F")|s.equals("M")))
	{
	    System.out.println("Validation error!");
	} else
	{
	    sex = s;
	}
    }

    public void printPerson()
    {
	System.out.println(surname + " " + forename + " " + gender);
    }

}

Method Exercise: Progress Tracker

Write a class Pupil that will track pupils’ progress through a year. The class will store pupils’ grades as percentages.

  1. Add private member variables String forename, surname
  2. Add private member variables int target, autumn, spring, summer
  3. Add a constructor method that will accept the parameters forename, surname, target
  4. Test the constructor by adding the following pupils: Joe, Bloggs, 70 and Jill, Cooper, 75
  5. Add accessor methods to setAutumn(), setSpring(), setSummer()
  6. Add accessor methods to getAutumn(), getSpring(), getSummer()
  7. Add the following grades to Joe Bloggs:  Autumn 55, Spring 65, Summer 75
  8. Add the following grades to JIll Cooper:  Autumn 50, Spring 60, Summer 70
  9. Add a method average() to return a double showing the average percentage a pupil has. Print out Joe and Jill’s average scores
  10. Add a method progress() that will return a String saying whether the pupil is above target, on target or below target on the summer test.
  11. Check this method works on Joe and Jill
  12. Add a print() method that will print out the pupil’s details in a suitable format

Extension Work

  • Add a validation() method to check that grades entered lie between 1 and 100
  • Modify your average() method so it will return a correct average if only one or two grades have been entered so far
  • Add a static int variable aBound to record the grade A boundary.
  • Add the appropriate setters and getters to aBound
  • Set up a Pupil [] array in your Main class to handle your pupils
  • Add a save() method to your Pupil class that will write the pupil data to file

Python Course 5: For Loops and Lists

For Loop Examples

Print the numbers 1 to 9

for k in range(1,10):
    print(k)

Countdown from 10 to 1

for k in range(10,0,-1):
    print(k)

Print the days of the week

days = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
for day in days:
    print(day)

Print the five times table

for k in range(1,11):
    print("5 x {} = {}".format(k, 5*k))

For Loop Exercises

Write for loops to output the following sequences of numbers

  1. 0,1,2,3,4,5,6,7,8,9,10
  2. 0,2,4,6,8,10,12,14,16
  3. 1,2,3,4,5, … 97,98,99,100
  4. 7,14,21, … 63,70,77
  5. 20,18,16, … 4,2,0,-2
  6. 2,5,8,11,14,17,20,23,26,29
  7. 99,88,77,66,55,44,33,22,11,0
  8. Numbers 1 to 1000.
  9. Even numbers from 0 to 100.
  10. Odd numbers from -50 to 50
  11. All multiples of 3 up to 500.

Look at the days of the week example above. Use lists and for loops to do the following

  1. Print out the seasons of the year (Spring, Summer, Autumn, Winter)
  2. Create a list of the names of the four people closest to you. Use a for loop to print that list.

Extension

Look at the examples above.

  1. Use a for loop to print the 5 times table up to 12 x 5
  2. Use a for loop to print the 7 times table up to 12 x 7 in the form “3 x 7 = 21”
  3. Use a for loop to print the following sequence: 0.5, 0.4, 0.3, 0.2, 0.1, 0
  4. Use a for loop to print the following sequence: 0.03, 0.02, 0.01, 0, -0.01, -0.02, -0,03
  5. Use a for loop to print five random numbers between 1 and 10
  6. Use a for loop to print the first ten square numbers: 1, 4, 9, 16, 25, 36, 49, 64, 81, 100
  7. Use a for loop to print the first ten triangle numbers: 1, 3, 6, 10, 15, 21, 28, 36,45, 55

Java Course 7: Arrays

Iterate Through an Array

String [] day =    {"Monday", "Tuesday", "Wednesday", 
		    "Thursday", "Friday", "Saturday", "Sunday"}; 

for(int i = 0; i<day.length;i++)
{
    System.out.println(day[i]);
}

Random Element of Array

String [] day = {"Monday","Tuesday","Wednesday","Thursday",
"Friday","Saturday","Sunday"};
int d = (int)(Math.random()*7);
System.out.println(day[d]);

Splitting a String into Words

String s = "This is an example string";
String [] seperated = s.split("\\s+");
for (int i=0; i<seperated.length; i++)
{
	System.out.println(seperated[i]);
}

for each loops

String [] day =    {"Monday", "Tuesday", "Wednesday", 
		    "Thursday", "Friday", "Saturday", "Sunday"}; 

for(String s: day)
{
    System.out.println(s);
}

Exercise

  1. int [] numbers = {3,5,3,4,7,8}; Print out the second element of the array
  2. Make a String array of the months of the year. Print out all the months.
  3. Print out a random month of the year
  4. Create an int array recording the number of days in each month
  5. Print out all the months and the days in each month.
  6. int [] numbers = {3,5,5,4,8,8,10,2}; Print out the total of all the numbers in the array. Print out the average
  7. Make a string array with the words “First”; “Second”; “Third”; … “Twelfth”. Write a for loop to print out “On the First Day of Christmas,” “On the Second Day of Christmas” etc.
  8. Separate the following string using the “,” as a token. Print out all the elements. String s = “1,5,6,1,7,1,4,3,1,4,5,6,1,5,3,5,6,4,4,8”;

Extension

Paste the following code into your IDE, and then do the questions below.

String [] question = { "What is the capital of France?",
		       "What is the capital of Germany?",
		       "What is the capital of Spain?"};
String [] answer = {"Paris", "Berlin","Madrid"};

int score = 0;
Scanner scan = new Scanner(System.in);
String input;

for(int i= 0; i<3; i++)
{
     System.out.println(question[i]);
     input = scan.nextLine();
     if(input.equals(answer[i]))
     {
	 score++;
     }
}

System.out.println("You scored "+ score + " out of "+ question.length);
  1. Run the code to check it works
  2. Add some extra questions and answers. Check the code still works
  3. Add code to print out the correct answer if the user gets a question wrong
  4. Alter your code so that questions and answers are read in from text files

Python Course 4: Lists

Sample Code

food = ["Sausage", "eggs", "Bacon", "Beans"]
pupils = ["John", "Jill", "Emily", "Satpal"]
scores = [5,3,6,7,9,1,2]
days = ["Sunday","Monday","Tuesday","Wednesday","Thursday", "Friday","Saturday"]        

# Print all the days
for day in days:
    print(day)

#print eggs
print(food[1])

#print Emily, Satpal
print(pupils[2:])

#print Tuesday, Wednesday
print (days[2:4])

#print John, Jill
print(pupils[:2])

#print Friday
print(days[-2])

print(len(days))
print(max(scores))
print(min(scores))

if "John" in pupils:
    print("Pupil is present")
else:
    print ("Pupil absent")

pupils = pupils + ["Arthur"]
print(pupils)

Exercises

The following questions refer to the sample code. You can type the code into IDLE and run it to help you figure out the answer

  1. Look at the print(food[ 1 ]) line. What does the [ 1] do?
  2. How would you print the first item in the list?
  3. If a python list has seven items, what would number would the seventh item be?
  4. Look at the print(pupils[2:]) line. What does [2:] mean?
  5. Look at the print(days[2:4])line. What does [2:4] mean?
  6. Look at the print(days[-2]) line. What does [-2] mean?
  7. What does len do?
  8. What do max and min do?

Now write your own modules to do the following

  1. Create a list called months, containing the months in the year.
  2. Print out all the months, one after the other
  3. Use slicing (e.g. days[2:4]) to print out the spring months: March, April, May
  4. Print out the summer months: June, July, August
  5. Print out the first and last months of the year
  6. Print out the winter months: December, January and February

Extension: Research

Use a search engine and online manuals to find out how to get Python to do the following

  1. Reverse the following list: [“Sunday”,”Monday”,”Tuesday”,”Wednesday”,”Thursday”, “Friday”,”Saturday”] i.e. print out “Saturday”,”Friday”,”Thursday”,… etc
  2. Remove “eggs” from this list food = [“Sausage”, “eggs”, “Bacon”, “Beans”]
  3. Sort the following list into ascending order scores = [5,3,6,7,9,1,2]
  4. Insert “Mushrooms” into this list, just after “eggs”
  5. Count how many times “blue” appears in this list [“red”,”blue”,”blue”,”blue”,”red”,”blue”]

Your Day on a Page

For many people, going to College means freedom. Freedom to try new things, to do what you like, when you like.

Well, not quite.

You’re still going to have  lectures and tutorials to attend (that’s why you’re going, remember?)  You want to make sure that you know what you’re doing every day, so that you can really enjoy your free time without worrying that you’re behind on an assignment.

That’s where Evernote can help you.

Evernote Home gives you your day on a page. Front and center should be your calendar. Your calendar will tell you where you need to be and when. Lectures, tutorials, practicals…

Setting up a calendar with all those details can be tedious. The good news is that 99% of the time your college will have your timetable already prepared and will share it with you via Google Calendar or Outlook. 

You can view that calendar on your home page on Evernote.  Here’s how you can add a Google Calendar. Evernote doesn’t support Outlook Calendar integration yet, but you can subscribe to your Outlook Calendar from your Gmail account. Scroll to the bottom of the page to see how.

Add your college calendar and when you open up Evernote in the morning you’ll have your day on a page before you.

But there’s more.

Searching is easy on Evernote, but why search when you can have the right notes appear at the right time?

Here’s a tip: link your study notes to your individual events.

Just suppose you’ve created a note with the materials you need for tomorrow’s 9am tutorial.  Link that note to the tutorial on the calendar on your Home Page. Here’s how to add link notes to calendar events.  Now the note will be there, just when you need it.

You can even get Evernote to remind you to open the notes as the lecture begins. Just go to Calendar settings (click the dots on the top right of the calendar widget).

If I only had two pieces of advice for people heading of to college, the above would be one of them. Follow this link to see the other…

Using Outlook

Using Outlook?  You can subscribe to your Outlook Calendar from your Gmail account, if your college allows you to share calendars.

  1. Go to Outlook and click on Settings (the cogwheel in the top right hand corner)
  2. Click on View all Outlook settings at the bottom
  3. Choose Calendar
  4. Choose Shared Calendars, just below Events from email. If Shared Calendars doesn’t appear then bad news, you’re college won’t allow this.
  5. Go to Publish a calendar and choose the calendar you want to share. Hit publish and copy the ICS link.  You
  6. Now open your Google Calendar
  7. Click on Cogwheel and Settings in the top right
  8. Choose Add Calendar and then From URL
  9. Enter the ICS link you copied earlier

Java Course 6: while and do While Loops

Counting Down

int count = 10;
while (count>0)
{
    System.out.println(count);
    count = count - 1;
}
System.out.println("Lift off!");

Counting Objects

String colours = "red blue red blue blue blue blue red blue red blue "
		 + "red blue blue red blue blue blue red blue red red "
		 + "blue blue red red red red blue red blue red blue blue";


Scanner scan = new Scanner(colours);
int redcount = 0;

while (scan.hasNext()) {
    String s = scan.next();
    if (s.equals("red")) {
	redcount = redcount + 1;
    }
}
System.out.println("Number of reds " + redcount);

A Basic Question Loop

Scanner scan = new Scanner(System.in);
String answer;

do
{
    System.out.println("What's the capital of France?");
    answer = scan.nextLine(); 

}while (!answer.equals("Paris"));
 System.out.println("Correct!");

A Question Loop with a Count

Scanner scan = new Scanner(System.in);
String answer;
int count = 0;

do
{
    System.out.println("What's the capital of France?");
    answer = scan.nextLine();
    count = count + 1;

}while (!answer.equals("Paris"));
 System.out.println("Correct!");
 System.out.println("It took you " + count + " guesses");

A Question Loop with a Flag

Scanner scan = new Scanner(System.in);
int answer;
boolean isNotDone = true;

do
{
    System.out.println("Enter an Integer, 0 to end.");
    answer = scan.nextInt();
    System.out.println(answer + " squared = " + answer * answer);
    if (answer == 0)
    {
	isNotDone = false;
    }

}while (isNotDone);
 System.out.println("Done!");

A Question Loop with a Count and a Flag

Scanner scan = new Scanner(System.in);
String answer;
boolean isCorrect = false;
int count = 0;
do
{
    System.out.println("Enter the password");
    answer = scan.nextLine();
    if (answer.equals("Java"))
    {
	isCorrect = true;
    }
    count = count + 1;
 }while(!isCorrect & count <3 );


if (isCorrect)
{
    System.out.println("Correct password");
}
else
{
    System.out.println("Incorrect password");

Exercise

while Questions

  1. Use a while loop to print out the integers from 1 to 10
  2. Use a while loop to print out the even numbers from 2 to 20
  3. Use a while loop to print out the four times table
  4. Use a while loop to print out the five times table in the form “n x 5 = 5n”
  5. Use a while loop to print out the sequence 7,10,13,16,19,22,25
  6. Use a while loop to print out the sequence -0.3, -0.2, -0.1, 0, 0.1, 0.2
  7. Use a while loop to print out the sequence 64, 32, 16, 8, 4, 2, 1
  8. Use a while loop and Scanner to count how many heads and tails there are in the String below. (nb. you should carefully copy and paste the String into your program)

String coins = “head head tail head tail head head head tail head tail head tail head head head tail “+ “head tail head tail head tail head tail head tail tail tail head head head tail “+ “tail head tail head tail tail head head head tail tail tail head tail head head head tail “+ “head tail tail head tail head head head tail head tail head tail head head head head “+ “head tail head tail head tail head head head tail tail head tail head tail head head head head”;

  1. Write a code to find the number of times the word “never” appears in the following poem: I never saw a purple cow, I never hope to see one, but I can tell you anyhow, I’d rather see than be one.”
  2. Now search the Internet for the text to the poem “McCavity the Mystery Cat” Write code to count the number of times the word McCavity appears.

do while Questions

  1. Make the computer keep asking “Are we there yet?” until the answer yes is input.
  2. Ask the user the to guess a number between one and ten. Hard code the number 4 as an answer. The computer will print out how many guesses the user takes before they get the correct answer.
  3. Modify program 2 so that the computer chooses a random number as the answer.
  4. Write a higher lower game. Modify program 3. The computer thinks of a number between 1 and 100. The user tries to guess the number, and the computer tells the user if their answer is higher or lower. Whe then user guesses correctly, the computer congratulates the user and tells them how many guesses it took them.
  5. Wrtie a password checker. The user cannot proceed until they enter the correct password.
  6. Modify your password checker so that the user sees the message “Locked Out” if they fail to guess the password in three guesses.

Extension

The skeleton code below is intended to guess the number the end user is thinking of. The end user can enter yes if the computer guesses the answer, higher if the number is higher and lower otherwise. Copy the code into the IDE and complete it.

Scanner scan = new Scanner(System.in);
double num = Math.random()*100;
int ran = (int)num+1;
int guess = 50;
int high =100;
int low= 0;
String input = "";
boolean isCorrect = false;

do
{
    System.out.println("Is the number " + guess + "?");
    input = scan.nextLine();
    if(input.equals("yes"))
    {
	isCorrect = true;
    }
    else if(input.equals("higher") )
    {
	low = guess;
	guess = low + (int)(high-low)/2;
    }


}while(!isCorrect);