Upgrade to Pro — share decks privately, control downloads, hide ads and more …

apidays Australia 2023 - Consuming And Building APIs During Hackathons, William Mckee, McDepth

apidays Australia 2023 - Consuming And Building APIs During Hackathons, William Mckee, McDepth

apidays Australia 2023 - Platforms, Products, and People: The Power of APIs
October 11 & 12, 2023
https://www.apidays.global/australia/

Consuming And Building APIs During Hackathons
William Mckee, Software Developer at McDepth

------

Check out our conferences at https://www.apidays.global/

Do you want to sponsor or talk at one of our conferences?
https://apidays.typeform.com/to/ILJeAaV8

Learn more on APIscene, the global media made by the community for the community:
https://www.apiscene.io

Explore the API ecosystem with the API Landscape:
https://apilandscape.apiscene.io/

apidays

October 24, 2023
Tweet

More Decks by apidays

Other Decks in Programming

Transcript

  1. AGENDA About Me / Hackathons Hackathons / Projects Learnings /

    Tools Get Involved / Resources Contact / QA
  2. ABOUT WILLIAM Currently based in Auckland Study at Massey Uni

    & do dev contract work Enjoy travel, drawing, coding, video games
  3. ABOUT TECHNICAL Self taught Python during Art school (2011) Started

    attending hackathons & conferences Moved to Sydney worked as developer and attended hackathons
  4. WHAT ARE HACKATHONS? Friday. Meet and greet. Team forming. Pizza.

    Saturday. Working on the project. Sunday. Clearing loose ends and presenting. 48 hour research and development projects. Could be run as public or company internal event. In person or online.
  5. NASA EARTH IMAGE REQUEST import requests import os import arrow

    import shutil blogdir = '/Users/williammckee/Developer/spacegif-output' thedate = '2019-05-20' rqnat = requests.get('https://epic.gsfc.nasa.gov/api/ natural/date/' + thedate + '?api_key=DEMO_KEY') rjsn = rqnat.json() lenet = len(rjsn) somnewd = arrow.get(rjsn[0]['date']) images = [] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
  6. MERGE OF EARTH + MARS dateinput = arrow.get(thedate) foldate =

    dateinput.strftime('%Y/%m/%d') spaceimg = os.listdir('{}/galleries/{}/template/'.format(bl ranc = random.choice(os.listdir('{}/galleries/{}/rovers/'.f rancam = '{}/galleries/{}/rovers/{}/'.format(blogdir, folda fileran = random.choice(os.listdir(rancam)) ranmar = '{}/{}'.format(rancam, fileran) marimg = PIL.Image.open('{}'.format(ranmar)) marimg = marimg.resize([512,512]) marimg = marimg.convert('RGB') for spci in spaceimg: earimg = PIL.Image.open('{}/galleries/{}/template/{}'.for earimg= earimg.resize([512,512]) earimg = earimg.convert('RGB') 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
  7. INPUT TEXT & GENERATE GIF msg = 'hello apidaysau' dateinput

    = arrow.get(thedate) msgslug = msg.replace(' ', '-') spaceimg = os.listdir(blogdir + '/galleries/' + dateinput.strftime('%Y/%m/%d') + '/blend/') for spci in spaceimg: earim = PIL.Image.open(blogdir + '/galleries/' + dateinput.strftime('%Y/%m/%d') + '/blend/' + spci) earsm = earim.resize([512,512]) earimg = earsm.convert("RGBA") font = ImageFont.truetype(fontdir,42) draw = ImageDraw.Draw(earimg) image_width, image_height = earimg.size y_text = 256 lines = textwrap.wrap(msg, width=20) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
  8. TECHNICAL ME CONT. Moved back to NZ Wanted something fresh

    so learnt: Then learnt (and continue to use):
  9. GENERATING FAKE PERSON AND A CURRENCY Ellen Jacobs of Wells,

    United Kingdom | ENS func Requestperson() (string, error) { url := "https://randomuser.me/api/" res, err := http.Get(url) if err != nil { return "", err } defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil { return "", err } var data struct { Results []Person `json:"results"` } err = json.Unmarshal(body, &data) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
  10. GETTING A RANDOM COMPANY THE FAIRFIELD CHASE CENTRE PTY LTD

    func getCompanyName() (string, error) { rand.Seed(time.Now().UnixNano()) rannm := rand.Intn(3075362) + 1 url := "https://data.gov.au/data/api/3/action/datastore_s resp, err := http.Get(url) if err != nil { return "", err } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { return "", err } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
  11. LATEST AW WEBSITE VISIT & PUTTING IT TOGETHER func Requestweb()

    string { url := `http://localhost:5600/api/0/` + `buckets/aw-watcher-web-chrome/events?limit=1` res, err := http.Get(url) if err != nil { fmt.Println(err) } defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err != nil { fmt.Println(err) } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
  12. RESULT OUTPUT Wrap the function in Gin. Frontend built in

    React sends email with EmailJS. { "message": Hello, My name is Ellen Jacobs of Wells, United Kin My company is THE FAIRFIELD CHASE CENTRE PTY LTD. On Fri, 22 S 2023 05:44:19 you visited the url http://localhost:8080/body. You must send 100,000,000 ENS via this link: example.com withi 7 days. If you do not I will tell your friends and family that visited the site. Be kind, Ellen Jacobs of Wells, United Kingd }
  13. HUGMORTY So you think you can hack - May 18

    till Jun 18, 2023 AI image generator with Rick & Morty prompts
  14. GENERATE SENTENCE FROM R&M "Evolved Narnian Disguised as Morty the

    Male Humanoid from Narnia Dimension is Alive." import { NextApiRequest, NextApiResponse } from "next"; import { HfInference } from '@huggingface/inference' const hf = new HfInference(process.env.HF_ACCESS_TOKEN) import { getCharacter } from 'rickmortyapi' import { writeFileSync } from 'fs'; import { Amplify, Storage } from 'aws-amplify'; import awsconfig from '../../aws-exports'; Amplify.configure(awsconfig); export default async function handler(req: NextApiRequest, const { query: { prompt}, method, } = req; const randomChar = Math.random() * (826 - 1) + 1; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
  15. "a painting of a woman with a cat on her

    head " const fetchImg = await fetch(char.data.image) const arrayBuffer = await fetchImg.arrayBuffer(); const buffer = Buffer.from(arrayBuffer); const imgclas = await hf.imageToText({ data: buffer, model: 'nlpconnect/vit-gpt2-image-captioning' }) 1 2 3 4 5 6 7 8
  16. const imgCap = await hf.textToImage({ inputs: sentence + " "

    + imgclas.generated_text + " " + p //model: 'ogkalu/Comic-Diffusion', model: 'DucHaiten/DH_ClassicAnime' }) const aBuffer = await imgCap.arrayBuffer(); const timestamp = Number(new Date()); const fileUrl = output.input + '-' + timestamp + ".png" Storage.put(fileUrl, aBuffer, {contentType: "image/png"}); const signedURL = await Storage.get(fileUrl); res.status(200).json({'imageurl': signedURL}); 1 2 3 4 5 6 7 8 9 10 11 12 13 14
  17. LEARNINGS Great opotunity to learn new languages or libraries Collabration

    is key. Relax. Not every hackathon works out. There is always next time.
  18. HACKATHON RESOURCES Directory HackAUS - Hackathons - DevPost - Upcoming

    NASA Space Apps - October. Terrible Ideas Hackathon - 8-10 December 2023. NZ/AU/UK GovHack - August(?) 2024. https://www.hackathonsaustralia.com/ https://www.hackathons.com.au/ https://devpost.com/ https://terriblehack.com/