{{ message }}

Instantly share code, notes, and snippets.

# Craig Janis cjanis

Created May 16, 2018
A loan calculator that allows for extra principal payments
View loan-calculator.py
 # given principal and interest rate # + periods = minimum payment amount and total cost # + extra payment = periods, total cost, and savings over minimum import math def calculate(principal,rate_yearly,periods,extra=0): # variables rate_monthly = rate_yearly / 12 / 100
Created May 8, 2018
Command line tic tac toe game built in Python
View tic-tac-toe.py
 b = ['O',' ',' ',' ',' ',' ',' ',' ',' ',' '] def play(b,m=0): # reset board if new game if m == 0: b = ['O',' ',' ',' ',' ',' ',' ',' ',' ',' '] print('new game') # update board
Created May 8, 2018
A simple blackjack game built with Python
View blackjack.py
 ## initiate game print( '\n' * 100 + '#' * 16 + '\n\nSIMPLE BLACKJACK' + '\nby Craig Janis\n' + '\nOverview: You start with two cards\nand decide whether to "hit" (ask\nfor another card) or "stand" (end\nyour turn with the cards you\nalready have). The dealer starts\nwith one card visible and one\ncard face down, and after your\nturn, the dealer will have a\nchance to hit or stand. You win\nif you end the game with more\npoints the dealer, but fewer\nthan 21 points. If you go over 21\npoints, that\'s called a "bust".\nTies go to the Dealer.\n\n' + '#' * 16 )
Created May 8, 2018
Calculate pi using the Nilakantha series with up to 48 decimals of precision
View pi.py
 ''' calculate pi using the Nilakantha series up to 48 decimals of precision Nilakantha series approximates pi, but is not as accurate as some other, more intensive methods the most accurate predictions come with odd number decimal precision '' def calculate_pi(decimals): # make the calculation
Created May 8, 2018
A simple numeric cipher created with Python
View cipher.py
 # create alphabet and digits dictionary import string alphabet_master = string.ascii_lowercase + string.digits + ' ' alphabet_master = {a:(alphabet_master.index(a) + 1) for a in alphabet_master} # the cipher def cipher(direction,key,message):
Last active Aug 29, 2015 — forked from jedda/gist:4103604
Configuring RADIUS on OS X 10.9 Server
View gist:fdaed8d5294e96f5ba98
Created Nov 28, 2012
Corona SDK Rating Prompt
View coronasdk-rating.lua
 -- show rating prompt local function ratingPrompt() local function ask() local function answer(event) if ("clicked" == event.action) then if (event.index == 1) then system.openURL("http://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=440754678") data.rated = "yes" writeData() elseif (event.index == 2) then
Created Nov 28, 2012
Data Storage with Corona SDK
View coronasdk-data.lua
 --os.remove(system.pathForFile( "data.db", system.DocumentsDirectory)) -- read data function readData() local path = system.pathForFile("data.db", system.DocumentsDirectory) local file = io.open(path, "r") if (file) then data = json.decode(file:read("*a")) else file = io.open(path, "w")
Created Nov 28, 2012
Corona SDK: IAP
View coronasdk-iap.lua
 -- iap results function iapTransaction(event) if (event.transaction.state == "purchased") or (event.transaction.state == "restored") then if (event.transaction.productIdentifier == "playmaticBalloons") then data.iap.iapBalloons = "yes" iconBalloonsPrice.alpha = 0 end writeData() elseif (event.transaction.state == "cancelled") then elseif (event.transaction.state == "failed") then
Created Nov 23, 2012
Using Facebook's Social Graph to Find A WordPress Blog's Most Popular Posts
View popularposts.php
 get_results("SELECT * FROM wp_posts WHERE \$wpdb->posts.post_status='publish' AND \$wpdb->posts.post_type='post'"); // get data for each post \$popular = array(); foreach (\$posts as \$post) {