Skip to content

Instantly share code, notes, and snippets.

@dndhm
dndhm / AppWithContext.js
Last active March 30, 2023 09:17
React Context.Consumer mocking
import React, { Component } from 'react';
import FruitContext from './FruitContext';
import FruityComponent from './FruityComponent';
export class App extends Component {
state = {
fruit: 'apple',
}
@danmakenoise
danmakenoise / test.js
Last active February 29, 2024 20:23
Unit Testing Children of React Context API Consumers with Enzyme
// Component.js
const Component = props => (
<MyContext.Consumer>
{(context) => (
<Foo
bar={props.bar}
baz={context.baz}
/>
)}
</MyContext.Consumer>
@ivanbanov
ivanbanov / component.storybook.js
Last active January 9, 2019 09:16
Mock React context
import React from 'react';
import {storiesOf} from '@kadira/storybook';
import mockContext from '<path-to>/js/mocks/context';
import {Component} from '../';
const context = {
user: 'Foo Bar'
};
storiesOf('Component', module)
@spalladino
spalladino / mysql-docker.sh
Created December 22, 2015 13:47
Backup and restore a mysql database from a running Docker mysql container
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
@flesler
flesler / index.html
Last active September 11, 2021 13:16
Anchor navigation powered by jquery.scrollTo
<!-- Include jQuery from somewhere, must use version 1.8 or above -->
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<!-- Include latest jquery.scrollTo, can download from https://github.com/flesler/jquery.scrollTo/releases -->
<script type="text/javascript" src="//cdn.jsdelivr.net/jquery.scrollto/2.1.2/jquery.scrollTo.min.js"></script>
<!-- Initialize the plugin, the contents of the script can be inlined here, of course -->
<script type="text/javascript" src="js/init.js"></script>
@cmawhorter
cmawhorter / .bash_profile
Created October 21, 2014 19:53
Add alias to bash_profile to get a quick http server anywhere. Just type H to serve current directory.
# http://stackoverflow.com/a/12269225/670023
# Binds to localhost
alias H="echo 'Serving HTTP on 127.0.0.1 port 8000 ...'; python -c 'import BaseHTTPServer as bhs, SimpleHTTPServer as shs; bhs.HTTPServer((\"127.0.0.1\", 8000), shs.SimpleHTTPRequestHandler).serve_forever()'"