Skip to content

Instantly share code, notes, and snippets.

View ocaoimh's full-sized avatar

Cormac O'Keeffe ocaoimh

View GitHub Profile
@ocaoimh
ocaoimh / index.html
Created October 18, 2023 15:09
spotify_clone
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Spotify Clone</title>
<link rel="stylesheet" href="styles/style.css" />
</head>
try:
request = requests.get('put your link here')
request.raise_for_status() # returns an HTTPError if the response is not OK
print("All good! Response code is", request.status_code)
except requests.exceptions.HTTPError as err:
if request.status_code == 404:
print("404: Oops, sorry we can't find that page!")
else:
print("The error code is", err.args[0]) # look up the 1st argument from HTTPError
@ocaoimh
ocaoimh / try_except.py
Last active June 23, 2023 16:37
try_except.py
from requests import codes # the code names from requests
from http.client import responses #it lets you look up the response
try:
r = requests.get('https://www.abc.net.au/triplej/hottest100/22/1-100', timeout=1)
r.raise_for_status() # returns an HTTPError object if an error has occurred during the process
except requests.exceptions.HTTPError as errh: # explains the errror
print("HTTP Error")
print(errh.args[0]) # look up the 1st argument from HTTPError
else:
fig, axes = plt.subplots(5, 3, sharex=True, figsize=(18,40)) # 5 rows x 3 columns
fig.subplots_adjust(hspace=0.1, wspace=.5) # ensure that the plots do not overlap
fig.suptitle('Insurance claims')
sns.boxplot(ax=axes[0, 0], data=data, x="total_claim_amount", y="state")
sns.boxplot(ax=axes[0, 1], data=data, x="total_claim_amount", y="response")
sns.boxplot(ax=axes[0, 2], data=data, x="total_claim_amount", y="coverage")
sns.boxplot(ax=axes[1, 0], data=data, x="total_claim_amount", y="education")
@ocaoimh
ocaoimh / rename-conditional.py
Last active April 1, 2023 09:22
Renaming based on condition
#Create a new dataframe with language ids and language names.
#Hindi, Bengali, Marathi, Telugu, Tamil, Gujarati, Urdu
#Corresponding to these language ids: 171, 330, 345, 49, 206, 260, 161
conditions = [
(data2['LanguageID'] == 171),
(data2['LanguageID'] == 330),
(data2['LanguageID'] == 345) ,
(data2['LanguageID'] == 49),
(data2['LanguageID'] == 206),
# Create likert list object
LXP.data.items.likert <- likert(LXP.data.items)
# Summarize the data
summary(LXP.data.items.likert)
# Plot the data
plot(LXP.data.items.likert)
# Plot the data with colours to match our visual identity
# Remove full stops and replace with them with blanks
names(LXP.data.items) <- gsub("\\.", " ", names(LXP.data.items))
#ordering levels
#Q1
LXP.data.items$`Access my timetable`<- factor(LXP.data.items$`Access my timetable`, levels = c("Very unimportant","Quite unimportant", "Neither important nor unimportant","Important","Very important"), ordered = T)
#Q2
LXP.data.items$`Particpate in collaborative activities forums peer assessment group work ` <- factor(LXP.data.items$`Particpate in collaborative activities forums peer assessment group work ` , levels = c("Very unimportant","Quite unimportant", "Neither important nor unimportant","Important","Very important"), ordered = T)
@ocaoimh
ocaoimh / likert_libraries_data
Last active July 13, 2021 16:47
Libraries and import data
# Import libraries
library(plyr)
library(dplyr)
library(likert)
library(grid)
library(ggplot2)
#Import data. You'll need to change the path here and point it to where your data are.
LXP.data <- read_excel("LMSdummyDataShort_en.xlsx")
#this cleans up your global environment (optional)
rm(list = ls())
# Version notes
## Usung data.table_1.12.8 and readxl_1.3.1, R version 3.6.1 (2019-07-05)
library(readxl) #this allows you import and extract data from your Excel workbooks
library(data.table) #this library is the most crucial one and applies the functions that list and recombine the data
library(xlsx) # this is optional. It's a tricky library that can break if you don't have the Java Development kit installed