Skip to content

Instantly share code, notes, and snippets.

View .js
import React, { useState } from "react";
import styled from "styled-components";
import { Button, Form } from 'semantic-ui-react'
const PatientDetails = () => {
const [details, setDetails] = useState({
name: "John Doe",
gender: "male",
age: 34,
referredBy: "self",
View fetchJson.js
// Based on: https://jsfiddle.net/t2g9ub43/1/
const fetchJson = async (url, { ...opts } = {}) => {
opts.headers = new Headers(opts.headers);
opts.headers.set('Accept', 'application/json');
return fetch(url, opts).then((resp) => {
const ct = resp.headers.get('content-type');
if (!ct || !ct.includes('application/json')) {
throw resp;
}
return resp.json().then((json) =>
View .rs
ErrorMime::JavaScript => format!(
"{pre}{json};\nlet css = {css_json};\n{code}\n{close}",
json = get_json(),
pre = "{ let error_json = ",
close = "}",
code = indoc::indoc!(r#"
const h = (tag, {style, ...props}, ...children) => {
const element = Object.assign(document.createElement(tag), props);
Object.assign(element.style, style);
for (const child of children) {
View .css
:root {
--fg: #d5ced9;
--bg: #23262e;
--red: #ee5d43;
--purple: #c74ded;
--yellow: #ffe66d;
--font: Arial, sans;
}
View http_error.rs
use std::fmt::Display;
use actix_web::{http::StatusCode, HttpResponse};
use serde_json::{json, to_string};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ErrorMime {
Json,
Html,
JavaScript,
View .js
const Foo = () => {
const foo = useSelector(selectFoo);
const [initial] = useState(foo);
useEffect(() => {
if (foo !== initial) {
console.log('foo');
}
}, [foo]);
View bad.rs
fn greet(name: &str) -> String {
if name.is_empty() {
// ..snip..
}
format!("Hello, {}", name)
}
View .rs
fn greet(name: &str) -> String {
if name.is_empty() {
format!("Hello, {}", "whoever")
} else {
format!("Hello, {}", name)
}
}
View .js
const create = sessionUser => data => Promise.try(() => transaction(model, async (modelTransaction) => {
const { CAN_CREATE_ORGANIZATIONS } = getPermissions(sessionUser.permissions);
const { userId } = sessionUser;
const { avatar, ...orgData } = data;
if (!CAN_CREATE_ORGANIZATIONS) {
throw Unauthorized({ message: 'Sie haben nicht das Recht Organisationen zu erstellen' });
}
const insert = params => modelTransaction.query()
View .js
let estate;
let signed;
let watches;
function getImagesAndServePages() {
estate = require('fs').readdirSync('./public/imgs/estate');
signed = require('fs').readdirSync('./public/imgs/signed');
watches = require('fs').readdirSync('./public/imgs/watches');