Skip to content

Instantly share code, notes, and snippets.

Daniel Norman 2color

View GitHub Profile
View commands.md

Useful linux commands

  • List files recursively: find input/ -type f | wc -l
@2color
2color / httpie-graphql.sh
Created Apr 16, 2020
How to send a GraphQL request with HTTPie
View httpie-graphql.sh
http POST https://graphqlapi.now.sh query="query { feed { id title } }"
View postgres-activity.sql
select * from pg_stat_activity where datname = 'DB_NAME'
View ghost_stack.yaml
# by default, the Ghost image will use SQLite (and thus requires no separate database container)
# we have used MySQL here merely for demonstration purposes (especially environment-variable-based configuration)
version: '3.1'
services:
ghost:
image: ghost:3-alpine
restart: always
@2color
2color / get_tweet_replies.py
Created Feb 18, 2020
Extract replies to a tweet into a CSV
View get_tweet_replies.py
import csv
import tweepy
# get credentials at developer.twitter.com
auth = tweepy.OAuthHandler('API Key', 'API Secret')
auth.set_access_token('Access Token', 'Access Token Secret')
api = tweepy.API(auth)
View download-code-github-monorepo.sh
# curl https://codeload.github.com/ORG/REPO/tar.gz/BRANCH
# tar -xz --strip=3 REPO-BRANCH/deployment-platforms/zeit-now/
curl https://codeload.github.com/prisma/prisma-examples/tar.gz/prisma2-deployment-zeit | tar -xz --strip=3 prisma-examples-prisma2-deployment-zeit/deployment-platforms/zeit-now/
View orm-patterns.md

ORM Patterns

In practice there are two common ORM patterns:

  • ActiveRecord: uses the model class to handle both business logic and database access.
  • DataMapper: a more complex approach which separates the in-memory objects from the database. Uses two class types:
    • Mapper: handles database access and mapping entities
    • Entities: in-memory representation with business logic

Some ORMs, like TypeORM support both patterns. Others like Sequelize support only ActiveRecord.

View prisma-lift-error.md

Failed calculateDatabaseSteps at 2019-12-18T10:35:02.979Z

RPC One-Liner

{"id":3,"jsonrpc":"2.0","method":"calculateDatabaseSteps","params":{"projectInfo":"","assumeToBeApplied":[{"stepType":"CreateModel","model":"User"},{"stepType":"CreateField","model":"User","field":"id","type":"String","arity":"required"},{"stepType":"CreateDirective","model":"User","field":"id","directive":"default"},{"stepType":"CreateDirectiveArgument","model":"User","field":"id","directive":"default","argument":"","value":"cuid()"},{"stepType":"CreateDirective","model":"User","field":"id","directive":"id"},{"stepType":"CreateDirective","model":"User","field":"id","directive":"unique"},{"stepType":"CreateField","model":"User","field":"email","type":"String","arity":"required"},{"stepType":"CreateDirective","model":"User","field":"email","directive":"unique"},{"stepType":"CreateField","model":"User","field":"name","type":"String","arity":"optional"},{"stepType":"CreateField","model":"User","field":"posts","type":"Post","arit
View failed-calculateDatabaseSteps-20191217184416.md

Failed calculateDatabaseSteps at 2019-12-17T17:44:16.463Z

RPC One-Liner

{"id":3,"jsonrpc":"2.0","method":"calculateDatabaseSteps","params":{"projectInfo":"","assumeToBeApplied":[{"stepType":"CreateModel","model":"User"},{"stepType":"CreateField","model":"User","field":"id","type":"String","arity":"required"},{"stepType":"CreateDirective","model":"User","field":"id","directive":"default"},{"stepType":"CreateDirectiveArgument","model":"User","field":"id","directive":"default","argument":"","value":"cuid()"},{"stepType":"CreateDirective","model":"User","field":"id","directive":"id"},{"stepType":"CreateField","model":"User","field":"email","type":"String","arity":"required"},{"stepType":"CreateDirective","model":"User","field":"email","directive":"unique"},{"stepType":"CreateField","model":"User","field":"name","type":"String","arity":"optional"}],"stepsToApply":[{"stepType":"CreateModel","model":"User"},{"stepType":"CreateField","model":"User","field":"id","type":"String","arity":"required"},{"stepT
View k8s.cheatsheet.md

Trigger cronjob manually

kubectl create job --from=cronjob/[CRONJOB] test-job-name

You can’t perform that action at this time.