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
import * as React from "react"; | |
import { useRx, useRxTap } from "src/useRx"; | |
import { some, none } from "monas"; | |
import { AppStateContext } from "src/state/AppState"; | |
import Headers from "./headers"; | |
import Response from "./response"; | |
export default function Requestor() { | |
const appState = React.useContext(AppStateContext); | |
const [http, httpError] = useRx(appState.http$, { |
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
class BinaryHeap<T> { | |
private harr: T[] = []; | |
constructor(private lessThan: (a:T, b:T) => boolean) { | |
} | |
size() { | |
return this.harr.length; | |
} |
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
class DSU { | |
private p: number[]; | |
constructor(n: number) { | |
this.p = new Array(n).fill(0).map((_, i) => i); | |
} | |
find(x: number) { | |
while(this.p[x] !== x) { | |
x = this.p[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
use std::fmt::Debug; | |
use std::future::Future; | |
use tokio::sync::mpsc; | |
use tokio::sync::{oneshot}; | |
use tokio::sync::mpsc::{Sender, Receiver}; | |
pub enum ActorMessage<State, Action> { | |
Message(Action), | |
Reply(oneshot::Sender<State>), | |
} |
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
{time, your_func_result} = :timer.tc(&your_func/arity, [your_func-args]) | |
If you have discovered this function, please upvote the original answer by Sainik on stackoverflow here: | |
https://stackoverflow.com/questions/29668635/how-can-we-easily-time-function-calls-in-elixir |
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
export function use$<T>(subject$: BehaviorSubject<T>){ | |
const [state, setState] = React.useState<T>(subject$.value); | |
React.useEffect(() => { | |
const subscription = subject$.subscribe({ | |
next(data){ | |
setState(data) | |
} | |
}); | |
return () => { | |
subscription.unsubscribe(); |
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
class UF { | |
public vertices: Array<number>; | |
constructor(n: number) { | |
this.vertices = Array.from({length: n}, (_, i) => i); | |
} | |
union(x: number, y: number){ | |
this.vertices[this.find(x)] = this.find(y); | |
} |
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 bs(nums: number[], x: number) { | |
let left = 0; | |
let right = nums.length - 1; | |
while (left <= right) { | |
const k = Math.floor((left + right) / 2); | |
if (nums[k] === x) return k; | |
if (nums[k] < x) left = k + 1; | |
else right = k - 1; | |
} | |
return -1; |
OlderNewer