Skip to content

Instantly share code, notes, and snippets.

import java.util.*;
class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(;
System.out.println("Enter a number");
int n = scanner.nextInt(); // read an integer from input stream.
System. out. println(n); // print n.
System.out.println("Hello world!");
IanMcT / tempConverter
Created Feb 24, 2017
Basis for Temp Converter - HMTL and JavaScript
View tempConverter
<p>Temp: <br />
<input type="text" id="tempInput" /><br />
<input id="radioCT" type="radio" name="conversionType" value="CToF" checked>Celsius to Fahrenheit</input><br />
<input id="radioCT" type="radio" name="conversionType" value="FToC">Fahrenheit to Celsius</input><br />
<button onclick="convertTemp()">Convert</button>
IanMcT / copyfileforclass
Created Feb 22, 2017
Google Script code for copying a file for every student in the class.
View copyfileforclass
function myFunction() {
// Usercan copy the current file with a new name.
var ui = DocumentApp.getUi();
var newFileName = "";
while (newFileName != "Q"){
if (newFileName != "Q")
Logger.log('File name is not Q');
IanMcT /
Created Feb 9, 2017
Example of Python program that uses methods and scope of variables.
var1 = 1
var2 = 2
#a method
def my_method():
global var2
var1 = 2
print('Method var1',var1,'var2:',var2)
IanMcT /
Created Jan 26, 2017
Hidden palindrome solution.
"""J3 Hidden Palindrome
This strategy loops from the longest possible palindrome to the shortest"""
foundpalindrome = True #sentinal value
keeplooping = True#Stop when palindrom found
#start with the longest possible, work in
for i in range(len(word),1,-1):
IanMcT /
Created Jan 21, 2017
Get image from file.
import urllib.request #part of the standard library
#provide the url to open
u = urllib.request.urlopen('')
#write the image data to a file
with open('p.png','wb') as f:
IanMcT / writetext
Created Jan 16, 2017
How to write on an image
View writetext
import numpy as np
import cv2
# Create a black image
#img = np.zeros((512,512,3), np.uint8)
img = cv2.imread('images/test_image.png')
# Write some Text
cv2.putText(img,'Hello World!',(10,200), font, 1,(255,255,255),2)
IanMcT /
Created Jan 15, 2017
Sample python program to take a picture and output the colour within a specified range.
import cv2
import numpy as np
#note the libraries that need importing
# Camera 0 is the integrated web cam on my netbook
camera_port = 0
#Number of frames to throw away while the camera adjusts to light levels
ramp_frames = 30
IanMcT /
Created Dec 13, 2016
sample animated rectangle
import random, os.path
import pygame
from pygame.locals import *
SCREENRECT = Rect(0, 0, 370, 720)
class Ball:
def __init__(self):
self.location = (50,50,50,50)
self.y = 50
def update(self):
IanMcT /
Created Dec 6, 2016
This shows how to create a screen in pygame.
#!/usr/bin/env python
import random, os.path
#import basic pygame modules
import pygame
from pygame.locals import *
SCREENRECT = Rect(0, 0, 640, 480)
GAME_ON = True