This file contains hidden or 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
function asyncOnce(promiseFn) { | |
let data = null; | |
let promise = null; | |
return function returnOnce(...args) { | |
if (!promise) { | |
promise = promiseFn(...args).then((promiseReturn) => { data = promiseReturn; }) | |
} | |
return data; |
This file contains hidden or 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
// ...snip | |
pub enum ClaimResult<'a> { | |
Claimed(&'a SpawnClaim), | |
ClaimedAlready(&'a SpawnClaim), | |
UnknownSpawn, | |
} | |
// ...snip | |
impl ClaimList { | |
// ...snip |
This file contains hidden or 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
for(var x = 1; x < 20; ++x) { | |
var label = ''; | |
if (x % 3 === 0) { label += 'Julia'; } | |
if (x % 5 === 0) { label += 'James'; } | |
console.log(label.length > 0 ? label : x); | |
} |
This file contains hidden or 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
pub enum Command<'a> { | |
ClaimSpawn { spawn_name: &'a str, message: Message }, | |
ClaimedList { message: Message }, | |
EstablishState { server_id: ServerId }, | |
Unknown, | |
} | |
impl<'a> Command<'a> { | |
fn from_message(message: Message) -> Self { | |
let content = message.content.trim(); |
This file contains hidden or 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
struct TreeNode<T> | |
where T: Ord | |
{ | |
value: T, | |
left: Option<Box<TreeNode<T>>>, | |
right: Option<Box<TreeNode<T>>>, | |
} | |
impl TreeNode<T> |
This file contains hidden or 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 reduceCompose = (f, g) => x => g(x, f(x)) | |
const reduceComposeArr = (...fns) => fns.reduce(reduceCompose, (x, y) => y) | |
const isNumber = (x, errors = {}) => Number.isNaN(parseInt(x, 10)) ? Object.assign({}, errors, { number: true }) : errors; | |
undefined | |
const length = (z) => (x, errors = {}) => (x && x.length < z) ? Object.assign({}, errors, { length: true }) : errors; | |
const presence = (x, errors = {}) => x === undefined ? Object.assign({}, errors, { presence: true }) : errors; | |
reduceComposeArr(presence, length(3), isNumber)('123') |
This file contains hidden or 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
// In your initialize code: | |
import React from 'react'; | |
import ReactDOM from 'react-dom'; | |
import FetchData from './fetch-data'; // Your data-fetching service. | |
import Component from './component'; | |
ReactDOM.render(<Component {...props} />, domElement, | |
function loadData() { | |
// this points to your component instance here. | |
FetchData().then(data => { |
This file contains hidden or 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
def quux | |
:quux | |
end |
This file contains hidden or 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
```ruby | |
def bar | |
:baz | |
end | |
``` |
This file contains hidden or 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
def interesting | |
[1, 2, 3].map { |x| x + 1 } | |
end |
NewerOlder