(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
package main | |
import ( | |
"context" | |
"flag" | |
"fmt" | |
"log" | |
"net/http" | |
"os" | |
"os/signal" |
// https://github.com/alfonsomunozpomer/react-fetch-mock | |
import React from 'react' | |
import fetchMock from 'fetch-mock' | |
import Enzyme from 'enzyme' | |
import {shallow, mount, render} from 'enzyme' | |
import Adapter from 'enzyme-adapter-react-16' | |
Enzyme.configure({ adapter: new Adapter() }) |
var BlogComments = {} | |
BlogComments.controller = function (options) { | |
App.state.fetch('blogComments', `/api/blog-post/${ options.blog_id }/comments`) | |
} | |
BlogComments.view = function (ctrl, options) { | |
var comments = App.state.blogComments | |
return m('.blog-comments-component', [ |
'use strict'; | |
var m = require('mithril'); | |
var icons = require('client/utils/icons'); | |
var remove = require('lodash/array/remove'); | |
var transform = require('lodash/object/transform'); | |
var last = require('lodash/array/last'); | |
var code = require('yields-keycode'); | |
function sameAs(filterA) { |
/* Expects month to be in 1-12 index based. */ | |
var monthInformation = function(year, month){ | |
/* Create a date. Usually month in JS is 0-11 index based but here is a hack that can be used to calculate total days in a month */ | |
var date = new Date(year, month, 0); | |
/* Get the total number of days in a month */ | |
this.totalDays = date.getDate(); | |
/* End day of month. Like Saturday is end of month etc. 0 means Sunday and 6 means Saturday */ | |
this.endDay = date.getDay(); | |
date.setDate(1); | |
/* Start day of month. Like Saturday is start of month etc. 0 means Sunday and 6 means Saturday */ |
/* bling.js */ | |
window.$ = document.querySelectorAll.bind(document); | |
Node.prototype.on = window.on = function (name, fn) { | |
this.addEventListener(name, fn); | |
} | |
NodeList.prototype.__proto__ = Array.prototype; |
m.validator = function (model, validations) { | |
this.errors = {} | |
this.validations = validations | |
this.model = model | |
} | |
m.validator.prototype.hasErrors = function () { | |
return Object.keys(this.errors).length | |
} |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
r := mux.NewRouter() | |
// Single handler | |
r.HandleFunc("/form", use(http.HandlerFunc(formHandler), csrf, logging) | |
// All handlers | |
http.Handle("/", recovery(r)) | |
// Sub-routers | |
apiMiddleware := []func(http.Handler) http.Handler{logging, apiAuth, json} |
##Userable | |
module Userable | |
def self.included(base) | |
base.has_one :user, :as => :userable, :dependent => :destroy, :autosave => true | |
base.validate :user_must_be_valid | |
base.alias_method_chain :user, :autobuild | |
base.extend ClassMethods | |
base.define_user_accessors | |
end | |