This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function getUser(id) { | |
const p1 = getUserProfile(id); | |
const p2 = getUserSettings(id); | |
return { | |
profile: await p1, | |
settings: await p2, | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Peekable { | |
constructor(iter) { | |
this.iter = iter; | |
this.deck = []; | |
} | |
peek() { | |
if (!this.deck.length) { | |
this.deck = [this.iter.next()]; | |
} | |
return this.deck[0]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) => |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:root { | |
--fg: #d5ced9; | |
--bg: #23262e; | |
--red: #ee5d43; | |
--purple: #c74ded; | |
--yellow: #ffe66d; | |
--font: Arial, sans; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Foo = () => { | |
const foo = useSelector(selectFoo); | |
const [initial] = useState(foo); | |
| |
useEffect(() => { | |
if (foo !== initial) { | |
console.log('foo'); | |
} | |
}, [foo]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn greet(name: &str) -> String { | |
if name.is_empty() { | |
// ..snip.. | |
} | |
format!("Hello, {}", name) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn greet(name: &str) -> String { | |
if name.is_empty() { | |
format!("Hello, {}", "whoever") | |
} else { | |
format!("Hello, {}", name) | |
} | |
} |
NewerOlder