Skip to content

Instantly share code, notes, and snippets.

/* eslint-disable */
/******************************************
~/form/address.jsx
*/
import { service } from '~/service.js';
import { workflow } from './workflow.js';
export const Autocomplete = service.connect([workflow, 'address'])(
({ value, suggestions, onChange }) => (
@romanlex
romanlex / fetch.js
Last active June 4, 2018 11:33
Fetch multiple urls with fetch and save multiple response data
const RAW_CONTENT_TYPES = ['image/svg+xml']
/**
* Fetch url
*
* @param {string} url
*/
export const fetchResources = url => fetch(url, {
credentials: 'same-origin',
}).then((response) => {
@gaearon
gaearon / prepack-gentle-intro-1.md
Last active May 3, 2024 12:56
A Gentle Introduction to Prepack, Part 1

Note:

When this guide is more complete, the plan is to move it into Prepack documentation.
For now I put it out as a gist to gather initial feedback.

A Gentle Introduction to Prepack (Part 1)

If you're building JavaScript apps, you might already be familiar with some tools that compile JavaScript code to equivalent JavaScript code:

  • Babel lets you use newer JavaScript language features, and outputs equivalent code that targets older JavaScript engines.
@amorgun
amorgun / sample.py
Created November 10, 2017 10:51
SqlAlchemy postgres bulk upsert
from sqlalchemy.dialects import postgresql
def bulk_upsert(session: Session,
items: Sequence[Mapping[str, Any]]):
session.execute(
postgresql.insert(MyModel.__table__)
.values(items)
.on_conflict_do_update(
index_elements=[MyModel.id],
set_={MyModel.my_field.name: 'new_value'},
@artalar
artalar / SuccesBillsInput.jsx
Last active June 6, 2018 06:31
Example of styled-component good practice
// @flow
import * as React from 'react';
import styled from 'styled-components';
type Props = {
className: string,
};
@krambertech
krambertech / test-task.md
Last active May 17, 2024 09:33
Intern / Junior Front-End Developer Position @ Youscan : Test Task

Test Task for Intern / Junior Front-End Developer Position @ Youscan

Основная задача тестового не узнать как сильно вы знаете React, а посмотреть насколько хорошо вы сможете разобраться с новыми технологиями в относительно короткий срок. В идеале, на него нужно потратить не более 3 дней. А так - делайте сколько делается, пока мы не закроем вакансию ;)

Описание

Нужно написать одностраничное приложения для просмотра фильмов с помощью The Movie Database API.

При открытии приложения, должен отображаться список популярных фильмов с пагинацией или динамической подгрузкой (на выбор). Также на странице должно быть поле для поиска. Когда ты вводишь туда какой-то текст, должны отобразиться фильмы которые ему соответствуют. Для каждого фильма в списке должен отображаться список жанров (названий жанров, не айдишек), к которым он принадлежит.

@monolithed
monolithed / mocha_vs_jasmine.md
Last active January 30, 2021 18:54
Mocha vs. Jasmine

Почему Mocha, а не Jasmine?

Ниже будут приведены аргументы в пользу выбора Mocha

  • Высокая популярность:
    — 4m против 400k загузок в месяц

  • Высокая активность:
    — 1 890 против 1400 коммитов (всего)
    — 171 против 101 коммитов (последний год)

@paulirish
paulirish / what-forces-layout.md
Last active May 26, 2024 09:59
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@nolanlawson
nolanlawson / protips.js
Last active February 4, 2024 18:06
Promise protips - stuff I wish I had known when I started with Promises
// Promise.all is good for executing many promises at once
Promise.all([
promise1,
promise2
]);
// Promise.resolve is good for wrapping synchronous code
Promise.resolve().then(function () {
if (somethingIsNotRight()) {
throw new Error("I will be rejected asynchronously!");
@koistya
koistya / App.js
Last active June 8, 2022 09:55
How to add `onscroll` event in ReactJS component
import React from 'react';
let lastScrollY = 0;
let ticking = false;
class App extends React.Component {
componentDidMount() {
window.addEventListener('scroll', this.handleScroll, true);
}