Skip to content

Instantly share code, notes, and snippets.

View dmitry's full-sized avatar
🇪🇪
Water, earth and air.

Dmitry Polushkin dmitry

🇪🇪
Water, earth and air.
View GitHub Profile
@dmitry
dmitry / plain_mail.rb
Created April 29, 2016 11:49
Use ActionMailer config to send plain through plain Mail
Mail.defaults do
delivery_method ActionMailer::Base.delivery_method, ActionMailer::Base.smtp_settings
end
mail = Mail.deliver do
to 'dmitry.polushkin@gmail.com'
from 'Mikel Lindsaar <test@9flats.com>'
subject 'First multipart email sent with Mail'
text_part do
@dmitry
dmitry / trackable_links.rb
Last active December 2, 2015 13:35
Add trackable links
@dmitry
dmitry / what-forces-layout.md
Created September 23, 2015 15:28 — forked from paulirish/what-forces-layout.md
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.

Element

Box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
  • elem.clientLeft, elem.clientTop, elem.clientWidth, elem.clientHeight
  • elem.getClientRects(), elem.getBoundingClientRect()
@dmitry
dmitry / Enhance.js
Last active September 17, 2015 12:04 — forked from sebmarkbage/Enhance.js
Higher-order Components
import { Component } from "React";
export var Enhance = ComposedComponent => class extends Component {
constructor() {
this.state = { data: null };
}
componentDidMount() {
this.setState({ data: 'Hello' });
}
render() {
@dmitry
dmitry / alternative-to-higher-order-components.md
Last active September 17, 2015 12:04 — forked from aldendaniels/alternative-to-higher-order-components.md
Alternative to Higher-order Components

React now supports the use of ES6 classes as an alternative to React.createClass().

React's concept of Mixins, however, doesn't have a corollary when using ES6 classes. This left the community without an established pattern for code that both handles cross-cutting concerns and requires access to Component Life Cycle Methods.

In this gist, @sebmarkbage proposed an alternative pattern to React mixins: decorate components with a wrapping "higher order" component that handles whatever lifecycle methods it needs to and then invokes the wrapped component in its render() method, passing through props.

While a viable solution, this has a few drawbacks:

  1. There's no way for the child component to override functionality defined on the higher order component.
@dmitry
dmitry / parent_controller_path.rb
Created August 13, 2015 12:15
Parent controller path through recognize_path
class ParentControllerPath
SEGMENT = '/'
attr_reader :path, :found
class << self
def routes
Rails.application.routes
end
end