Skip to content

Instantly share code, notes, and snippets.

View DarrylD's full-sized avatar
💭
daydreaming

Darryl D. DarrylD

💭
daydreaming
View GitHub Profile
@thevangelist
thevangelist / my-component.spec.js
Created August 4, 2016 13:06
The only React.js component test you'll ever need (Enzyme + Chai)
import React from 'react';
import { shallow } from 'enzyme';
import MyComponent from '../src/my-component';
const wrapper = shallow(<MyComponent/>);
describe('(Component) MyComponent', () => {
it('renders without exploding', () => {
expect(wrapper).to.have.length(1);
});
@abhiaiyer91
abhiaiyer91 / reduxSelectorPattern.md
Last active April 29, 2022 06:00
Redux Selector Pattern

Redux Selector Pattern

Imagine we have a reducer to control a list of items:

function listOfItems(state: Array<Object> = [], action: Object = {}): Array<Object> {
  switch(action.type) {
    case 'SHOW_ALL_ITEMS':
      return action.data.items
    default:
@emilong
emilong / component.jsx
Created May 27, 2016 20:35
Creating semantic links for react-router using HOCs
import React, { Component } from 'react'
import { SubWidgetLink } from './routes'
export default class MyComponentWithALink extends Component {
render() {
const { widget } = this.props
return (
<div>
...
@StJohn3D
StJohn3D / cheerio-react.js
Created May 19, 2016 15:53
Quickly convert react components to jQuery like Cheerio objects for testing - source code from cheerio-react on npm
var ReactDOMServer = require('react-dom/server');
var cheerio = require('cheerio');
module.exports = function( reactClass ) {
var staticMarkup = ReactDOMServer.renderToStaticMarkup(reactClass);
var $ = cheerio.load(staticMarkup);
return $.root().children().first();
};
@btroncone
btroncone / rxjs_operators_by_example.md
Last active July 16, 2023 14:57
RxJS 5 Operators By Example
@mlsteele
mlsteele / ngrok-copy
Created January 15, 2016 16:49
Copy the url of the active ngrok connection to the clipboard.
#!/usr/bin/env bash
# Copy the url of the active ngrok connection to the clipboard.
# Usage:
# ngrok-copy # copies e.g. https://3cd67858.ngrok.io to clipboard.
# ngrok-copy -u # copies e.g. http://3cd67858.ngrok.io to clipboard.
if [[ "$1" == "-u" ]]; then
NGROK_URL=`curl -s http://127.0.0.1:4040/status | grep -P "http://.*?ngrok.io" -oh`
else
NGROK_URL=`curl -s http://127.0.0.1:4040/status | grep -P "https://.*?ngrok.io" -oh`
@gbabiars
gbabiars / Scores.js
Created December 20, 2015 21:15
Basic example of RxJS and React
import React from 'react';
import axios from 'axios';
import Rx from 'rxjs';
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
scores: []
};
@mykelswitzer
mykelswitzer / component.jsx
Created September 11, 2015 00:41
React.js with pickadate.js
// How to get the pickadate to mount correcty in React.js component
// requires jQuery and pickadate.js (https://github.com/amsul/pickadate.js/)
var Component = React.createClass({
getInitialState: function() {
return ({value: null});
},
componentDidMount: function() {
@islahul
islahul / react-double-colon-meaning-es6.js
Last active June 15, 2017 23:19
React double colon meaning JSX usage
import './login.styl';
import Component from '../components/component.react';
import React from 'react';
import exposeRouter from '../components/exposerouter.react';
import {focusInvalidField} from '../lib/validation';
@exposeRouter
export default class Login extends Component {
static propTypes = {
@lukehoban
lukehoban / speech.js
Last active December 28, 2023 15:14
Project Oxford Speech APIs Node.js Sample
var fs = require('fs');
var util = require('util');
var request = require('request');
var clientId = 'test-app'; // Can be anything
var clientSecret = 'f6f0bfec08274b8790520a9079b808af'; // API key from Azure marketplace
var str = 'This is a cool demo to call Microsoft text to speach service in Node.js.';
console.log('Converting from text -> speech -> text.');