Skip to content

Instantly share code, notes, and snippets.

View beardlessman's full-sized avatar

Dmitrii Mungalov beardlessman

View GitHub Profile
@beardlessman
beardlessman / interviewTasks.js
Last active March 30, 2019 09:57
Собеседование Леши: замыкания, промисы, прототипы
// Отметить идентификаторы, доступные через замыкания
// Ответ: weapon, name
function Samurai(name) {
var weapon = 'katana';
this.getWeapon = function() {
return weapon;
};
this.getName = function() {
return name;
@beardlessman
beardlessman / classof.js
Created March 30, 2019 09:41
Возвращает класс объекта
const classof = object => Object.prototype.toString.call(object).slice(8, -1);
@beardlessman
beardlessman / socket-io-emit.js
Created April 17, 2019 05:51
Выбираем, кому эмитить событие
// ответить
// текущему клиенту
socket.emit(EVENT_NAME, data);
// клиентам этой сессии
const sockets = io.sockets.sockets;
const clients = Object.keys(sockets);
clients.forEach(client => {
if (sockets[client].handshake.sid !== socket.handshake.sid) return;
sockets[client].emit(EVENT_NAME, data);
});
// SERVER
const axios = require('axios');
module.exports = () => {
const io = require('socket.io')();
io.listen(3000);
io.on('connection', function(socket) {
socket.on('SEARCH_REQUEST', query => {
axios
const metadata = {
title: 'Scratchpad',
translations: [
{
locale: 'de',
title: 'Javascript-Umgebung'
}
],
url: '/en-US/dosc/Tools/Scratchpad'
};
const propertyActions = [
{
name: 'body',
check: arg => typeof arg === 'string'
},
{
name: 'children',
check: arg => arg instanceof Array
},
{
@beardlessman
beardlessman / print.js
Created June 4, 2019 01:22
.toString() энкодит utf-8?
import fs from 'fs';
const print1 = path => {
fs.readFile(path, (err, content) => console.log(content.toString()));
}
const print2 = path => fs.readFile(
path,
'utf-8',
(error, data) => console.log(data),
@beardlessman
beardlessman / hookExample.js
Created September 4, 2019 06:50
react hook example, flow
//@flow
import React, { useState, useEffect } from 'react';
type IProps = {
initial?: number,
};
export default function HookExample({ initial = 0 }: IProps) {
const [fuckingCount, setFuckingCount] = useState(initial);
import React, { useState, useEffect } from 'react';
function useFriendStatus(friendID) {
const [isOnline, setIsOnline] = useState(null);
function handleStatusChange(status) {
setIsOnline(status.isOnline);
}
useEffect(() => {
@beardlessman
beardlessman / ProfileSelectWithHooks.tsx
Created April 14, 2020 06:05
Profile Select With Hooks
import { Select, Spin } from 'antd';
import { IProfile } from 'modules/user/types';
import React, { useState } from 'react';
import debounce from 'lodash/debounce';
import uniqWith from 'lodash/uniqWith';
const { Option } = Select;
interface IResponse {