Skip to content

Instantly share code, notes, and snippets.

@mDibyo
mDibyo / execute.sh
Created June 22, 2014 05:45
Custom custom Ubuntu image for distribution on Google Compute Engine
#!/bin/bash
# Install required tools
sudo aptitude install squashfs-tools genisoimage
@mDibyo
mDibyo / queue
Last active March 28, 2016 03:51
A simple thread-safe implementation of a FIFO queue backed by a linked-list.
package queue
import (
"container/list"
"sync"
)
// Queue is a thread-safe FIFO queue implemented on top of a linked list.
type Queue struct {
list list.List
import withHook from 'with-hook';
class HookedInput extends React.PureComponent {
render() {
const WithFormInputProps = withHook(useFormInput);
return (
<WithFormInputProps>
{({ value, onChange }) => <input value={value} onChange={onChange} />}
</WithFormInputProps>
class WindowInfo extends React.PureComponent {
render() {
const WithWindowWidth = withHook(() => {
const [width, setWidth] = useState(window.innerWidth);
const handleWindowResize = () => setWidth(window.innerWidth);
useEffect(() => {
window.addEventListener('resize', handleWindowResize);
return () => window.removeEventListener('resize', handleWindowResize);
});
import withHooksSupport from 'with-hooks-support';
class Input extends React.PureComponent {
render() {
const { value, onChange } = useFormInput('Take 2!');
return <input value={value} onChange={onChange} />;
}
}
export default withHooksSupport(Input);
class HookedInput extends React.PureComponent {
render() {
// `withHook` creates a new function component that calls `useFormInput`
// that passes the return value to its children.
const WithFormInputProps = withHook(useFormInput);
return (
<WithFormInputProps>
{({ value, onChange }) => <input value={value} onChange={onChange} />}
</WithFormInputProps>
);
class withHooksSupport(Component) {
return class ComponentWithHooksSupport extends Component {
// TODO
}
}
function withHooksSupport(Component) {
return class ComponentWithHooksSupport extends Component {
render() {
const WithHook = withHook(() => super.render());
return (
<WithHook>
{superRenderReturnValue => superRenderReturnValue}
</WithHook>
);
}
function withHooksSupport(Component) {
return class ComponentWithHooksSupport extends Component {
render() {
const withHook = (useHook) => {
return ({ children }) => {
const returnValue = useHook();
return children(returnValue);
}
}
function withHooksSupport(Component) {
return class ComponentWithHooksSupport extends Component {
render() {
const withHook = (useHook) => {
return () => useHook();
}
const WithHook = withHook(() => super.render());
return <WithHook />;
}