Skip to content

Instantly share code, notes, and snippets.

@Rhysoshea
Rhysoshea / number_adder.py
Created April 21, 2020 02:36
Random number adder taken from std input
import time
def main():
limits = [10, 20, 30]
total = 0
for i, num in enumerate(limits):
file1 = open('file.txt', 'a+')
@Rhysoshea
Rhysoshea / random_generator.py
Created April 20, 2020 12:55
Random number generator
import random
while True:
response = input()
if response == "End":
break
num = random.randint(0,int(response))
print(num)
@Rhysoshea
Rhysoshea / parenting.py
Created April 18, 2020 06:38
Parenting Partnering Returns codejam 2020 solution
def solution(n, arr):
dict_free = {"J": [0,0],
"C": [0,0]
}
arr = [[x,i,""] for i,x in enumerate(arr)]
arr = sorted(arr, key= lambda x:x[0][0])
for time in arr:
if time[0][0] >= dict_free["J"][1] or time[0][1] <= dict_free["J"][0]:
dict_free["J"] = [time[0][0],time[0][1]]
@Rhysoshea
Rhysoshea / nesting_depth.py
Created April 18, 2020 06:24
Nesting Depth codejam 2020 solution
def solution(n):
ans = ""
ans += "(" * n[0]
for i in range(len(n)-1):
ans += str(n[i])
diff = n[i] - n[i+1]
if diff < 0:
ans += "("*abs(diff)
elif diff > 0:
ans += ")"*abs(diff)
@Rhysoshea
Rhysoshea / vestigium.py
Created April 18, 2020 06:19
Vestigium codejam 2020 solution
def solution(n, arr):
k = r = c = 0
for i in range(n):
if len(arr[i]) != len(set(arr[i])):
r += 1
if len([x[i] for x in arr]) != len(set([x[i] for x in arr])):
c+=1
k+=arr[i][i]
@Rhysoshea
Rhysoshea / helper.py
Created August 28, 2019 03:41
Helper functions for k-means clustering project
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from mpl_toolkits.axes_grid1 import make_axes_locatable
from sklearn.cluster import KMeans
from sklearn.metrics import mean_squared_error
import itertools
from sklearn.metrics import silhouette_samples, silhouette_score
def draw_scatterplot(x_data, x_label, y_data, y_label):
@Rhysoshea
Rhysoshea / except.py
Created November 29, 2018 00:08
Example of an exception
try:
clouds = dict['list'][i]['clouds']['all']
except KeyError:
clouds = 0
@Rhysoshea
Rhysoshea / import.py
Created November 28, 2018 23:54
Example of code turning csv files into json data
'''
converts a csv file into a JSON file for all reports, giving latest gen output
'''
import json
import pandas as pd
import numpy as np
from datetime import datetime as dt
'''
@Rhysoshea
Rhysoshea / example.plist
Created November 28, 2018 11:59
Example script for scheduling a script execution
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dt$
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.demo.dashboard.plist</string>
<key>ProgramArguments</key>
<string>/path/to/working/directory/python/test.py</string>
<key>KeepAlive</key>
<true/>
@Rhysoshea
Rhysoshea / highcharts.js
Created November 28, 2018 11:42
Example code of creating a highcharts graph
$(function() {
$.getJSON("./data/interconnector.json", function(data) {
var french = [],
irish = [],
dutch = [],
e_w = [],
time = [],
newTime = []
i = 0;