Skip to content

Instantly share code, notes, and snippets.

View sethdavis512's full-sized avatar
🤖

Seth Davis sethdavis512

🤖
View GitHub Profile
// prop callback
class Compoennt {
render() {
return (
<div>
<Thing onChange={(val) => {
this.setState({ val1: val })
}}/>
<Thing onChange={(val) => {
this.setState({ val2: val })
@peterpme
peterpme / RadioBtnGroup.jsx
Created September 21, 2015 19:31
Radio Button Group in React
const RadioBtnGroup = React.createClass({
getDefaultProps() {
return {
options: []
}
}
handleValueChange(evt) {
this.setState({
value: evt.currentTarget.value
@ebakan
ebakan / Popper.js
Last active January 24, 2018 19:25
React Component for Popper.js that takes the reference as its first child and the popper as its second child (a la react-tether)
import React, { Component, PropTypes } from 'react';
import popperJS from 'popper.js';
export default class Popper extends Component {
constructor(props) {
super(props);
this.state = {};
this.update = this.update.bind(this);
}
function RadioGroup({ onChange, name, children }) {
const [state, inputProps] = useRadioGroup(name)
return (
<Context.Provider value={inputProps}>
{children}
</Context.Provider>
)
}
function RadioInput(props) {
@tmpvar
tmpvar / my-first-module.md
Last active December 20, 2021 18:48
how to create your very first node.js module and publish it to the npm registry

building your first node module

This is pretty simple, lets dive in!

choose a name

Find a name that isn't taken and clearly describes what your module is doing

$ npm view your-first-node-module
@kitze
kitze / plopfile.js
Created May 25, 2016 10:41
A sample plopfile for generating React components and components with containers
module.exports = function (plop) {
/* Helpers */
plop.addHelper('upperCase', function (text) {
return text.toUpperCase();
});
/* Files */
var createIndex = {
type: 'add',
@alisterlf
alisterlf / gist:3490957
Created August 27, 2012 18:10
JAVASCRIPT:Remove Accents
function RemoveAccents(strAccents) {
var strAccents = strAccents.split('');
var strAccentsOut = new Array();
var strAccentsLen = strAccents.length;
var accents = 'ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž';
var accentsOut = "AAAAAAaaaaaaOOOOOOOooooooEEEEeeeeeCcDIIIIiiiiUUUUuuuuNnSsYyyZz";
for (var y = 0; y < strAccentsLen; y++) {
if (accents.indexOf(strAccents[y]) != -1) {
strAccentsOut[y] = accentsOut.substr(accents.indexOf(strAccents[y]), 1);
} else
@cjavilla-stripe
cjavilla-stripe / value-based-saas-pricing-seed.json
Last active January 28, 2023 14:46
Stripe CLI fixture for creating value based pricing Stripe test data
{
"_meta": {
"template_version": 0
},
"fixtures": [
{
"name": "startup_product",
"path": "/v1/products",
"method": "post",
"params": {
@mritzco
mritzco / plopfile.js
Created March 8, 2018 08:09
Custom action for plop. Appends data to JSON files
const fs = require('fs-extra');
const methods = {}, priv = {};
// Private methods to do string replacement. Not optimized and cummulative trying to keep it simple.
// far better options here: https://stackoverflow.com/questions/5069464/replace-multiple-strings-at-once
priv.replaceObj = function(value, vars) {
let obj = value;
Object.keys(obj).forEach(function(item) {
obj[item] = priv.replaceStr(obj[item], vars);
});
return obj;
import { useState, useEffect } from 'react';
// Usage
function App() {
// Call our hook for each key that we'd like to monitor
const happyPress = useKeyPress('h');
const sadPress = useKeyPress('s');
const robotPress = useKeyPress('r');
const foxPress = useKeyPress('f');