TIL that the _OSI function serves a similar purpose to User-Agent strings. Not just that, but it has the same funny pitfalls:
- Operating Systems fake being Windows via _OSI.
- Browsers fake being each other via UA.
type numeric = number | bigint | |
const num_guard = (x: unknown): x is numeric => | |
typeof x == 'number' || typeof x == 'bigint' | |
const num_cond = <T,>(x: T) => ( | |
typeof x == 'number' || typeof x == 'bigint' | |
) as T extends numeric ? true : false | |
// this example is incomplete, |
pub fn trampoline<F, A, C, T>(f: F, args: A) -> T | |
where | |
F: FnOnce(A) -> Result<C, T>, | |
C: FnOnce() -> Result<C, T>, | |
{ | |
let mut out = f(args); | |
// `while let` would require an awkward | |
// `if let Err(x) return x; unreachable!()` at the end. | |
// https://users.rust-lang.org/t/is-there-any-way-to-express-while-let-some-true/72527/2 | |
loop { |
// boilerplate | |
class BigUint { | |
/** Zero */ | |
static N0() { | |
return new BigUint(0n) | |
} | |
/** One */ | |
static N1() { | |
return new BigUint(1n) | |
} |
#![no_std] | |
/// if `cond` is `true`, then `identity(x)` | |
/// | |
/// if `cond` is `false` then `drop(x)` | |
pub fn cond_ident<T>(cond: bool, x: T) -> Option<T> { | |
if cond { | |
Some(x) | |
} else { | |
None |
#![warn(clippy::pedantic, clippy::nursery)] | |
use core::iter::successors; | |
use num_integer::{Integer, Roots}; //0.1 | |
pub fn divisors_fast<T: Integer + Roots + Clone>(x: &T) -> Vec<T> { | |
let sq = x.sqrt(); | |
let mut divs = Vec::new(); | |
let n1 = T::one(); |
use num_integer::Integer; // 0.1 | |
#[derive(Copy, Clone, Eq, PartialEq, Debug)] | |
enum S { | |
F, | |
B, | |
FB, | |
} | |
fn fb<T: Integer>(n: &T) -> Option<S> { |
fn main(){let mut n=7usize;while n!=0{print!("{n} ");n=[n*3+1,n/2][n%2]}} |
def fn(x, n): | |
return (x/n + x*n) / 2 |
#!/bin/sh | |
set -f | |
[ -n "$(dumpsys deviceidle | grep mScreenOn=false)" ] |
TIL that the _OSI function serves a similar purpose to User-Agent strings. Not just that, but it has the same funny pitfalls: