Skip to content

Instantly share code, notes, and snippets.

Ivan Montiel idmontie

Block or report user

Report or block idmontie

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@idmontie
idmontie / index.js
Created Jun 6, 2019
Intercom webhook signature validation
View index.js
const express = require('express');
const bodyParser = require('body-parser');
const crypto = require('crypto');
const serverless = require('serverless-http');
const app = express();
const KEY = 'YOUR_KEY';
app.use(bodyParser.raw({
type: '*/*',
@idmontie
idmontie / todo.md
Created Mar 8, 2019
TODO.md template for VS Code TODO Plugin
View todo.md

Key ☐ incomplete · ✔ completed · ✘ canceled

Title: ☐ Item 1 ☐ Item 2

View StateReducerToggle.js
export default class Toggle extends Component {
static TOGGLE = 'TOGGLE';
state = { on: false }
onClick = (e) => {
e.preventDefault();
this.internalSetState(state => ({
on: !state.on,
View FullStateReducer.js
class App extends Component {
stateReducer = (prevState, nextState) => {
switch (nextState.type) {
case Toggle.TOGGLE: {
const count = prevState.count || 0;
const isOn = count < 4 ? nextState.on : false;
return {
...prevState,
...nextState,
View simpleReducer.js
(state, action) => {
switch (action.type) {
case TOGGLE: {
const count = state.count || 0;
const isOn = count < 4 ? action.changes.on : false;
return {
...state,
...action.changes,
count: isOn ? count + 1 : count,
View ToggleSwitchClick.js
class App extends Component {
state = { clickCount: 0 }
canClick() {
return this.state.clickCount < 4;
}
onIncrement() {
this.setState(state => ({
clickCount: state.clickCount + 1,
View ToggleSwitch.js
<Toggle>
{({ on, onToggle }) => (
<Switch on={on} onToggle={onToggle} />
)}
</Toggle>
View Toggle.js
export default class Toggle extends Component {
state = { on: false }
onClick = (e) => {
e.preventDefault();
this.setState(state => ({
on: !state.on,
}));
}
View Switch.js
const Switch = ({ on, onToggle }) => (
<label className={styles.switch} onClick={onToggle}>
<input
checked={on}
type="checkbox"
/>
<span className={styles.slider} />
</label>
);
View mouseHoC.js
const mousePosition = () => (BaseComponent) => {
return class MousePosition extends Component {
constructor(props) {
super(props);
this.state = { x: 0, y: 0 };
}
componentDidMount() {
this.listener = (e) => {
this.setState(() => ({ x: e.pageX, y: e.pageY }));
You can’t perform that action at this time.