Sometimes we need to share props and behaviour between multiple components/containers. For that we can do a higher order component. Example:
Higher Order Component that will decorate other component:
| require "net/http" | |
| require "uri" | |
| class MultipartPost | |
| BOUNDARY = "-----------RubyMultipartPost" | |
| EOL = "\r\n" | |
| def initialize uri, &block | |
| @params = Array.new | |
| @uri = URI.parse uri | |
| instance_eval &block if block |
| var mediaJSON = { "categories" : [ { "name" : "Movies", | |
| "videos" : [ | |
| { "description" : "Big Buck Bunny tells the story of a giant rabbit with a heart bigger than himself. When one sunny day three rodents rudely harass him, something snaps... and the rabbit ain't no bunny anymore! In the typical cartoon tradition he prepares the nasty rodents a comical revenge.\n\nLicensed under the Creative Commons Attribution license\nhttp://www.bigbuckbunny.org", | |
| "sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" ], | |
| "subtitle" : "By Blender Foundation", | |
| "thumb" : "images/BigBuckBunny.jpg", | |
| "title" : "Big Buck Bunny" | |
| }, | |
| { "description" : "The first Blender Open Movie from 2006", | |
| "sources" : [ "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ElephantsDream.mp4" ], |
| require 'net/http' | |
| class HttpClient | |
| def initialize(base_url, username = nil, password = nil) | |
| @base_url = base_url | |
| @username = username | |
| @password = password | |
| end | |
| def get(path, headers = {}) |
| # Takes a hash of string and file parameters and returns a string of text | |
| # formatted to be sent as a multipart form post. | |
| # | |
| # Author:: Cody Brimhall <mailto:cbrimhall@ucdavis.edu> | |
| # Created:: 22 Feb 2008 | |
| # Licensed under the WFTPL - http://stackoverflow.com/questions/184178/ruby-how-to-post-a-file-via-http-as-multipart-form-data | |
| # http://sam.zoy.org/wtfpl/ | |
| require 'rubygems' | |
| require 'mime/types' |
| from PIL import Image, ImageChops | |
| def trim(im, border): | |
| bg = Image.new(im.mode, im.size, border) | |
| diff = ImageChops.difference(im, bg) | |
| bbox = diff.getbbox() | |
| if bbox: | |
| return im.crop(bbox) | |
| def create_thumbnail(path, size): |