Skip to content

Instantly share code, notes, and snippets.

View SebastianUdden's full-sized avatar
:octocat:
const jsNr1 = softwareEatsWorld => webEatsSoftware => javaScriptRulesWeb => true

Sebastian Uddén SebastianUdden

:octocat:
const jsNr1 = softwareEatsWorld => webEatsSoftware => javaScriptRulesWeb => true
View GitHub Profile
from flask import Flask, jsonify
from flask_cors import CORS, cross_origin
app = Flask(__name__)
CORS(app)
@app.route('/api', methods=['GET'])
def greet():
return jsonify({'message': 'Hello python'})
@SebastianUdden
SebastianUdden / format-text-link.ts
Created September 21, 2023 08:25
formatTextLink
const uuidv4 = () =>
"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (x) => {
const random = (Math.random() * 16) | 0;
const value = x === "x" ? random : (random & 0x3) | 0x8;
return value.toString(16);
});
const copyToClipboard = (value) => {
const body = document.body;
const storage = document.createElement("textarea");
storage.value = value;
body.appendChild(storage);
storage.select();
storage.setSelectionRange(0, 99999);
document.execCommand("copy");
body.removeChild(storage);
@SebastianUdden
SebastianUdden / Add.js
Created June 14, 2022 08:24
Setup jest to work with react/typescript
// Create an initial function file
// Add.ts
const Add = (x: number, y: number) => {
return x + y;
};
export default Add;
@SebastianUdden
SebastianUdden / calendar.tsx
Created May 19, 2022 13:23
A baseline responsive calendar component
import styled from "styled-components";
import moment from "moment";
import { useState } from "react";
const firstDayOfMonth = (date: any) =>
moment(date).startOf("month").format("d");
const getBlanks = (firstDayOfMonth: number) => {
const blanks = [];
for (let i = 0; i < firstDayOfMonth; i++) {
const byName = (a, b) => {
if (a.name > b.name) return 1;
if (a.name < b.name) return -1;
return 0;
};
@SebastianUdden
SebastianUdden / swap-element-positions.js
Last active May 16, 2022 12:40
Swap element positions in an array
const handleChangePosition = (
oldIndex,
newIndex,
array
) => {
if (newIndex < 0 || newIndex > array.length - 1) return [];
const newArray = [...array];
const oldObj = array[oldIndex];
const newObj = array[newIndex];
@SebastianUdden
SebastianUdden / import-and-export-localstorage.js
Created May 13, 2022 21:43
Import and export localstorage to file for sharing and backup
const createFile = (data, filename, type) => {
const file = new Blob([data], { type: type });
var a = document.createElement("a"),
url = URL.createObjectURL(file);
a.href = url;
a.download = filename;
a.style.color = "white";
const exportEl = document.getElementById("export");
if (exportEl) {
exportEl.style.marginTop = "15px";
@SebastianUdden
SebastianUdden / save-and-get-localstorage.js
Created May 13, 2022 15:07
How to save and get localStorage data
export const getSaved = () =>
JSON.parse(localStorage.getItem("new-tag") || "{}");
export const save = (value) =>
localStorage.setItem("new-tag", JSON.stringify(value));