Skip to content

Instantly share code, notes, and snippets.

View HarryCoops's full-sized avatar

Harry Cooper HarryCoops

View GitHub Profile
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():
@HarryCoops
HarryCoops / pingsweep.py
Created July 20, 2015 19:51
Host discovery program in python. Usage: pingsweep.py base_ip range,
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:
# 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:'))
@HarryCoops
HarryCoops / pattern_matching_example.hs
Last active August 29, 2015 14:24
Haskell code showing how pattern matching can make your code cleaner
-- 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
@HarryCoops
HarryCoops / timedi.py
Last active August 8, 2022 13:17
Time dilation calculator in python
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')