Skip to content

Instantly share code, notes, and snippets.

var React = require.requireActual('react')
var assign = require.requireActual('object-assign')
function stubContext(Component, context) {
var _component = Component
var _context = context
var _contextTypes = {}
Object.keys(_context).forEach((key) => {
_contextTypes[key] = React.PropTypes.any
// Solution #1: Generic Override (like CSS)
var ButtonGroup = React.createClass({
render() {
return <div>{this.props.buttons.map((btn, i) =>
<Button style={{
...(i !== 0 && {marginLeft: 0})
...(i !== this.props.buttons.length - 1 && {marginRight: 0})
}} />
)}</div>;
@taion
taion / Button.js
Last active July 31, 2016 09:10
Embarrassing strawman API proposal that hopefully gets the point across
// This is _not_ supposed to be a real API. It's only intended to describe what
// I'm looking for. It's almost intentionally awful.
export const buttonHook = new OverrideHook({
properties: ['margin'],
});
export default function Button(props) {
return (
<button
@mik01aj
mik01aj / README.md
Last active April 21, 2017 13:02
How to use Tether with React

Tether is a great library for positioning stuff (tooltips, modals, hints, etc) in your web app.

But, as I use React, it was pretty problematic for me, as Tether mutates the DOM and React breaks miserably when it sees mutated DOM. The solution is to have the tethered element outside the part of the DOM tree which is controlled by React (in this case, I use document.body).

That's why I created 2 helpers to use Tether with React.

The first one, TetheredElement is a plain JS helper to create a new element, attach it to some other one via Tether, and populate it with some React component.

The second one, TetherTarget is a React component and it uses TetheredElement to integrate it further with React, so that you can attach components to each other with Tether, without leaving the cozy React/JSX world and worrying about manual DOM operations. Just write:

@export-mike
export-mike / compose-async.js
Last active June 30, 2020 22:30
compose utility function for async await, A team effort with @cameronbourke and @gwyneplaine. It was a fun discussion.
/*
* Requires Node 8+
* Works in chrome, simply copy and paste into console.
*/
const R = require('ramda');
const compose =
(...funcs) =>
(...args) =>
funcs.reduceRight(async (a, f) => {
@wuhaixing
wuhaixing / views_in_keystone.md
Last active October 4, 2020 10:43
How to Construct Yourself UI in KeystoneJS

#How to Construct Yourself UI in KeystoneJS

KeystoneJS provide Admin UI with one set of route controllers and view templates(list&item) for all of the models.But usually,you will need some custome views other than Admin UI to display models. Although the KeystoneJS documention don't tell us much about how to contruct custome view,we can learn this from the source code in skeleton project generated by yo keystone,or you can just check out the keystone demo project's source code.We will walk through the blog feature's implementation in this demo application to demonstrate how to construct custome UI in KeystoneJS application.

As KeystoneJS documention described in Routes & Views section,there is a routes/index.js file, where we bind application's URL patterns to the controllers that load and process data, and render the appropriate template.You can find following code in it:

app.get('/blog/:catego

@grabbou
grabbou / .travis.yml
Created August 19, 2014 08:27
Code coverage integration for CodeClimate / TravisCI & Mocha
language: node_js
node_js: ["0.11", "0.10"]
env:
CODECLIMATE_REPO_TOKEN: <your_token>
before_script:
- npm install -g istanbul
- npm install -g mocha
- npm install -g codeclimate-test-reporter
var DateHelper = {
// Takes the format of "Jan 15, 2007 15:45:00 GMT" and converts it to a relative time
// Ruby strftime: %b %d, %Y %H:%M:%S GMT
time_ago_in_words_with_parsing: function(from) {
var date = new Date;
date.setTime(Date.parse(from));
return this.time_ago_in_words(date);
},
time_ago_in_words: function(from) {
@jeroenvisser101
jeroenvisser101 / safari.css
Last active May 9, 2023 01:31
Hide Safari contacts auto-fill when [autocomplete="off"]
input[autocomplete="off"]::-webkit-contacts-auto-fill-button {
visibility: hidden;
display: none !important;
pointer-events: none;
height: 0;
width: 0;
margin: 0;
}
@ceejbot
ceejbot / esm_in_node_proposal.md
Last active July 17, 2023 02:45
npm's proposal for supporting ES modules in node

ESM modules in node: npm edition

The proposal you’re about to read is not just a proposal. We have a working implementation of almost everything we discussed here. We encourage you to checkout and build our branch: our fork, with the relevant branch selected. Building and using the implementation will give you a better understanding of what using it as a developer is like.

Our implementation ended up differing from the proposal on some minor points. As our last action item before making a PR, we’re writing documentation on what we did. While I loathe pointing to tests in lieu of documentation, they will be helpful until we complete writing docs: the unit tests.

This repo also contains a bundled version of npm that has a new command, asset. You can read the documentation for and goals of that comma