Skip to content

Instantly share code, notes, and snippets.

@obikag
obikag / ROT13.py
Last active August 29, 2015 14:16
ROT13 substitution cipher implemented in Python. ROT13 method encrypts and decrypts a given string. Special characters and numbers are not encrypted with this cipher.
'''
Created on Feb 24, 2015
'''
import re
# Create a dictionary to store the cipher
cipher = {
'A':'N','B':'O','C':'P','D':'Q','E':'R','F':'S','G':'T','H':'U','I':'V','J':'W','K':'X','L':'Y','M':'Z',
'N':'A','O':'B','P':'C','Q':'D','R':'E','S':'F','T':'G','U':'H','V':'I','W':'J','X':'K','Y':'L','Z':'M',
'a':'n','b':'o','c':'p','d':'q','e':'r','f':'s','g':'t','h':'u','i':'v','j':'w','k':'x','l':'y','m':'z',
@obikag
obikag / Prime.py
Created February 25, 2015 00:11
Prime number methods done in Python. First method determines if a number is prime, while the second method print to screen the first 'n' prime numbers. View comments for more information.
'''
Created on Feb 24, 2015
'''
# Method to determine if a number is a prime number
def isPrime(num):
if num <= 0 :
print("Number must be a positive integer greater than zero")
return False
elif (num == 1):
@obikag
obikag / Fibonacci.py
Created February 25, 2015 00:29
Fibonacci Number methods done in Python. First two methods calculates the Fibonacci number (n), while the last method prints the Fibonacci number sequence 'n' times.
'''
Created on Feb 24, 2015
'''
# Recursive Method calculating Fibonacci Number for n
def fibRecursion(n):
if (n == 0) :
return 0
elif (n == 1):
return 1
@obikag
obikag / TextAnalysis.py
Last active August 29, 2015 14:16
Text Analysis object class implemented in Python. The class methods return the frequencies of word types and n-grams in the sample text. Additionally, the number of words in the sample text is calculated.
'''
Created on Feb 24, 2015
Sample text is an excerpt from Chapter 2 of the Adventures of Huckleberry Finn
'''
import operator, string
class TextParser:
@obikag
obikag / CompareTables.lua
Last active December 20, 2015 03:59
Function to compare tables based on values within each table. Sequence of values in each table is not taken into consideration. This function returns true if all of the values in each of the tables match.
--Method to compare tables
function compare_tables(table1,table2)
temp = {}
if #table1 ~= #table2 then return false end
for _,v1 in pairs(table1) do
for _,v2 in pairs(table2) do
if v1 == v2 then
table.insert(temp,v1)
break
end
@obikag
obikag / CompareTuples.py
Created July 24, 2013 01:20
Function to compare tuples based on values within each tuple. Sequence of values in each tuple is not taken into consideration. This method returns true if all of the values in each of the tuples match.
# Method for comparing two tuples
def compare_tuple(tuple1,tuple2):
temp = []
if len(tuple1) != len(tuple2): return False
for val1 in tuple1:
for val2 in tuple2:
if val1 == val2:
temp.append(val1)
break
return (len(temp) == (len(tuple1) and len(tuple2)))
@obikag
obikag / Prime.lua
Created September 19, 2013 00:03
Prime number functions done in Lua. First function determines if a number is prime, while the second function print to screen the first 'n' prime numbers. View comments for more information.
---Function to determine if a number is a prime number
function isPrime(num)
if num <= 0 then
print("Number must be a positive integer greater than zero")
return false
elseif num == 1 then return true end
--[[Prime number is divisable by itself and one,
so we check for other factors between the prime number and one. (1 < x < num)
]]
for x = num-1,2,-1 do
@obikag
obikag / PascalTriangle.lua
Last active December 23, 2015 23:09
Pascal's Triangle calculated using a recursive function in Lua.
--Recursive function to create the mathemeatical series
function pascal(col,row)
if(col == 0) or (col == row) then return 1
else return pascal(col-1,row-1) + pascal(col,row-1)
end
end
--Prints Pascal's Triangle to the 'n'th row
function PascalTriangle(num)
if (num <= 0) then print("Number must be greater than zero") return end
@obikag
obikag / ROT13.lua
Created October 18, 2013 02:39
ROT13 substitution cipher implemented in Lua. ROT13 function encrypts and decrypts a given string. Special characters and numbers are not encrypted with this cipher.
--Create a table to store the cipher
cipher = {
A="N",B="O",C="P",D="Q",E="R",F="S",G="T",H="U",I="V",J="W",K="X",L="Y",M="Z",
N="A",O="B",P="C",Q="D",R="E",S="F",T="G",U="H",V="I",W="J",X="K",Y="L",Z="M",
a="n",b="o",c="p",d="q",e="r",f="s",g="t",h="u",i="v",j="w",k="x",l="y",m="z",
n="a",o="b",p="c",q="d",r="e",s="f",t="g",u="h",v="i",w="j",x="k",y="l",z="m"
}
--Function encrypts and decrypts using ROT13
function ROT13(str)
@obikag
obikag / tennis.html
Created August 24, 2016 12:38
My version of the tennis game from the Udemy course, "Code Your First Game: Arcade Classic in JavaScript on Canvas".
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<canvas id="gameCanvas" width="800" height="600"></canvas>
<script>
var canvas;