Skip to content

Instantly share code, notes, and snippets.

View cmmartin's full-sized avatar

Charlie Martin cmmartin

  • Founderpath
  • Brooklyn, NY
View GitHub Profile
@cmmartin
cmmartin / what-do-i-restart.sh
Created May 1, 2022 18:35
Find what service is running the web server in bash
netstat -tulpen | grep 443
@cmmartin
cmmartin / useGraphQL.js
Last active May 12, 2019 06:58
The simplest way to make a graphQL request in React
/**
* Usage:
*
* function Movie({ title = 'Inception' }) {
* const [data, loading, error] = useGraphQL('https://api.graph.cool/simple/v1/movies', `
* query getMovie($title: String!) {
* Movie(title: $title) {
* releaseDate
* actors {
* name

Keybase proof

I hereby claim:

  • I am cmmartin on github.
  • I am charliemartin (https://keybase.io/charliemartin) on keybase.
  • I have a public key ASB0YIxZ0_Ci3kADAbuH-eofDcgSPM6jdGxDgXnMscHTywo

To claim this, I am signing this object:

@cmmartin
cmmartin / redis.js
Created December 2, 2017 19:13
Redis client for node.js that uses promises
/* @flow */
import redis from 'redis'
import bluebird from 'bluebird'
bluebird.promisifyAll(redis.RedisClient.prototype)
bluebird.promisifyAll(redis.Multi.prototype)
const client = redis.createClient(process.env.REDIS_URL)
@cmmartin
cmmartin / react16-portal.js
Last active December 12, 2017 22:33
An example of how simple it is to create a portal in React v16+
// @flow
/* eslint-env browser */
import * as React from 'react'
import { createPortal } from 'react-dom'
type Props = {
children: React.Node,
}
export default class Portal extends React.Component<Props> {
@cmmartin
cmmartin / read-file-promise.js
Last active May 25, 2017 20:02
Read a file in Node.js. Returns a promise.
const fs = require('fs')
module.exports = function readFilePromise(path, encoding) {
return new Promise((resolve, reject) => {
try {
var filename = require.resolve(path)
fs.readFile(filename, encoding || 'utf8', (err, file) => {
if (err) reject(err)
else resolve(file)
})
@cmmartin
cmmartin / write-file-promise.js
Created May 25, 2017 19:44
Write a file in Node.js, creating its path if necessary. Returns a promise.
const fs = require('fs')
const path = require('path')
const mkpath = require('mkpath')
module.exports = function writeFilePromise(fileName, contents) {
return new Promise((resolve, reject) => {
mkpath(path.dirname(fileName), err => {
if (err) reject(err)
else {
fs.writeFile(fileName, contents, err => {
@cmmartin
cmmartin / Example-BouncingText.js
Last active October 17, 2021 11:13
React Native HOC for easily adding spring animations to your components
/*
* EXAMPLE USAGE
* This component is text that will bounce on mount and
* every time `this.props.someProperty` changes.
* Too bad react native doesn't support decorators yet :/
*/
import React, {
Component,
StyleSheet,
@cmmartin
cmmartin / auth.conf
Last active February 10, 2016 16:04
Nginx http auth with htpasswd
auth_basic "Restricted";
auth_basic_user_file /home/dokku/$APP/nginx.conf.d/.htpasswd;
@cmmartin
cmmartin / unfuck-cors.sh
Last active April 18, 2016 21:19
Open Chrome on OSX with web security disabled to avoid CORS shenanigans in development
open -a Google\ Chrome --args --disable-web-security --user-data-dir