This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import ntplib | |
def get_time(): | |
'''Get atomic time from server and return it, along with the offset.''' | |
c = ntplib.NTPClient() | |
response = c.request('uk.pool.ntp.org', version=3) | |
return time.ctime(response.tx_time), response.offset | |
def main(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import subprocess | |
def scan(base, ceiling): | |
base_suff = int(base.split('.')[-1]) | |
for i in range(base_suff, ceiling+1): | |
hostname = '.'.join(base.split('.')[:-1] + [str(i),]) | |
try: | |
with open('/dev/null') as f: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# generator function for the fibonacci sequence | |
def fibonacci(): | |
a, b = 0, 1 | |
while True: | |
yield a | |
a, b = b, a + b | |
def main(): | |
term = int(input('nth term:')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- a long function to tell you what your number is or | |
-- if it's bigger than 5 | |
onetofive :: (Integral a) => a -> String | |
onetofive x = do | |
if x == 1 then | |
"One!" | |
else | |
if x == 2 then | |
"Two!" | |
else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
def main(): | |
running = True | |
while running: | |
print('Enter a speed in m/s or as a fraction of the speed of light.') | |
print('m/s in the format: x m/s, fraction in the format 0.x') |