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 / .irbrc.rb
Created April 8, 2010 15:50 — forked from dekart/.irbrc.rb
# Put this content to ~/.irbrc file (no extension)
require "rubygems"
begin
require "ap"
rescue LoadError => err
puts "Cannot find awesome_print gem. Please run 'gem install awesome_print' to install it."
end
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new # guest user
if user.role? :admin
can :manage, :all
else
can :read, :all
module FormtasticExtensions
module Formtastic
module TextileEditor
def self.included(base)
base.class_eval do
@javascript_included = false
end
end
@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 / 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 / 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()
// Allows you to specify events on the data tied to the view in the same way
// that you can specify dom events:
//
// dataEvents: {
// instanceName: {
// 'change:name': 'mothed',
// delete: 'otherMethod'
// }, ...
// }
registerDataEvents: function(unbind) {
@dmitry
dmitry / gist:1296732
Created October 18, 2011 21:09
Creating a Backbone.js View Manager
/**
Big thanks to Derick Bailey for his post here:
http://lostechies.com/derickbailey/2011/09/15/zombies-run-managing-page-transitions-in-backbone-apps/
*/
(function(Account) {
/** LOTS OF MODEL, COLLECTION, AND VIEW CREATION GOING ON UP HERE, LEFT IT OUT FOR SIMPLICITY */
/**
* Define Routing.
@dmitry
dmitry / gist:1394872
Created November 26, 2011 02:50 — forked from avalanche123/gist:981817
GitHub Emoji
:+1:
:-1:
:airplane:
:art:
:bear:
:beer:
:bike:
:bomb:
:book:
:bulb:
namespace :routes do
desc "Writes doc/routes.html. Requires Graphviz (dot)"
task :visualizer => :environment do
File.open(Rails.root.join('doc', 'routes.html'), 'wb') do |f|
f.write Rails.application.routes.router.visualizer
end
end
end