by Ossi Hanhinen, @ohanhi
with the support of Futurice 💚.
Licensed under CC BY 4.0.
import { Component } from "React"; | |
export var Enhance = ComposedComponent => class extends Component { | |
constructor() { | |
this.state = { data: null }; | |
} | |
componentDidMount() { | |
this.setState({ data: 'Hello' }); | |
} | |
render() { |
function npm_package_is_installed { | |
if [ $(npm list --depth 0 --parseable true "${2}" | grep "${1}$") ]; then | |
echo "1" | |
else | |
echo "0" | |
fi | |
} | |
# npm_package_is_installed gulp | |
# npm_package_is_installed gulp -g |
2015-01-29 Unofficial Relay FAQ
Compilation of questions and answers about Relay from React.js Conf.
Disclaimer: I work on Relay at Facebook. Relay is a complex system on which we're iterating aggressively. I'll do my best here to provide accurate, useful answers, but the details are subject to change. I may also be wrong. Feedback and additional questions are welcome.
Relay is a new framework from Facebook that provides data-fetching functionality for React applications. It was announced at React.js Conf (January 2015).
// resolution is [width, height] structure | |
// Evaluate resolution by width (height doesn't matter, just keep it proportional) | |
function evalResolutionByWidth(requiredWidth, actualResolution) { | |
var actualWidth = actualResolution[0]; | |
var actualHeight = actualResolution[1]; | |
if (actualWidth > requiredWidth) { | |
var scale = actualWidth / requiredWidth; | |
return [requiredWidth, Math.round(actualHeight / scale)]; | |
} else { |
# put this file in home folder | |
date_format %d/%b/%Y | |
log_format %h %^[%d:%^] "%r" %s %b "%R" "%u" |
from pymongo import MongoClient | |
from bson import SON | |
from time import mktime | |
from datetime import datetime, timedelta | |
from time import mktime | |
from pprint import pprint | |
from random import randrange, randint, choice | |
def seed_position_times(db): |
;; 0. Given that `app` is a RING handler | |
;; 1. We have 6 functions: 3 to modify requests, 3 to modify responses | |
;; 1.1. Request modifiers | |
(defn modify-request-first [handler] | |
(fn [request] | |
(println "modify-request-first") ; "println" is a placeholder for real code | |
(handler request))) |
(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.
class PPrintMixin: | |
def __str__(self): | |
return '<{}: id={!r}>'.format(type(self).__name__, self.id) | |
def __repr__(self): | |
attrs = [] | |
for name in self._fields.keys(): | |
value = getattr(self, name) | |
if isinstance(value, (Document, EmbeddedDocument)): | |
attrs.append('\n {} = {!s},'.format(name, value)) |