Skip to content

Instantly share code, notes, and snippets.

View maxfarseer's full-sized avatar

Max P maxfarseer

View GitHub Profile
@maxfarseer
maxfarseer / Easy javascript loader
Last active February 17, 2016 07:48
Javascript promise loader
//https://davidwalsh.name/javascript-loader
var load = (function() {
// Function which returns a function: https://davidwalsh.name/javascript-functions
function _load(tag) {
return function(url) {
// This promise will be used by Promise.all to determine success or failure
return new Promise(function(resolve, reject) {
var element = document.createElement(tag);
var parent = 'body';
// won't work correctly
let counter = 0;
function delay(ms) {
return new Promise((resolve, reject) => {
setTimeout(function() {
console.log(++counter)
resolve()
@maxfarseer
maxfarseer / connect.js
Created May 17, 2016 07:47 — forked from gaearon/connect.js
connect.js explained
// connect() is a function that injects Redux-related props into your component.
// You can inject data and callbacks that change that data by dispatching actions.
function connect(mapStateToProps, mapDispatchToProps) {
// It lets us inject component as the last step so people can use it as a decorator.
// Generally you don't need to worry about it.
return function (WrappedComponent) {
// It returns a component
return class extends React.Component {
render() {
return (
let id;
beforeEach(done => {
id = mongoose.Types.ObjectId()
done()
})
nock(`${API_ROOT_V1}`)
.log(console.log)
.post('/api/v1/providers/add', {name: 'User', phone: '+7-123-45-67-89'})
.reply(200, { status: 200, data: '574ad7429a59dcd429adfc32' })
@maxfarseer
maxfarseer / api-cheatsheet-array.md
Last active April 9, 2018 15:54 — forked from rauschma/api-cheatsheet-array.md
Шпаргалка по API массивов

Array<T>

<T> = iterable (то есть, что-то перечисляемое, доступное для перебора)

Легенда:

  • ✏️ метод изменяет this.
  • 🔒 метод не изменяет this.

Array.prototype.*:

_renderChapter({ name }) {
return (
<View key={name} style={styles.chapter}>
<Text small style={styles.chapterText}>
{name}
</Text>
<View style={styles.chapterLine} />
</View>
);
}
@maxfarseer
maxfarseer / tz2-back-routes.js
Last active April 30, 2018 07:07
Routes для создания бэкэнда к тестовому заданию 2
// Корневой адрес API: https://mysterious-reef-29460.herokuapp.com/api/v1
// POST /validate (введены корректные данные: username = 'max', password = '12345'
{
"status": "ok",
"data": {
"id": 1
}
}
@maxfarseer
maxfarseer / comprehensive-guide-tyler-1
Created May 6, 2018 04:59
Код для статьи A Comprehensive Guide to React.js in 2018 1
JSX. Позволяет нам писать HTML как синтаксис, который преобразуется в объекты lightweightJavaScript.
Виртуальный DOM (Virtual DOM) — JavaScript-представление реального DOM.
React.Component — способ создания нового компонента.
render (method) — описывает, как будет выглядеть пользовательский интерфейс
для конкретного компонента.
ReactDOM.render — выполняет рендер React-компонента на узел (node) DOM.
@maxfarseer
maxfarseer / comprehensive-guide-tyler-2.js
Created May 6, 2018 05:01
Код для статьи A Comprehensive Guide to React.js in 2018 2
import React from 'react'
import ReactDOM from 'react-dom'
class HelloWorld extends React.Component {
render() {
return (
<div>Hello World!</div>
)
}
}
ReactDOM.render(<HelloWorld />, document.getElementById('root'));