Skip to content

Instantly share code, notes, and snippets.

View renanvalentin's full-sized avatar

Renan Valentin renanvalentin

  • São José do Rio Preto
View GitHub Profile
import collections
class SimpleGraph:
def __init__(self):
self.edges = {}
def neighbors(self, id):
return self.edges[id]
export type Channel = {
on(event : string, listener : Function): *
};
export type Subscriber = {
listener(config : { window : HTMLIFrameElement, domain : string }): Channel
};
const subscribe = (channel : Channel) => {
let listeners = {};
@renanvalentin
renanvalentin / patch.js
Created June 8, 2017 19:33
ReactDOM.findDOMNode monkey patch
const ReactDOM = require('react-dom');
const findDOMNode = ReactDOM.findDOMNode;
ReactDOM.findDOMNode = (component) => {
if (findDOMNode) {
return findDOMNode(...args);
}
if(!component.container) {
@renanvalentin
renanvalentin / polyfills.js
Last active June 29, 2017 18:24
Storybook's jsdom setup
var mockWebSocket = require('mock-socket').WebSocket;
/* globals window, document */
const jsdom = require('jsdom').jsdom;
global.document = jsdom('');
global.window = document.defaultView;
Object.keys(document.defaultView).forEach((property) => {
if (typeof global[property] === 'undefined') {
global[property] = document.defaultView[property];
defmodule LearningElixir.Router.Test do
use ExUnit.Case, async: true
use Plug.Test
alias LearningElixir.Router
@opts Router.init([])
test "returns hello text" do
response = conn(:get, "/")
defmodule LearningElixir do
use Application
# See http://elixir-lang.org/docs/stable/elixir/Application.html
# for more information on OTP Applications
def start(_type, _args) do
import Supervisor.Spec, warn: false
children = [
# Define workers and child supervisors to be supervised
defmodule LearningElixir.Router do
use Plug.Router
plug :match
plug :dispatch
get "/" do
send_resp(conn, 200, "Hello")
end
def run do
{:ok, _} = Plug.Adapters.Cowboy.http LearningElixir.Router, []
end
def start(_type, _args) do
import Supervisor.Spec, warn: false
children = [
# Define workers and child supervisors to be supervised
# worker(LearningElixir.Worker, [arg1, arg2, arg3]),
Plug.Adapters.Cowboy.child_spec(:http, LearningElixir.Router, [], [port: 4001])
]
# See http://elixir-lang.org/docs/stable/elixir/Supervisor.html