Skip to content

Instantly share code, notes, and snippets.

import time
odd = True
counter = 0
while True:
counter += 1
time.sleep(600)
print('{word} {count}'.format(count=counter, word='tick' if odd else 'tock'))
odd = not odd
@KoaxialKable
KoaxialKable / doorRiddle.py
Last active August 29, 2015 14:24
Very simple demonstration of the logic behind the "Two Guardians" riddle from The Labyrinth, the bool argument is the [unknown] true state of the door in question. Because the nature of each guardian is applied to the answer, we are guaranteed exactly one logical "not" and therefore should accept the opposite of our answer as the truth.
def liar(answer):
return !answer
def honest(answer):
return answer
#"Would that door say that this is the door to the castle?"
#if asking the liar, and the liar is the death door:
print(liar(honest(false))) # "True"
@KoaxialKable
KoaxialKable / stringz.py
Last active August 29, 2015 14:19
Just a quick peek at some of the string formatting options available in Python.
for row in curs.fetchall():
print('{Name:<21} {Amount:>17,.2f} {AvgAmount:>18,.2f} {NumTimes:>12}'.format(
Name = row[0],
Amount = row[1],
AvgAmount = row[2],
NumTimes = row[3]
)
@KoaxialKable
KoaxialKable / FizzBuzzBaz.py
Created April 10, 2015 18:42
After my "first instinct" solution to FizzBuzz, I put this together as a more robust alternative. It's cleaner and allows the substitution of any number of "Buzz" words in place of numbers. I think it captures the spirit of the solution a lot better.
upper = 100
words = {"Fizz": 3, "Buzz": 5, "Baz": 7}
for i in range(1, upper+1):
result = ""
for word, number in words.items():
if i % number == 0:
result += word
if result == "":
print(i)
else:
@KoaxialKable
KoaxialKable / FizzBuzz.py
Last active August 29, 2015 14:18
First instinct when I heard about the FizzBuzz problem. This took less than two minutes to conceive and code.
for i in range(1,101):
if i % 3 == 0:
if i % 5 == 0:
print("FizzBuzz")
continue
print("Fizz")
elif i % 5 == 0:
print("Buzz")
elif i % 7 == 0:
print("Baz")
@KoaxialKable
KoaxialKable / Wallet_Test.py
Last active August 29, 2015 14:17
First exposure to both XML and the Eve Online API. This is my attempt to aggregate data using an API key
#! /usr/bin/env python
print('Importing Libraries...')
import time
import datetime
import requests
import locale
import xml.etree.cElementTree as ET
from xml.etree.ElementTree import ElementTree
from operator import itemgetter
<script type="text/javascript">
$(document).ready(function () {
// add code here
$("#Button1").click(function () {
alert("Hello world!");
});
})
</script>
@KoaxialKable
KoaxialKable / 7.1.lua
Last active August 29, 2015 14:02
Needlessly complicated Exercise 7.1
limit = 30 -- set the upper limit; don't care to get user input for this
function make_it_so()
local sum_of_squares = 0 --static
local sum_of_cubes = 0 --static
return function(a)
sum_of_squares = sum_of_squares + a^2
sum_of_cubes = sum_of_cubes + a^3
print("Squares: "..sum_of_squares, "Cubes: "..sum_of_cubes) --prints running total every time function is called
#wrapper(header(h2{News}+img[src="image.png"])+nav(ul>li*3>a(img))+article#News_$*5(h1+p(lorem200)+li{Continue reading article in }>a{news.c0m})+footer)
becomes:
<div id="wrapper">
<header>
<h2>News</h2>
<img src="image.png" alt="">
SELECT s1.Industry, s1.TickerSymbol, s1.ST_Close
FROM StockData AS s1
WHERE s1.ST_Close =
(SELECT MAX(s2.ST_Close)
FROM StockData as s2
WHERE s1.Industry = s2.Industry)
ORDER BY s1.ST_Close DESC;