Skip to content

Instantly share code, notes, and snippets.

🌵

Paruyr yogurt1

🌵
Block or report user

Report or block yogurt1

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@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 / 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
@yogurt1
yogurt1 / Chat.js
Last active Dec 14, 2016
Chat in pure Node.js at backend and Vanilla.js at frontend
View Chat.js
var http = require("http");
var msgs = []; // All messages array
var subscribers = []; // All subscribers array
var PORT = process.env.PORT || 8080;
// Create HTTP server
var server = http.createServer(function(req, res) {
// Small router
switch(req.url) {
case "/":
@yogurt1
yogurt1 / babel.preset.js
Created Dec 4, 2016
my custom babel preset
View babel.preset.js
const preset = buildPreset()
Object.defineProperty(preset, "buildPreset", {
configurable: true,
writable: true,
enumerable: false,
value: buildPreset
})
module.exports = preset
function buildPreset(opts = {}) {
You can’t perform that action at this time.