Skip to content

Instantly share code, notes, and snippets.

View yogurt1's full-sized avatar
🦦

Paruyr yogurt1

🦦
View GitHub Profile
@yogurt1
yogurt1 / echo.ts
Created June 5, 2020 15:13
Laravel echo
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 August 17, 2019 23:31
mongoose graphql connection pagination
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 => {
@yogurt1
yogurt1 / vimrc
Created August 7, 2018 09:04
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
@yogurt1
yogurt1 / user.js
Created July 18, 2018 11:12
Flow wtf
// @flow
type User = {
name: string,
email: string,
phone: string,
isEmployee: boolean,
isAdmin: boolean,
};
@yogurt1
yogurt1 / JSEffect.ts
Last active July 10, 2018 11:12
JS Promise + #abort(). PS typescript
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 / vscode-sync
Created June 16, 2018 11:25
vscode sync settings
a
@yogurt1
yogurt1 / app.js
Last active June 14, 2018 20:51
Node.js async example
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 17:39
pwgen bash edition
# 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 February 19, 2018 01:45
React <Memoization />
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 November 27, 2017 10:22
webogram scroll
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