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 / 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 / javascript-lies.js
Last active May 7, 2021 05:24
Javascript lies
null + null === 0 // true
[] + [] === '' // true
null + 1 === 1 // true
isNaN(null) // false
NaN === NaN // false
@cmmartin
cmmartin / moment-filter.js
Last active July 31, 2019 09:01
A generic Moment.js date filter for Angular.js
// REQUIRES:
// moment.js - http://momentjs.com/
// USAGE:
// {{ someDate | moment: [any moment function] : [param1] : [param2] : [param n]
// EXAMPLES:
// {{ someDate | moment: 'format': 'MMM DD, YYYY' }}
// {{ someDate | moment: 'fromNow' }}
@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 / 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 / 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 / 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 => {