Skip to content

Instantly share code, notes, and snippets.

@altaudio
altaudio / .env
Created May 4, 2017 13:21
Environment Variables
PAGE_TOKEN=’EAAGfqT712tEBAK7bGOUSPZCYoH...’ //A really long string
VERIFY_TOKEN=’z-dev-demo’
APP_SECRET=’2b7b02fbe0c3a5021e72b591d25549ea’
@altaudio
altaudio / botServer.js
Created May 4, 2017 13:23
Messenger Bot Server
var Bot = require('messenger-bot')
var http = require('http')
const bot = new Bot({
token: process.env.PAGE_TOKEN,
verify: process.env.VERIFY_TOKEN,
app_secret: process.env.APP_SECRET
})
bot.on('error', (error) => {
console.log(error.message)
@altaudio
altaudio / getStarted.js
Created May 4, 2017 13:25
Get Started Postback Handler
const users = {}
bot.on(‘postback’, (payload) => {
if (payload.postback.payload === ‘GET_STARTED_PAYLOAD’) {
const senderId = payload.sender.id
bot.getProfile(senderId, (error, profile) => {
if (error) {
console.log(error)
}
@altaudio
altaudio / newsBot.js
Created May 4, 2017 13:26
Send Hacker News Posts
bot.on('message', (payload, reply) => {
const message = payload.message.text
const senderId = payload.sender.id
const apiUrl = 'https://newsapi.org/v1/articles?source=hacker-news&sortBy=top&apiKey=52a36d98da214f98a9b9b9bfaba502a7'
if (message === 'news' || message === 'News') {
request
.get(apiUrl)
.end((error, result) => {
const articles = result.body.articles
0x62F557F5A81879185A972DCFDfC9E61f5Ab03212
@altaudio
altaudio / todos.js
Last active December 28, 2018 14:31
import React, { Component } from 'react'
class Todos extends Component {
constructor() {
super()
this.state = { newTodo: '' }
}
addTodoAndClearNewTodo() {
import { Container } from 'unstated'
class TodosContainer extends Container {
state = {
todos: []
}
addTodo(todo) {
this.setState({ todos: [ ...this.state.todos, todo ] })
}
@altaudio
altaudio / todos.js
Last active December 28, 2018 14:30
import React, { Component } from 'react'
import { Subscribe } from 'unstated'
import TodosContainer from '../../containers/todos'
class Todos extends Component {
constructor() {
super()
this.state = { newTodo: '' }
}

Useful Commands

Insert Text on line above found match

find app/webapp/src/js -type f -name "*.js" -prin
t0 | xargs -0 sed -i '' -e '/UNSAFE/i\
// eslint-disable-next-line camelcase'

List Files

grep -E -l "(componentWillReceiveProps|componentWillMount|componentWillUpdate)" app/webapp/node_modules/**/*.js | wc -l

Show matches in color

grep -E --color "(componentWillReceiveProps|componentWillMount|componentWillUpdate)" app/webapp/node_modules/**/*.js

Clear all files with a certain match

truncate -s 0 $(grep -l "husky" ./*)