Skip to content

Instantly share code, notes, and snippets.

View oliverjumpertz's full-sized avatar
🏠
Working from home

Oliver Jumpertz oliverjumpertz

🏠
Working from home
View GitHub Profile
@oliverjumpertz
oliverjumpertz / MyNFT.sol
Last active June 3, 2021 09:22
A basic ERC721 (NFT) implementation. Instantly runnable in remix.ethereum.org
// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;
import "https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-contracts/master/contracts/token/ERC721/ERC721.sol";
import "https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-contracts/master/contracts/utils/Counters.sol";
import "https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-contracts/master/contracts/access/AccessControl.sol";
import "https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-contracts/master/contracts/utils/Context.sol";
contract MyNFT is Context, AccessControl, ERC721 {
@oliverjumpertz
oliverjumpertz / index.js
Created January 8, 2021 08:30
Calculating the simple and exponential moving average in JavaScript
function simpleMovingAverage(prices, window = 5, n = Infinity) {
if (!prices || prices.length < window) {
return [];
}
let index = window - 1;
const length = prices.length + 1;
const simpleMovingAverages = [];
@oliverjumpertz
oliverjumpertz / simple-linear-regression.js
Created January 5, 2021 19:49
Simple linear regression implemented in JavaScript
const inputArray = [
{
squareMeters: 200,
priceInDollars: 190000
},
{
squareMeters: 100,
priceInDollars: 90000
},
{
@oliverjumpertz
oliverjumpertz / dialog.html
Created December 24, 2020 21:04
HTML native dialog
<dialog open>
<form method="dialog">
<p>Do you want to confirm your action?</p>
<div class="right">
<input class="btn" type="submit" value="Ok" />
<input class ="btn" type="submit" value="Cancel" />
</div>
</form>
</dialog>
@oliverjumpertz
oliverjumpertz / index.js
Created December 24, 2020 20:48
Switching over anything
function getCheering(followers) {
// If you were to switch over followers, you'd be surprised,
// because you'd always hit the default case.
// By switching over true, all cases get evaluated properly, although they
// contain numeric ranges!
switch (true) {
case followers >= 2000:
return "Wow, I'm speechless. I'm so happy, thank you!!!";
case followers >= 1000:
return "Wow, this is so great!";
@oliverjumpertz
oliverjumpertz / index.js
Created December 24, 2020 20:45
Iterating over values and indices with a for..of-loop
// Iterating over the array with each individual element at hand while separately
// keeping track of the index.
let i = 0;
for (const element of array) {
console.log(i++, element);
}
@oliverjumpertz
oliverjumpertz / index.js
Created December 24, 2020 20:40
Creating a vanilla dictionary
const dict = {};
dict.__proto__; // => {}
console.log(dict.hasOwnProperty); // => f hasOwnProperty() {}
const emptyDict = Object.create(null);
emptyDict.__proto__; // => undefined
emptyDict.hasOwnProperty; // => undefined
// ❗️ Anyone can modify the object prototype from the outside
@oliverjumpertz
oliverjumpertz / Dockerfile
Created December 19, 2020 13:35
Minimum contents of a project for a containerized Lambda
FROM public.ecr.aws/lambda/nodejs:12
COPY package*.json ./
RUN npm install
COPY index.js ./
CMD [ "index.handler" ]
@oliverjumpertz
oliverjumpertz / .dockerignore
Last active December 16, 2020 14:31
A Dockerfile to get your Next.js app containerized.
node_modules/
README.md
@oliverjumpertz
oliverjumpertz / once.ts
Last active May 9, 2020 17:35
once is a function wrapper that wraps another function. The wrapped function will only be executed exactly once, no matter what arguments are passed in subsequent calls.
type AnyFunc = (...args: any) => any;
export function once(func: AnyFunc): AnyFunc {
let alreadyCalled = false;
return (...args: any[]): any => {
if (alreadyCalled) {
return undefined;
}
alreadyCalled = true;