Skip to content

Instantly share code, notes, and snippets.

View progress.sh
#!/usr/bin/env bash
#
# See https://stackoverflow.com/questions/26881441/can-you-get-the-number-of-lines-of-code-from-a-github-repository
#
git clone --depth 1 git@github.com:oreillymedia/heron.git
printf "\nTotal lines\n"
echo "========================="
cloc heron --quiet --csv --include-lang=Python,JavaScript,HTML --exclude-dir=migrations | cut -d ',' -f 2,5
printf "\nLines excluding tests\n"
echo "========================="
View Swagger-to-APIB.md

Prerequisites

fury is a tool for converting among different API documentation formats

Install fury-cli

npm install -g fury-cli

View test-spec.js
{"swagger": "2.0", "info": {"title": "Discovery Graph API", "description": "", "version": ""}, "host": "web.discovery-graph.svc.dev-seb.local", "schemes": ["https"], "paths": {"/api/graph/discovery/": {"get": {"operationId": "list", "responses": {"200": {"description": ""}}, "parameters": [], "description": "Discovery view to generate REST API schema", "summary": "Discovery view to generate REST API schema", "tags": ["discovery"]}}, "/api/graph/v1/classifier/classify": {"post": {"operationId": "classifier_classify_create", "responses": {"201": {"description": ""}}, "parameters": [{"name": "data", "in": "body", "schema": {"type": "object", "properties": {"identifier": {"description": "", "type": "string"}, "title": {"description": "", "type": "string"}, "description": {"description": "", "type": "string"}}}}], "consumes": ["application/json"], "tags": ["v1"]}}, "/api/graph/v2/content/": {"get": {"operationId": "content_list", "responses": {"200": {"description": ""}}, "parameters": [{"name": "limit", "required
View gcloud-cheatsheet.md

Static site hosting

List buckets

$ gsutil ls
gs://ano-auth-test-bucket/
gs://ano-static-site-bucket/
View letsencrypt-on-heroku.md
View keen-in-react.js
/*********************************************************************
|| Import required modules
*********************************************************************/
import {fromJS} from 'immutable'
import Keen from 'keen-js'
var client = new Keen({
projectId: "your-project-id",
writeKey: "your-write-key"
})
@odewahn
odewahn / better-syntax-for-connected components.md
Last active Jun 7, 2017
This is a better syntax for creating connected component
View better-syntax-for-connected components.md

If you're using Redux and connect, this is a nice syntax for creating connected components:

export default connect((state) => state)(React.createClass({
  render: function() {
    ...
    this.props.Projects.get("ProjectName") // access the state tree provided by combineReducers
  }
})
@odewahn
odewahn / error-handling-with-fetch.md
Last active Sep 9, 2021
Processing errors with Fetch API
View error-handling-with-fetch.md

I really liked @tjvantoll article Handling Failed HTTP Responses With fetch(). The one thing I found annoying with it, though, is that response.statusText always returns the generic error message associated with the error code. Most APIs, however, will generally return some kind of useful, more human friendly message in the body.

Here's a modification that will capture this message. The key is that rather than throwing an error, you just throw the response and then process it in the catch block to extract the message in the body:

fetch("/api/foo")
  .then( response => {
    if (!response.ok) { throw response }
    return response.json()  //we only get here if there is no error
  })
@odewahn
odewahn / config-timing-in-single-page-app.md
Last active Aug 3, 2020
Loading global environment variables in a single page app (SPA) in react/redux
View config-timing-in-single-page-app.md

I was trying to pass config variables from a backend written in Go to a single page app (SPA) written in react. For example, I wanted to set an "Env" flag to dev or prod or control whether you have to log in or not. Here's an example of the /api/config route that supplies this data:

{
    "Auth0ClientDomain": "odewahn.auth0.com", 
    "Auth0ClientID": "gcSxq9GfpUdVWNIvYiOsP7rh1s8u6ftA", 
    "ClientBrowser": "HTTPie", 
    "ClientOS": "darwin", 
    "Env": "dev", 
    "FirstClientLoad": "true", 
@odewahn
odewahn / samalba-search-example.go
Last active Jun 12, 2016
Example of how to search your own public repos using samalba client
View samalba-search-example.go
package main
import (
"fmt"
"log"
"github.com/samalba/dockerclient"
)
// Helpful: