Skip to content

Instantly share code, notes, and snippets.

View esshka's full-sized avatar
🏠
Working from home

Eugeny esshka

🏠
Working from home
View GitHub Profile

This is an example of how I combine interaction/service classes with Wisper event broadcasting in Rails.

In this example, I show a UsersController#create API, a corresponding service object, and all the test code/listeners to make it all happen.

The outcome is:

  • Concepts in your system ("Signing up a user", "Creating an order") have a single entry point in your codebase, vs. making stupid raw ActiveRecord calls to object.save in dozens of places.
  • Since your concept has one entry point (the service class), you can easily grep for usage of it.
  • Stupid easy to attach listeners to the service class
  • All event listeners are very small and easily unit tested
@esshka
esshka / Enhance.js
Last active August 29, 2015 14:26 — 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() {
@esshka
esshka / bootstrapping.md
Last active September 7, 2015 16:51 — forked from dideler/bootstrapping.md
Bootstrapping - a list of useful resources to get up and running quickly

Welcome!

For feedback or suggestions, please send a tweet (@dideler). Gist comments don't notify me. Pull requests aren't possible with gists (yet), so I don't recommend forking because then I can't easily get the change.

Starring this gist will give me an idea of how many people consider this list useful.


  • OpenStrategy - kinda like this list, but much nicer presentation
@esshka
esshka / gist:8bd240695203f7b856bf
Last active September 7, 2015 18:23 — forked from igorpavlov-zz/gist:18af35999f8c7838cf21
AppRTC main JS code
var RTCPeerConnection = null;
var getUserMedia = null;
var attachMediaStream = null;
var reattachMediaStream = null;
var webrtcDetectedBrowser = null;
var webrtcDetectedVersion = null;
function trace(text) {
if (text[text.length - 1] === "\n") {
text = text.substring(0, text.length - 1);

Default Rendering

By default, controllers in Rails automatically render views with names that correspond to valid routes.

For example, if you have this code in your BooksController class:

class BooksController < ApplicationController
end
@esshka
esshka / # Sublime Emmet JSX Reactjs.md
Created January 22, 2016 09:52 — forked from max-mykhailenko/# Sublime Emmet JSX Reactjs.md
Sublime text 3. Enable Emmet in JSX files with Sublime React plugin

Problem

  • Using emmet in jsx files
  • Emmet expands text when js autocomplete needed
  • Using className instead of class

How it works

  • Install plugin RegReplace
  • Install plugin Chain Of Command
@esshka
esshka / destructuring.js
Created February 10, 2016 11:50 — forked from mikaelbr/destructuring.js
Several demos and usages for ES6 destructuring.
// === Arrays
var [a, b] = [1, 2];
console.log(a, b);
//=> 1 2
// Use from functions, only select from pattern
var foo = () => {
return [1, 2, 3];
@esshka
esshka / inheritance.clj
Created February 16, 2016 18:14 — forked from david-mcneil/inheritance.clj
Demonstration of implementation "inheritance" in clojure
;; Define a "base type" of Dog
(defrecord Dog [breed])
;; Define a "sub type" of TrainedDog
(defrecord TrainedDog [dog word])
;; The interface that both Dog and TrainedDog will implement
(defprotocol Talker
(bark [_])
(speak [_])
@esshka
esshka / gist:11dc9db2c1a2b2c2b160
Created February 29, 2016 12:52 — forked from jacqui/gist:983051
Redis SORT command examples
# Optimized for writes, sort on read
# LVC
redis.hset("bonds|1", "bid_price", 96.01)
redis.hset("bonds|1", "ask_price", 97.53)
redis.hset("bonds|2", "bid_price", 95.50)
redis.hset("bonds|2", "ask_price", 98.25)
redis.sadd("bond_ids", 1)
redis.sadd("bond_ids", 2)
@esshka
esshka / react-testing-in-rails.diff
Created April 12, 2016 00:19 — forked from jakecraige/react-testing-in-rails.diff
Simple react component testing in rails + capybara
commit 074a79b95e66d999abe500051c5337805575ea3f
Author: Jake Craige <[email protected]>
Date: Tue Apr 7 10:14:29 2015 -0700
Add testing infastructure for React components
diff --git a/app/controllers/components_controller.rb b/app/controllers/components_controller.rb
new file mode 100644
index 0000000..4ffc308
--- /dev/null