Skip to content

Instantly share code, notes, and snippets.

@ogilviemt
ogilviemt / coderbyte1.py
Created December 9, 2014 04:37
coderbyte question 1
def FirstReverse(str):
array = list(str)
length = len(array) - 1
reverse = []
while length > 0:
for char in array:
reverse.append(array[length])
length -= 1
value = ''.join(reverse)
return value
@ogilviemt
ogilviemt / star_field_test.py
Created November 22, 2014 16:28
Animated star field background using pygame
import pygame
import random
screen = pygame.display.set_mode([1024, 768])
height = pygame.display.Info().current_h
width = pygame.display.Info().current_w
pygame.display.set_caption('Window Caption')
clock = pygame.time.Clock()
#create the locations of the stars for when we animate the background
@ogilviemt
ogilviemt / template.py
Last active August 29, 2015 14:10
A collection of commonly declared variables for my .py scripts
import pygame
screen = pygame.display.set_mode([1024, 768])
height = pygame.display.Info().current_h
width = pygame.display.Info().current_w
pygame.display.set_caption('Window Caption')
clock = pygame.time.Clock()
#define some commonly used colours
WHITE = (255, 255, 255)
@ogilviemt
ogilviemt / is_prime.py
Created March 23, 2014 21:12
Accept input and determine prime numbers
import string
def is_prime(n):
n = abs(int(n))
if n < 2:
return False
if n == 2:
return True
if not n & 1:
return False
@ogilviemt
ogilviemt / calcAgeInDays
Created November 12, 2013 20:00
Calculate age in days -- teaching myself java
//
// This is not my code!
//
// Stolen from http://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html
// for purposes of teaching myself java. As per their license, the following must be included:
//
// Copyright (c) 2013, Oracle America, Inc.
// All rights reserved.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
@ogilviemt
ogilviemt / 1d20 Roller
Last active December 26, 2015 09:29
Teaching myself Python. This is a simple random dice roller. Input a number of dice to roll (like 3d6) and a modifier if you have one (like bonus damage!) and this snip of code will calculate the total using randint as a randomizer.
from random import randint
while True:
string = str(raw_input("Dice: ")) #how about "3d6", for example
split = string.split("d") #create a list containing 3 and 6
modifier = None
while modifier is None:
modifier = int(raw_input("Modifier: "))
if modifier is "":
modifier = 0