Analytics libraries cheatsheet

Mixpanel

mixpanel.identify('284');
mixpanel.people.set({ $email: 'hi@gmail.com' });
mixpanel.register({ age: 28, gender: 'male' }); /* set common properties */

Google Analytics’s analytics.js

ga('create', 'UA-XXXX-Y', 'auto');
ga('create', 'UA-XXXX-Y', { userId: 'USER_ID' });
ga('send', 'pageview');
ga('send', 'pageview', { 'dimension15': 'My custom dimension' });

Google Analytics’s analytics.js cheatsheet

Google Analytics’s Analytics.js is deprecated.

Page view

ga('create', 'UA-XXXX-Y', 'auto')
ga('create', 'UA-XXXX-Y', { userId: 'USER_ID' })
ga('send', 'pageview')
ga('send', 'pageview', { 'dimension15': 'My custom dimension' })

Events

ga('send', 'event', 'button',  'click', {color: 'red'});
ga('send', 'event', 'button',  'click', 'nav buttons',  4);
/*                  ^category  ^action  ^label          ^value */

Exceptions

ga('send', 'exception', {
  exDescription: 'DatabaseError',
  exFatal: false,
  appName: 'myapp',
  appVersion: '0.1.2'
})

docker-compose cheatsheet

Basic example

# docker-compose.yml
version: '2'

services:
  web:
    build: .
    # build from Dockerfile
    context: ./Path
    dockerfile: Dockerfile
    ports:
     - "5000:5000"
    volumes:
     - .:/code
  redis:
    image: redis

Commands

docker-compose start
docker-compose stop
docker-compose pause
docker-compose unpause
docker-compose ps
docker-compose up
docker-compose down

Reference

Building

web:
  # build from Dockerfile
  build: .
  args:     # Add build arguments
    APP_HOME: app
  # build from custom Dockerfile
  build:
    context: ./dir
    dockerfile: Dockerfile.dev
  # build from image
  image: ubuntu
  image: ubuntu:14.04
  image: tutum/influxdb
  image: example-registry:4000/postgresql
  image: a4bc65fd

Ports

  ports:
    - "3000"
    - "8000:80"  # guest:host
  # expose ports to linked services (not to host)
  expose: ["3000"]

Commands

  # command to execute
  command: bundle exec thin -p 3000
  command: [bundle, exec, thin, -p, 3000]
  # override the entrypoint
  entrypoint: /app/start.sh
  entrypoint: [php, -d, vendor/bin/phpunit]

Environment variables

  # environment vars
  environment:
    RACK_ENV: development
  environment:
    - RACK_ENV=development
  # environment vars from file
  env_file: .env
  env_file: [.env, .development.env]

Dependencies

  # makes the `db` service available as the hostname `database`
  # (implies depends_on)
  links:
    - db:database
    - redis
  # make sure `db` is alive before starting
  depends_on:
    - db

Other options

  # make this service extend another
  extends:
    file: common.yml  # optional
    service: webapp
  volumes:
    - /var/lib/mysql
    - ./_data:/var/lib/mysql

Advanced features

Labels

services:
  web:
    labels:
      com.example.description: "Accounting web app"

DNS servers

services:
  web:
    dns: 8.8.8.8
    dns:
      - 8.8.8.8
      - 8.8.4.4

Devices

services:
  web:
    devices:
    - "/dev/ttyUSB0:/dev/ttyUSB0"
services:
  web:
    external_links:
      - redis_1
      - project_db_1:mysql

Hosts

services:
  web:
    extra_hosts:
      - "somehost:192.168.1.100"

Network

# creates a custom network called `frontend`
networks:
  frontend:

External network

# join a pre-existing network
networks:
  default:
    external:
      name: frontend

Semver cheatsheet

Semver

Given a version number MAJOR.MINOR.PATCH:

MAJORincompatible API changes
MINORadd functionality (backwards-compatible)
PATCHbug fixes (backwards-compatible)

Simple ranges

  1.2.3
 =1.2.3
 >1.2.3
 <1.2.3
>=1.2.3

Note that suffixed versions (1.2.3-rc1) are not matched.

Ranges

~1.2.3is >=1.2.3 <1.3.0 
^1.2.3is >=1.2.3 <2.0.0 
^0.2.3is >=0.2.3 <0.3.0(0.x.x is special)
^0.0.1is =0.0.1(0.0.x is special)
^1.2is >=1.2.0 <2.0.0(like ^1.2.0)
~1.2is >=1.2.0 <1.3.0(like ~1.2.0)
^1is >=1.0.0 <2.0.0 
~1same 
1.xsame 
1.*same 
1same 
*any version 
xsame 

Hyphenated ranges

1.2.3 - 2.3.0is >=1.2.3 <=2.3.4

Partial right

1.2.3 - 2.3is >=1.2.3 <2.4.0
1.2.3 - 2is >=1.2.3 <3.0.0

Partial left

1.2 - 2.3.0is 1.2.0 - 2.3.0

When the right is partial (eg, 2.3), missing pieces are assumed to be x (eg, 2.3.x).

When the left is partial (eg, 1.2), missing pieces are assumed to be 0 (eg, 1.2.0).

Combining ranges

>=0.14 <16And (space-separated)
0.14.x || 15.x.xOr (pipe-separated)

Pre-releases

1.2.3-prerelease+build

Explanation

^means “compatible with”
~means “reasonably close to”
0.x.xis for “initial development”
1.x.xmeans public API is defined

References