Skip to content

Instantly share code, notes, and snippets.

@IanMcT
IanMcT / Main.java
Created January 20, 2019 12:14
javaSampleInput created by IanMcT - https://repl.it/@IanMcT/javaSampleInput
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 February 24, 2017 14:55
Basis for Temp Converter - HMTL and JavaScript
<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 February 22, 2017 15:59
Google Script code for copying a file for every student in the class.
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 February 9, 2017 15:05
Example of Python program that uses methods and scope of variables.
#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 January 26, 2017 03:13
Hidden palindrome solution.
"""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 January 21, 2017 00:06
Get image from file.
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 January 16, 2017 19:45
How to write on an image
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 January 15, 2017 14:23
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
IanMcT / sample_animation.py
Created December 13, 2016 16:04
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
IanMcT / HOWTOCREATEASCREEN.py
Created December 6, 2016 19:41
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