Skip to content

Instantly share code, notes, and snippets.

View Main.java
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
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
IanMcT / tempConverter
Created Feb 24, 2017
Basis for Temp Converter - HMTL and JavaScript
View tempConverter
<html>
<head>
</head>
<body>
<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>
</p>
@IanMcT
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');
}else
{
@IanMcT
IanMcT / mymethod.py
Created Feb 9, 2017
Example of Python program that uses methods and scope of variables.
View mymethod.py
#variables
var1 = 1
var2 = 2
#a method
def my_method():
global var2
var1 = 2
print('Method var1',var1,'var2:',var2)
@IanMcT
IanMcT / j3palindrome.py
Created Jan 26, 2017
Hidden palindrome solution.
View j3palindrome.py
"""J3 Hidden Palindrome
http://cemc.math.uwaterloo.ca/contests/computing/2016/stage%201/juniorEn.pdf
This strategy loops from the longest possible palindrome to the shortest"""
word=input()
#0-3
#1-2
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
IanMcT / getFromUrl.py
Created Jan 21, 2017
Get image from file.
View getFromUrl.py
import urllib.request #part of the standard library
#provide the url to open
u = urllib.request.urlopen('https://docs.python.org/3/_static/py.png')
#write the image data to a file
with open('p.png','wb') as f:
f.write(u.read())
@IanMcT
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
font = cv2.FONT_HERSHEY_SIMPLEX
cv2.putText(img,'Hello World!',(10,200), font, 1,(255,255,255),2)
@IanMcT
IanMcT / vision.py
Created Jan 15, 2017
Sample python program to take a picture and output the colour within a specified range.
View vision.py
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
IanMcT / sample_animation.py
Created Dec 13, 2016
sample animated rectangle
View sample_animation.py
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
IanMcT / HOWTOCREATEASCREEN.py
Created Dec 6, 2016
This shows how to create a screen in pygame.
View HOWTOCREATEASCREEN.py
#!/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