Skip to content

Instantly share code, notes, and snippets.

View gillchristian's full-sized avatar
🦀
i use rust btw

Christian Gill gillchristian

🦀
i use rust btw
View GitHub Profile
fn main() {
let client = redis::Client::open("redis://127.0.0.1/").expect("Failed to connect to Redis");
let mut con = client
.get_connection()
.expect("Failed to get Redis connection");
let _ = do_something(&mut con).expect("Failed to execute Redis command");
}
fn do_something(con: &mut redis::Connection) -> redis::RedisResult<()> {
fn format_entities(text: String, entities: Vec<MessageEntityRef<'_>>) -> String {
let mut text = text;
// Raplace entities in reverse order to avoid messing up the indexes
for entity in entities.into_iter().rev() {
let start = entity.start();
let end = entity.end();
let entity_text = entity.text();
fn get_factor(x: i64) -> usize {
fn go(n: usize, x: i64) -> usize {
let x = x / 10;
if x >= 10 {
go(n + 1, x)
} else {
n + 1
}
}
const isCancelledDirectly =
cancellationReason === CANCELLATION_REASON.UNAWARE_OF_SUBSCRIPTION || CANCELLATION_REASON.MISS_DPG_TITLES;
// ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// a b c
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// d
// a === b => boolean (d)
//
// d || c => boolean | c

Keybase proof

I hereby claim:

  • I am gillchristian on github.
  • I am gillchristian (https://keybase.io/gillchristian) on keybase.
  • I have a public key whose fingerprint is 965C AF06 AB76 AABA CABA CAC5 EA14 A615 39F6 7B49

To claim this, I am signing this object:

/**
* We could use `Either<string, T>` as a validaiton result. But the problem is,
* we wouldn't be able to accumulate the errors. The `Validation` types enables
* that for us.
*
* ```ts
* type Validation<E, T> = Either<NonEmptyArray<E>, T>
* ```
*
* @example
import * as Option from "fp-ts/Option";
import * as Either from "fp-ts/Either";
import * as ArrayFP from "fp-ts/Array";
import * as TaskEither from "fp-ts/TaskEither";
import { Ord, contramap } from "fp-ts/Ord";
import { Ord as ordString, Semigroup as semigroupString } from "fp-ts/string";
import { sequenceS } from "fp-ts/Apply";
import { flow, pipe } from "fp-ts/function";
// Functor
const isPrimitive = (x) => {
const t = typeof x;
return (
t === 'string' ||
t === 'number' ||
t === 'boolean' ||
t === 'undefined' ||
t === null
);
const fs = require("fs");
const letterToNumber = {
a: 2,
b: 2,
c: 2,
d: 3,
e: 3,
f: 3,
g: 4,