Skip to content

Instantly share code, notes, and snippets.

async function getUser(id) {
const p1 = getUserProfile(id);
const p2 = getUserSettings(id);
return {
profile: await p1,
settings: await p2,
};
}
@brigand
brigand / .js
Last active August 4, 2021 00:17
class Peekable {
constructor(iter) {
this.iter = iter;
this.deck = [];
}
peek() {
if (!this.deck.length) {
this.deck = [this.iter.next()];
}
return this.deck[0];
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",
@brigand
brigand / fetchJson.js
Created July 3, 2021 21:15
fetchJson
// 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) =>
@brigand
brigand / .rs
Last active June 25, 2021 03:56
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) {
:root {
--fg: #d5ced9;
--bg: #23262e;
--red: #ee5d43;
--purple: #c74ded;
--yellow: #ffe66d;
--font: Arial, sans;
}
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,
const Foo = () => {
const foo = useSelector(selectFoo);
const [initial] = useState(foo);
useEffect(() => {
if (foo !== initial) {
console.log('foo');
}
}, [foo]);
fn greet(name: &str) -> String {
if name.is_empty() {
// ..snip..
}
format!("Hello, {}", name)
}
fn greet(name: &str) -> String {
if name.is_empty() {
format!("Hello, {}", "whoever")
} else {
format!("Hello, {}", name)
}
}