Skip to content

Instantly share code, notes, and snippets.

Avatar
🌵

Paruyr yogurt1

🌵
View GitHub Profile
View echo.ts
export class Echo implements IEcho {
readonly #socketServerUrlSubject = new BehaviorSubject<string | null>(null);
readonly #authHeadersSubject = new BehaviorSubject<Record<string, string> | null>(null);
readonly #channelsSubscriber = new ChannelSubscriber();
readonly #socket$ = this.#socketServerUrlSubject.pipe(
distinctUntilChanged(),
switchMap(socketServerUrl => {
if (!socketServerUrl) {
return EMPTY;
@yogurt1
yogurt1 / paginate-pluigin.js
Created Aug 17, 2019
mongoose graphql connection pagination
View paginate-pluigin.js
const { Buffer } = require('buffer');
const encodeCursor = (item, field) => {
const value = item[field];
const json = JSON.stringify(value);
const base64 = Buffer.from(json).toString('base64');
return base64;
};
const decodeCursor = cursor => {
View vimrc
let g:vitality_always_assume_iterm = 1
let g:indent_guides_start_level = 2
let g:indent_guides_enable_on_vim_startup = 1
let g:pencil_neutral_code_bg = 0
let g:pencil_neutral_headings = 0
let g:pencil_higher_contrast_ui = 1
let g:pencil_terminal_italics = 1
let g:pencil_gutter_color = 1
View user.js
// @flow
type User = {
name: string,
email: string,
phone: string,
isEmployee: boolean,
isAdmin: boolean,
};
@yogurt1
yogurt1 / JSEffect.ts
Last active Jul 10, 2018
JS Promise + #abort(). PS typescript
View JSEffect.ts
type CancelFn = () => void;
type SideEffect<T> = (onCancel: (cancelFn: CancelFn) => void) => Promise<T>;
type Reject = (error: Error) => void;
class CancelError extends Error {
readonly cancelled = true;
}
const rejectOnce = (reject: Reject): Reject => {
let called = false;
@yogurt1
yogurt1 / app.js
Last active Jun 14, 2018
Node.js async example
View app.js
const http = require('http');
const port = process.env.PORT || 3000;
const reqsCount = 50; // Number of requests
const server = http
.createServer((req, res) => {
setTimeout(() => {
res.end(`<h1>EXPENSIVE</h1>`);
}, 1500);
})
@yogurt1
yogurt1 / pwgen.sh
Last active May 14, 2018
pwgen bash edition
View pwgen.sh
# How to use: sh pwgen.sh <password length, default 9>
_LENGTH=9
if test x"$@" != x
then _LENGTH="$@"
fi
cat /dev/urandom |\
tr -dc 'A-Za-z0-9' |\
fold -w $_LENGTH |\
#-w 20 |\
@yogurt1
yogurt1 / Memoization.jsx
Last active Feb 19, 2018
React <Memoization />
View Memoization.jsx
import React from 'react';
import PropTypes from 'prop-types';
class Memoization extends React.Component {
lastInput = null;
result = null;
render() {
const { equals, input, compute, children } = this.props;
@yogurt1
yogurt1 / ui-height.js
Last active Nov 27, 2017
webogram scroll
View ui-height.js
var atBottom = true
var scrollTopInitial = -1
$(scrollableWrap).on('scroll', function (e) {
if (!element.is(':visible') ||
$(scrollableWrap).hasClass('im_history_to_bottom') ||
curAnimation) {
return
}
var st = scrollableWrap.scrollTop
atBottom = st >= scrollableWrap.scrollHeight - scrollableWrap.clientHeight
You can’t perform that action at this time.