Nested ReactJS Components
Here's an example of how to create nested components with ReactJS. Note that this JSX code must be compiled to native JavaScript to work. While this is a trivial example, you can use nested components to build up complex user interfaces and share a parent's state
in the props
of its child. As the application becomes more complex, it . . .
State vs. Props in React.js Components
Components in React.js have two properties used to store data to display in HTML: the state
and props
objects. They're both plain JavaScript objects and both can be used in the render
function of your components. Here I've summarized the difference between state
and props
, as well as their use cases.
State
state
is useful when a . . .
FizzBuzz in React.js
Title says it all
Here's a simple index.html
to start with:
<!doctype html> <html> <head> <meta charset="utf-8"> <title>Awesome FizzBuzz Incrementing</title> <!-- dependencies --> <script src="http://fb.me/react-0.12.2.js"></script> </head> <body> <script type= . . .
4 Instantiation Styles in JavaScript
Functional, Functional Shared, Prototypal, Pseudoclassical
Functional
var Dog = function(){ var dogInstance = {}; dogInstance.speak = function(){ console.log("woof!"); }; return dogInstance; };
Functional with shared methods
var DogMethods = { speak: function(){ console.log("woof!"); } }; var Dog = function(){ var instance = _.extend(DogMethods); return instance; };
Prototypal
. . .
An Algorithm to Convert Decimals to Fractions in JavaScript
Num to Fraction String in 16 Lines
/** * Write a function that takes a number as its argument and * returns a string that represents that number's simplified fraction. * * Example: toFraction(0.5) === '1/2' * * Whole numbers and mixed fractions should be returned as irregular fractions * * Example: toFraction(3.0) === '3/1' * * Example: . . .
A Simple Event System In Python
A callback-based event system with and without class inheritance
Here I made an easily digestible snippet to show how callback-based event systems work. It prints the output in the picture above when you run it in Terminal. The concept here is really easy, and I hope this post helps newbie developers understand event systems (Python is sooooo readable!). Here's the class inheritance-based . . .
Filesystem events on OS X
Terminal.app command to monitor everything OH MY GOD SO MUCH IS HAPPENING
tl;dr type lsof and see EVERYTHING YOUR COMPUTER IS DOING ON THE FILESYSTEM #WhoDesignedThis #unix