Skip to content

Instantly share code, notes, and snippets.

View john-reed.rs
#![feature(proc_macro_hygiene, decl_macro)]
#[macro_use]
extern crate rocket;
extern crate chrono;
extern crate reqwest;
use anyhow::Result;
use chrono::{Duration, Local};
use redis::{Commands, Connection};
View john-reed.py
import requests
import json
import http.server
import socketserver
from http import HTTPStatus
import redis
from datetime import datetime
from urllib.parse import urlparse
import urllib.parse as urlparse
from urllib.parse import parse_qs
@auryn31
auryn31 / osx_bootstrap.sh
Last active Apr 23, 2021 — forked from codeinthehole/osx_bootstrap.sh
Script to install stuff I want on a new OSX machine
View osx_bootstrap.sh
#!/usr/bin/env bash
#
# Bootstrap script for setting up a new OSX machine
#
# This should be idempotent so it can be run multiple times.
#
# Apps without brew installation:
# - Magnet https://magnet.crowdcafe.com https://apps.apple.com/app/id441258766?mt=12
#
#
View response.json
{
"_links": {
"self": {
"href": "http://localhost:8080/users/51"
},
"users": {
"href": "http://localhost:8080/users"
}
},
"id": 51,
View UserController.kt
@GetMapping("/users/{id}")
fun specificUser(@PathVariable id: Int): ResponseEntity<EntityModel<User>> {
if(dataBean.users.filter { it.id == id }.isEmpty()){
return ResponseEntity(HttpStatus.NOT_FOUND)
}
return ResponseEntity(EntityModel(dataBean.users.filter { it.id == id }.first(),
linkTo(methodOn(UserController::class.java).specificUser(id)).withSelfRel(),
linkTo(methodOn(UserController::class.java).allUsers()).withRel("users")), HttpStatus.OK)
}
View block6.bash
serverless invoke local --function price --data '{"queryStringParameters":{"url":"https://www.amazon.de/Raspberry-Pi-ARM-Cortex-A72-Bluetooth-Micro-HDMI/dp/B07TC2BK1X/"}}'
View block5.js
const axios = require('axios').default;
const JSDOM = require('jsdom').JSDOM;
module.exports.price = async event => {
if(event.queryStringParameters == undefined || event.queryStringParameters.url == undefined) {
return {
statusCode: 404,
body: JSON.stringify({
message: "You forgot the URL parameter!"
})
View block2.js
const axios = require('axios').default;
module.exports.price = async event => {
var encoded_url = encodeURI("https://www.amazon.de/Raspberry-Pi-ARM-Cortex-A72-Bluetooth-Micro-HDMI/dp/B07TC2BK1X");
const res = await axios.get(encoded_url);
return {
statusCode: res.status,
body: JSON.stringify({
title: "PLACEHOLDER",
price: 0.0
View block3.js
const axios = require('axios').default;
const JSDOM = require('jsdom').JSDOM;
module.exports.price = async event => {
var encoded_url = encodeURI("https://www.amazon.de/Raspberry-Pi-ARM-Cortex-A72-Bluetooth-Micro-HDMI/dp/B07TC2BK1X");
const res = await axios.get(encoded_url);
const document = new JSDOM(res.data).window.document;
const title_with_whitespace = document.querySelector("#productTitle").textContent;
View block4.js
{
"statusCode": 200,
"body": "{\"title\":\"Raspberry Pi 4 Modell B 4GB ARM-Cortex-A72 4X 1,50GHz, 4GB RAM, WLAN-ac, Bluetooth 5, LAN, 4X USB, 2X Micro-HDMI\",\"price\":\"65.90\"}"
}