Cheatsheet
          
          
            
            2m read
          
          
          
          
            
          
        
      Zsh
Checking Directories Size
du -sh * | sort -h      # human-readable, sorted
du -h * | sort -rh | head -5    # human-readable, sorted, top 5Identifying Processes Using Ports
lsof -i tcp:4000 
COMMAND     PID  USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
com.docker 30895 dmitry   27u  IPv6 0x76138f66872a1fdd      0t0  TCP *:terabase (LISTEN)Scan open ports on a remote machine
sudo nmap -sT -p-  <ip_address>asdf
Use .default-npm-packages file to install packages globally
Updating a single package in all versions
asdf list nodejs | xargs -I@ env ASDF_NODEJS_VERSION="@" npm install -g $pkgUpdating all packages in all versions
asdf list nodejs | xargs -I@ env ASDF_NODEJS_VERSION="@" npm upgrade -gWill also can easily parallelize it with the -P xargs option
asdf list nodejs | xargs -I@ -P4 env ASDF_NODEJS_VERSION="@" npm upgrade -gKafka
Send kafka messages to the topic
kafka-console-producer --broker-list localhost:9092 --topic {topic}
>send
>wowConsume events from the given topic
kafka-console-consumer --bootstrap-server localhost:9092 --topic {topic} --from-beginning
send
wow
^CProcessed a total of 2 messagesCreate kafka topics (log compact)
kafka-topics --create \
--bootstrap-server localhost:9092 \
--topic {topic} \
--partitions 8 \
--replication-factor 1 \
--config cleanup.policy=compact \
--config retention.ms=10000 \
--config segment.bytes=100
Created topic {topic}.Ruby
Profiling tools
gem 'memory_profiler'
gem 'flamegraph'
gem 'rack-mini-profiler'
gem 'stackprof'Benchmarking code
Benchmark.measure { 1000.times {  } } && 1Generating flamegraph report
Flamegraph.generate('graph.html') do
  @user = User.take_random
endCreating inline active record model
class User < ActiveRecord::Base; endNewRelic
Looking for problematic endpoints
SELECT COUNT(*),
   percentile(duration, 50),
   percentile(duration, 95),
   percentile(duration, 99),
   max(duration),
   percentile(externalDuration, 50),
   percentile(externalDuration, 95),
   percentile(externalDuration, 99),
   max(externalDuration),
   percentile(databaseDuration, 50),
   percentile(databaseDuration, 95),
   percentile(databaseDuration, 99),
   max(databaseDuration)
FROM Transaction FACET name
WHERE appName = '{app}' AND transactionType = 'Web' SINCE 24 hours ago LIMIT MAXInspecting action
SELECT *
FROM Transaction
WHERE appName = '{app}'
  AND transactionType = 'Web'
  AND name = '{controller}'
  AND duration > 1000 SINCE 24 hours ago LIMIT MAXKubernetes (k8s)
Get all resources in the given context
# resources: deployment,pods,services,configmaps,secrets,ingress
kubectl --context {context} get podsDelete resources found by a given search
# -l app=app-name to filter using k8s labels
# | grep something to filter using grep if there are no labels
# | xargs kubectl cmd to run a kubectl command on the results
kubectl get configmap,secrets,deployments,service,ingress -o jsonpath="{range .items[*]}{.kind}/{.metadata.name}{'\n'}{end}" | grep something | xargs kubectl deleteWatch logs from multiple pods simultaneously - https://github.com/stern/stern
stern deployment/name