This directive allows you to write you modal windows inline in your html code without writing the same boilerplate code for open and closing a popup. It also supports view caching and is scope destroy aware so you do not need to hide it manually when you switching a view.
| // How to get the pickadate to mount correcty in React.js component | |
| // requires jQuery and pickadate.js (https://github.com/amsul/pickadate.js/) | |
| var Component = React.createClass({ | |
| getInitialState: function() { | |
| return ({value: null}); | |
| }, | |
| componentDidMount: function() { |
The 0.13.0 improvements to React Components are often framed as "es6 classes" but being able to use the new class syntax isn't really the big change. The main thing of note in 0.13 is that React Components are no longer special objects that need to be created using a specific method (createClass()). One of the benefits of this change is that you can use the es6 class syntax, but also tons of other patterns work as well!
Below are a few examples creating React components that all work as expected using a bunch of JS object creation patterns (https://github.com/getify/You-Dont-Know-JS/blob/master/this%20&%20object%20prototypes/ch4.md#mixins). All of the examples are of stateful components, and so need to delegate to React.Component for setState(), but if you have stateless components each patterns tends to get even simpler. The one major caveat with react components is that you need to assign props and context to the component instance otherwise the component will be static. The reason is
You got your hands on some data that was leaked from a social network and you want to help the poor people.
Luckily you know a government service to automatically block a list of credit cards.
The service is a little old school though and you have to upload a CSV file in the exact format. The upload fails if the CSV file contains invalid data.
The CSV files should have two columns, Name and Credit Card. Also, it must be named after the following pattern:
YYYYMMDD.csv.
| dependencies: | |
| pre: | |
| - source /etc/lsb-release && echo "deb http://download.rethinkdb.com/apt $DISTRIB_CODENAME main" | sudo tee /etc/apt/sources.list.d/rethinkdb.list | |
| - wget -qO- http://download.rethinkdb.com/apt/pubkey.gpg | sudo apt-key add - | |
| - sudo apt-get update | |
| - sudo apt-get install rethinkdb=1.16.3~0precise | |
| - sudo cp /etc/rethinkdb/default.conf.sample /etc/rethinkdb/instances.d/instance1.conf | |
| - sudo /etc/init.d/rethinkdb restart |
| /* bling.js */ | |
| window.$ = document.querySelector.bind(document); | |
| window.$$ = document.querySelectorAll.bind(document); | |
| Node.prototype.on = window.on = function(name, fn) { this.addEventListener(name, fn); }; | |
| NodeList.prototype.__proto__ = Array.prototype; | |
| NodeList.prototype.on = function(name, fn) { this.forEach((elem) => elem.on(name, fn)); }; |
| # After spending too much time away from Python on Javascript, I gave this a shot. To my surprise, it worked! | |
| # Since Python doesn't bind "self" implicitly in classes, this looks pretty similar to Python classes. | |
| # You want inheritance? Pass in the Parent "class" and copy the key/vals a la Javascript. | |
| # Even adding dot syntax is not too tough. | |
| def Cat(legs, colorId, name): | |
| def sayHi(): | |
| print 'Hi, my name is %s. I have %s legs and am %s.' % (this['name'], this['legs'], this['color']) | |
| this = { |
| ### s3 implementation of Paperclip module that supports deep | |
| ### cloning of objects by copying image attachments. | |
| ### Refer to Paperclip issue: https://github.com/thoughtbot/paperclip/issues/1361#issuecomment-39684643 | |
| ### Original gist works with fog: https://gist.github.com/stereoscott/10011887 | |
| module Paperclip | |
| module CopyAttachments | |
| def copy_attachments_from(source_obj, source_bucket = nil, destination_bucket = nil) | |
| self.class.attachment_definitions.keys.each do |attachment_name| | |
| source_attachment = source_obj.send(attachment_name) |
| 'use strict'; | |
| module.exports = function CustomError(message, extra) { | |
| Error.captureStackTrace(this, this.constructor); | |
| this.name = this.constructor.name; | |
| this.message = message; | |
| this.extra = extra; | |
| }; | |
| require('util').inherits(module.exports, Error); |