Skip to content
/ Brain Public

Use this repository instead of your brain. Super helpful?

Notifications You must be signed in to change notification settings

bes/Brain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Brain

Use this repository instead of your brain. Super helpful?

SSH

configure multiple ssh keys for Github

Host github1
   HostName     github.com
   User         git
   IdentityFile ~/.ssh/id_rsa_github1
Host github2
  HostName     github.com
  User         git
  IdentityFile ~/.ssh/id_rsa_github2

Then register additional ssh keys using ssh-add

ssh-add -t 12h ~/.ssh/your_private_key

List current keys using

ssh-add -l

The last step is to clone the git using the new virtual Host from the ssh config

git clone git@github1:username/projectname.git

Configure ssh through another ssh proxy (use with e.g. AWS)

#The ssh proxy machine
Host my-proxy-name
  HostName     <ip address>
  User         ec2-user
  IdentityFile ~/.ssh/<identity>.pem

#Connect to a host matching a pattern
Host <partial-match-dns>-*.eu-west-1.compute.internal
  User         ec2-user
  IdentityFile ~/.ssh/<identity>.pem
  ProxyCommand ssh my-proxy-name -W %h:%p

#Connect to a specific host through a proxy machine running ssh
Host <some-other-host-trivial-name>
  User         ubuntu
  IdentityFile ~/.ssh/spiideo-kp1.pem
  ProxyCommand ssh my-proxy-name -W <some-specific-machine>.eu-west-1.compute.internal:22

Easy "VPN" tunnel using SSH

  • Download / install sshuttle
  • sshuttle --dns -r username@remote-server-ip-or-name 0/0

Network analysis

Tools for analyzing local networks

Primary WAN interface:

ip route get 8.8.8.8

List SSIDs

iw dev wlan0 scan | grep "SSID:" | sort | uniq

IP neighbors

List local ip addresses that were recently connected.

This is primarily run FROM a router, e.g. OpenWRT or other router that has a shell.

ip neigh

mDNS

dns-sd -B _http
dns-sd -L "Instance name here" _http._tcp.
dns-sd -Gv4v6 bla-bla-bla.local

Port scan

Scan all ports for a specific IP address

nmap -p- 192.168.1.2

TODO: Add more nmap examples

GPG

Encrypt to a specific person

From clipboard

Encrypt

pbpaste | gpg -ear <recipient>

Decrypt

pbpaste | gpg -d

From file

Encrypt

gpg --output encrypted_file.gpg --encrypt --recipient <recipient> file_to_encrypt

Decrypt

gpg --output decrypted_file --decrypt encrypted_file.gpg

Encrypt with a password

Encrypt

gpg --sign -c file.txt

Decrypt

gpg --output <file> -d <file>.gpg

OpenSSL

Encrypt with password

openssl aes-256-cbc -a -salt -in <INFILE> -out <OUTFILE>.openssl

Decrypt with password

openssl aes-256-cbc -d -a -in <INFILE>.openssl -out <OUTFILE>

Options

  • -a Means that the file (in/out) should be in Base64
  • -d Means decrypt

SSH

Port forwarding from a remote server port to a local port

# ssh -N -L [bind_address:]<local port>:<host>:<remote port> <server>
ssh -N -L 5005:localhost:4000 some.ssh.server.com

Rust

Rustup

  • rustup update
  • rustup show
  • rustup toolchain list
  • rustup default nightly
  • rustup default stable

Cargo

Display features enabled by a dependency

cargo tree -e features

List installed applications

cargo install --list

cargo sweep

Install: cargo install cargo-sweep

Removes build artifacts except for the currently installed toolchain cargo sweep -r --toolchains="stable" "$HOME/repos/"

Sweep everything (except for binaries and a few other artifacts) cargo sweep -r --maxsize 0 "$HOME/repos/"

cargo-update

Install: cargo install cargo-update

List what needs to be updated: cargo install-update -l

Update all packages cargo install-update -a

cargo udeps

Find unused dependencies.

https://github.com/est31/cargo-udeps

Use:

cargo +nightly udeps --all-features

Resources

Rustdoc documentation

cargo doc --no-deps --all-features --open

Interesting projects

Golang

Install Using Homebrew

brew install go --cross-compile-common

GORE Go REPL

Golang REPL

A good use of gore might be to get current epoch nanos

$ gore
:import time
time.Now().UnixNano()

Java

macOS installation alternatives

  • Homebrew: brew cask install adoptopenjdk11
  • SDKMAN!
    • List: sdk list java
    • Install: sdk install java 13.0.1.hs-adpt

Measure Heap space graphically

Use VisualVM

Stack traces of running java process

pkill -3 java

Stacktrace will end up in /var/log/<some name>.log

Use top and press Shift+H to see thread PIDs, convert them to 0xHex and check against the log.

Start an instance with debugging

java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=4000,suspend=n -jar <myapp>.jar

See SSH section for port forwarding from a remote server

PHP

Crontab for removing old sessions (if your inode count goes through the roof, and you can't use your system anymore...)

0 5  *   *   *     find /var/lib/php5 -name "sess_*" -cmin +24 | xargs rm

Here's a post on stackoverflow for finding the place with the most files if you run out of inodes.

Check your inode count using

df -i

Spring (Boot)

Spring (Boot) SYSK

Spring errors

  • ErrorMvcAutoConfiguration - Whitelabel error page configuration
  • DefaultErrorAttributes - this is (one of?) the place the map of error values are generated
  • ErrorViewResolver - implement this and install it as a Bean/Component to override the whitelabel error page.

Docker

List images

docker images

List containers

docker ps

Or to show all containers

docker ps -a

Run a container

  • -e: supply environment variable
  • -it: interactive shell, if necessary
  • --rm: means temporary container, will be removed after exit
  • -p: map port from HOST:CONTAINER
  • -d: Detach - Run container in background and print container ID
  • -v: Mount a directory in the container HOST:CONTAINER
  • --network: Specify the network, use host for running the container in the host network space.
    • On mac the host can be connected to using DNS docker.for.mac.localhost

Examples

  • docker run -it --network host --rm -v "$HOME/slask":/opt/slask ubuntu:17.10 bash
  • docker run -e SOME_ENV_VARIABLE='true' --rm -it -p 8080:8080 name/of/image:version

Remove orphaned / dangling volumes

List them

docker volume ls -qf dangling=true

Remove them

docker volume rm $(docker volume ls -qf dangling=true)

Simple Docker UI

An app for managing Docker images locally: Simple Docker UI

Docker commands

Download a HLS to disk

docker run --rm -it \
  -v $(pwd):/config \
  linuxserver/ffmpeg \
  -f hls -i "<HLS_LINK_HERE>" -c copy /config/out.mp4

Google

Google Sign In

Amazon Web Services

Install AWS CLI

brew install awscli

Then configure it (AWS CLI Getting Started)

Selecting which user should be used by AWS CLI

export AWS_DEFAULT_PROFILE=user2

DynamoDB

Tutorial

Run local DynamoDB

java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb

application.yml

amazon:
  #The live server location, if you want to run against it
  region: EU_WEST_1
  dynamoDb:
    # If this is set, run against dynamo db local
    endpoint: http://localhost:8000/
logging:
  level:
    com:
      package: TRACE

JSON

Pretty print JSON

pbpaste works by default on OSX, can work on linux if you define it.

Using underscore

A CLI for parsing JSON data into component parts, usable by your shell.

pbpaste | underscore print --color | less

Using python

pbpaste | python -m json.tool | less

Gradle

Additional command line properties for gradle

Additional properties are given on the command line as

./gradlew task1 task2 task3 '-PmyPropertyName=some-value'

The properties can be used in gradle tasks/plugins/etc:

project.findProperty("myPropertyName")

Debug gradle tasks in IntelliJ

./gradlew --no-daemon -Dorg.gradle.debug=true <task-name>

Then in IDEA create a "Remote" configuration on port 5005 and press debug.

Force an update of dependencies

./gradlew --refresh-dependencies dependencies

Create wrapper

gradle wrapper --gradle-version 3.1

Gradle properties

The following options can be put in a gradle.properties file in the root of your Gradle project.

# Enable gradle daemon
org.gradle.daemon=true

# Enable caching
org.gradle.caching=true

# Set JVM args, e.g. increase heap or set OOM flags
org.gradle.jvmargs=-Xmx4096m -XX:MaxMetaspaceSize=1024m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/Users/bes/slask/heapdump

Test heap

Configure the test heap

allprojects { project ->
    project.plugins.withId('java') {
        // Only for tests
        test {
            maxHeapSize = "1536M"
            jvmArgs "-XX:MaxMetaspaceSize=512m"
        }
    }
    project.plugins.withId('java-library') {
        // Only for tests
        test {
            maxHeapSize = "1536M"
            jvmArgs "-XX:MaxMetaspaceSize=512m"
        }
    }
}

Incredible gradle documents

Discovering Gradle build scripts from classpath (embed gradle scripts in gradle plugin) Distribute Custom Gradle (wrapper with scripts?) Provided scope in gradle, use provided scope without dependencies ending up in the distribution)

GCloud

Installation instructions

Installing on OSX

curl https://sdk.cloud.google.com | bash

Using a preview command

gcloud preview app deploy

Kubernetes

Install kubectl gcloud components install kubectl

Debug Java

-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=33777 -Dcom.sun.management.jmxremote.rmi.port=33777 -Djava.rmi.server.hostname=127.0.0.1 -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false

Shells

Restart shell

exec -l $SHELL

Zsh/Bash keyboard commands

Tables generated with Tables Generator

Cut / Paste in terminal (Readline Kill / Yank)

Keys Command
C-k Readline kill
C-y Readline yank

More cutting

Keys Command
Alt-d Cut forward to end of word
Ctrl-w Cut backwards to beginning of word
Ctrl-u Cut backwards to beginning of line
Ctrl-space Set mark (start selecting)
Ctrl-2 Set mark (same as Ctrl-space)
Alt-w Cut marked area
Ctrl-x-x Start marking in opposite direction

Search backwards / forwards

Keys Command
C-r Search backwards
C-s Search forwards

Less commands

Keys Command
Spacebar Next page
b Previous page
/ Forward search
? Backward search
n Next search match
N Previous search match
q Quit

Snippets

List all changed git files and remove the first line of each file if the first line is a newline

git ls-files --modified | gxargs gsed -i '1{/^$/d}'

List directories of that are about 1 GB or larger in size

du -h -d1 | ggrep -E "[0-9]+\.?[0-9]*G"

List the 5 largest files in all subdirectories

(macOS, or linux without g prefix)

gfind -type f -exec gdu -Sh {} + | gsort -rh | head -n 5

Zsh

My self-answered stackoverflow/superuser question

Enable / disable function tracing

setopt xtrace
my_func
unsetopt xtrace

It's also possible to use (and combined with xtrace):

setopt verbose
my_func
unsetopt verbose

Predefined zsh functions

  • OSX: /usr/local/share/zsh/functions

oh-my-zsh plugins

~/.oh-my-zsh/plugins

Git

Git configuration

Tell Git not to guess, but rather insist that you set user.name and user.email explicitly before it will let you commit:

git config --global --add user.useConfigOnly true

Git push a specific commit to a specific branch

If the branch exists

git push <remotename> <commit SHA>:<remotebranchname>

If the branch does not yet exist

git push <remotename> <commit SHA>:refs/heads/<remotebranchname>

Source

Git worktree

Git worktree

git worktree add -b hotfix ../hotfix origin/master

When you are done with a linked working tree you can simply delete it

rm -rf ../hotfix

Administrative files will get gc'd, but you can do that manually too:

git worktree prune

Cleaning up

git remote prune origin
# Warning will remove all 'newly created' branches as well (removes all fully merged branches from the current branch's perspective)
git branch --merged | grep -v "\*" | grep -v master | grep -v dev | xargs -n 1 git branch -d

See stackoverflow

List changes

git log --oneline --graph origin/master..HEAD

Tag a version

git tag -a <tagname> [<commit>]
git push <remote> --tags

Push the contents of a new branch

git push <remote> HEAD:refs/for/branch-name

List all local branches with tracking information

git branch -lvv

Find a changed row

git log --patch | grep -E "(commit ([0-9]|[a-fA-F])+|((\+|\-).+(returnData)))" | less

In a specific file

git log --patch ./path/to/File.java | grep -E "(commit ([0-9]|[a-fA-F])+|((\+|\-).+(returnData)))" | less

Find a patch that contains specific words

git log -Gregex
#or
git log -Sword

Print the diff of each file matching the search:

git log -Sword -p

See answer on stack overflow

Create a topic branch from a remote branch with tracking

git branch --track topic_branch_name origin/rel-7.2.A.0

Add tracking information to an existing branch

git branch -u upstream/foo

Git subtree

Copied from this article First add a remote

git remote add -f <remote name> <git path>

Then add the subtree

git subtree add --prefix <new path of subtree> <remote> master --squash

Update the subtree later

git fetch <remote> master
git subtree pull --prefix <path of subtree> <remote> master --squash

Contribute to upstream

git subtree push --prefix=<path of subtree> <remote> <TARGET-BRANCH>

SQL

macOS

  • DB Browser for SQLite
  • Sequel Pro

StackOverflow

Atom Editor

Essential packages

C(++)

GLFW

You need to install CMake first! Instruction for Linux/OSX:

Now you can #include <GLFW/glfw3.h>

#ImGui

Framework for menus / windows in OpenGL (e.g. using GLFW)

IntelliJ

Enable Annotation processing in IntelliJ

  • Build, Execution, Deployment > Compiler > Annotation Processors > Enable annotation processing
  • Plugins > Browse repositories > Lombok
  • Add @ComponentScan annotation to your @SpringBootApplication, otherwise @Autowired can't be found by IntelliJ (?)

GPG

Logging

Cleaner log using sed

adb logcat | grep SomeTerm | sed -e 's/\/SomeOtherTerm[(].....[)]//'

Redirect std out & std err to /dev/null

command > /dev/null 2>&1

Redirecting std out & std err to two different files and seeing the output at the same time

command > >(tee ~/Desktop/buildlog/stdout.log) 2> >(tee ~/Desktop/buildlog/stderr.log >&2)

Android

Flashing CM

  • Find model files, download recovery & CM SW
  • Go to device Wiki & follow instructions

Assuming fs privileges for dev app: "run-as"

adb shell
run-as com.your.packagename
cd /data/data/com.your.pacakagename/

See this answer on stackoverflow

adb shell input script

ainput script on Github

Android annotation processing

Use Lombok + Android APT

Android APK debugging

Check for resources inside APK ~/sdk/android-curr/build-tools/21.1.1/aapt dump resources build/outputs/apk/MyApk.apk | grep raw/

Android System / Apps

get package name / apk location

adb shell pm list packages -f

get apk Manifest main info

aapt d badging <APK>

Monkey

adb shell monkey -s 20120614 -v -p com.package.name -p com.package2.name --pct-touch 20 --pct-motion 60 --pct-majornav 15 --pct-appswitch 5 --throttle 300 1000000 | tee log.txt

Systrace

~/sdk/android-curr/platform-tools/systrace/systrace.py --app=com.package.name gfx input view wm am hal res dalvik sched freq idle load

Memory usage for a process

$ adb shell dumpsys meminfo com.package.name

or

adb shell procrank | grep home

Force backup of a specific package (for testing)

Result of operation (e.g. encrypted content) is output to FD 0 (stdout) = shown in terminal.

$ adb shell bu 0 backup <package name>

More options are available in frameworks/base/cmds/bu/src/com/android/commands/bu/Backup.java

tcpdump

$ tcpdump -i <interface> -s 65535 -w <some-file>
$ tcpdump -i any -p -s 0 -w /sdcard/capture.pcap
# "-i any": listen on any network interface
# "-p": disable promiscuous mode (doesn't work anyway)
# "-s 0": capture the entire packet
# "-w": write packets to a file (rather than printing to stdout)

Only for loopback:

$ adb shell "tcpdump -i lo  -vv -s 0 -w /sdcard/tcpoutput.pcap"

Android Screens and resolution

DPI Scale factors

  • LDPI = 0.75
  • MDPI = 1
  • TVDPI = 1.33
  • HDPI = 1.5
  • XHDPI = 2
  • XXHDPI = 3

System Screen Density

Density

$ adb shell getprop ro.sf.lcd_density

Screen width

$ adb shell dumpsys window | grep DisplayWidth

Simulate screen density and resolution

Ex. HVGA

$ adb shell wm size 320x480
$ adb shell wm density 160

Ex. Tablet

$ adb shell wm size 1080x1920
$ adb shell wm density 240

Tip: kill com.android.systemui from DDMS to force it to load the correct resources.

SQLite extra logging

$ adb shell setprop log.tag.SQLiteLog V
$ adb shell setprop log.tag.SQLiteStatements V
$ adb shell stop
$ adb shell start

Device emulator with latency/delay

emulator -avd <some avd> -netdelay 400:1200 -netspeed gsm

Unix Common

Find files while excluding directories

Note from the manual:

  Operators
        Operators join together the other items within the expression.
        They include for example -o (meaning logical OR)
        and -a (meaning logical AND).
        Where an operator is missing, -a is assumed.
gfind . -type d \
  \( \
    -path ./node_modules \
    -o -path ./.git \
  \) \
  -prune \
  -o -type f -name "*.ts*" -print | gxargs wc -l

So logically this means

  • Find from . all -type d
    • And from that list if the path is
      • node_modiles
      • OR .git
    • Then -prune the list of those directories
  • After pruning

Make sudo password entry visible character-by-character

sudo visudo

# Find this line
Defaults        env_reset

# Change to this line
Defaults        env_reset,pwfeedback

# Now timeout your sudo session and test it
sudo -k

# Should prompt your password again
sudo visudo

Make a random string

RANDOM_STRING=$(env LC_CTYPE=C tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w 64 | head -n 1)

Make a random big file

Linux

Poll status of running dd, (status will be printed in the terminal running dd).

sudo dd if=/dev/urandom of=./bigfile bs=1M count=458000

#check status
sudo kill -USR1 `pidof dd`

macOS

sudo dd if=/dev/urandom of=./bigfile bs=1m count=458000
#check status
sudo kill -INFO `pidof dd`

Loop over a number of files and execute a command for each one

for f in $(find -name "*.apk"); do adb install -r $f; done

Remove CRLF at the end of lines in a file

Use dos2unix command in ubuntu

List all open files and the program that is keeping the file open

lsof

Or on macos you can also use

sudo fs_usage

Find my external ip using the command line

dig +short myip.opendns.com @resolver1.opendns.com

Peak memory usage of a process run

Use the memusg script, as explained here.

Jekyll

# While developing
jekyll serve
# Before launching
jekyll build

Environments (rbenv, jenv...)

iOS / XCode

Investigate crash without proper stack with attached debugger

First try to find the memory address of the instance you want to inspect. That can be done with e.g. the memory graph in XCode.

Then, in the LLDB prompt:

(lldb) expr -l Swift -- let $my = unsafeBitCast(0x98f63c31, to: MyClass.self)
(lldb) expr -l Swift -- print($my.thing)

Get list of running and shut down emulators

xcrun simctl list devices

#or

xcrun simctl list devices | grep Booted

XCode Cleanup

  • Archives - Delete from Organizer
  • Simulators - Delete from XCode then xcrun simctl delete unavailable
  • Device debug symbols - Delete unwanted from ~/Library/Developer/Xcode/iOS DeviceSupport/

Directory of a simulator

~/Library/Developer/CoreSimulator/Devices/<DEVICE_ID_FROM_SIMCTL>/

Concurrency

GCD tutorial @ raywenderlich

  • Queue types

  • Custom Serial Queue

  • Global Concurrent Queue

  • Custom Concurrent Queue

  • Concurrent queues

  • QOS_CLASS_USER_INTERACTIVE: UI updates, small workloads

  • QOS_CLASS_USER_INITIATED: Waiting for immediate result, required for continued user interaction

  • QOS_CLASS_UTILITY: Long running tasks with progress

  • QOS_CLASS_BACKGROUND: User is unaware

  • Methods

  • dispatch_get_main_queue

  • dispatch_get_global_queue

  • dispatch_queue_create: instantiate with reverse DNS style name

  • DISPATCH_QUEUE_CONCURRENT

  • DISPATCH_QUEUE_SERIAL (or) nil / NULL / 0: Serial queue

  • dispatch_queue_attr_make_with_qos_class: Usage = private let serialQueue = dispatch_queue_create("my.reverse.dns", dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_BACKGROUND, 0))

  • dispatch_after

  • dispatch_sync:

  • dispatch_async

  • dispatch_barrier_async

  • Dispatch barrier (dispatch_barrier_async) advice

  • Custom Serial Queue: Don't use dispatch barrier, doesn't make sense

  • Global Concurrent Queue: Be careful, can starve other global tasks

  • Custom Concurrent Queue: Do use

Testing network conditions using WiFi

Python

Dive Into Python 3

Miniconda

Install

brew cask install miniconda

Aliases

I have put a custom conda plugin in .oh-my-zsh

Other stuff

#Check which sandboxes you already have
conda info -e

#Create a new sandbox
conda create -n my_sandbox python=3.6

#Use the sandbox in this terminal
source activate my_sandbox

#iPython is probably useful
conda install ipython

#When you feel done use
source deactivate

Use iPython

$ ipython
from webmonkey import monkey
mon = monkey.SW()
mon.driver...

Javascript

Node

Stringify

JSON.stringify is great but sometimes complex node objects have recursive pointers.

Use this instead:

const util = require('util')

console.log(util.inspect(myObject, {showHidden: false, depth: null}))

Or just use console.log or console.dir which use it implicitly.

NVM

Example: Node 7.10 and NPM 5.0.1

nvm install 7.10
nvm use 7.10
npm install -g [email protected]

packages

Prepare a canvas for HiDPI use

pixelRatio(canvas) {
  var ctx = canvas.getContext("2d"),
    dpr = window.devicePixelRatio || 1,
    bsr = ctx.webkitBackingStorePixelRatio ||
      ctx.mozBackingStorePixelRatio ||
      ctx.msBackingStorePixelRatio ||
      ctx.oBackingStorePixelRatio ||
      ctx.backingStorePixelRatio || 1;

  return dpr / bsr;
}

prepareCanvas(canvas, width, height) {
  var pixelRatio = this.pixelRatio(canvas);
  canvas.width = width * pixelRatio;
  canvas.height = height * pixelRatio;
  canvas.style.width = width + "px";
  canvas.style.height = height + "px";
  return pixelRatio;
}

Virtual machine using Vagrant & VirtualBox

Vagrant is an easy way to set up virtual machines. Don't forget to install VirtualBox.

Vagrantfile example

Place this file in ~/vagrant/Vagrantfile

Vagrant up

To start the machine in go to the directory with the Vagrantfile and do

vagrant up

Vagrant ssh

To enter the machine do

vagrant ssh

More commands

#Save the current state and stop
vagrant suspend

#Shut down the OS and power down the guest machine
vagrant halt

#Completely remove the machine from the host
vagrant destroy

#Upgrade e.g. ubuntu
vagrant box update

nmap

List all IP addresses of a certain subnet

nmap -sn 192.168.1.0/24

macOS

Settings

Keyboard repeat rate - sign out required?

defaults write -g KeyRepeat -float 1.8
defaults write -g InitialKeyRepeat -int 15

Dock animation speed

defaults write com.apple.dock autohide-time-modifier -int 0;killall Dock

Show hidden files

defaults write com.apple.finder AppleShowAllFiles YES;killall Finder

Key repeat not working in some apps, reboot needed:

defaults write -g ApplePressAndHoldEnabled -bool false

Set the screenshot directory

defaults write com.apple.screencapture location /Users/myuser/some/path

Turn off charging hardware chime

defaults write com.apple.PowerChime ChimeOnNoHardware -bool true
killall PowerChime

Kernel modules extensions (.kext)

Kernel modules can be located in these locations

  • User kexts /Library/Extensions
  • System kexts /System/Library/Extensions

List loaded modules

kextstat

Uninstall a .kext

sudo kextunload /Library/Extensions/SomeKernelExtension.kext
sudo rm -rf /Library/Extensions/SomeKernelExtension.kext

Also check if there are things hanging around in Receipts

# Remove any Receipts that belong to a .kext
lsa -lsa /Library/Receipts/

Multiple disk dropbox sync

Follow this guide on Lifehacker. Or from the original source.

But use the modified version below to avoid the Automator Cog, which shows up unless you redirect the log to /dev/null.

Basically:

  • Create a folder somewhere, e.g. in home folder called ~/.dropbox2
  • In Automator
    • File > New > Application option
    • Drag the "Run Shell Script" action into the main window
    • Paste this HOME=$HOME/.dropbox2 /Applications/Dropbox.app/Contents/MacOS/Dropbox &>/dev/null &
    • When the disk is attached, run the program - Before the disk is detached, close Dropbox2 (exit the second dropbox instance).

Check what is preventing your computer from going to sleep

pmset -g assertions

Environment variables

#These won't end up in your terminal PATH
defaults write ~/.MacOSX/environment PATH "/all/your/paths/:/paths/"

Find the program running on a port

sudo lsof -i :8080

##Improve performance MacOS X (on mid 2014 rMBP) has pretty bad performance on an external 4k display. These tips might help:

Tweaks

Copy public key

pbcopy < ~/.ssh/id_rsa.pub

List of OSX Apps

Essential

Optional

Lifehacker essential mac list

SDKMAN!

SDK Manager for Java based languages https://sdkman.io/.

Brew / Homebrew

Create a brew bundle

First install brew bundle by simply writing brew bundle in the terminal, which is also the command for installing everything in the bundle file in the current directory.

Create a Homebrew bundle in the form of a Brewfile, which declares all taps and packages that you have installed.

Create a Brewfile from scratch in the current directory:

brew bundle dump --file ./Brewfile --force

To uninstall all Homebrew formulae not listed in Brewfile:

brew bundle cleanup

List packages

brew list

Fetch new package info

brew update

List outdated packages

brew outdated

Upgrade outdated package

brew upgrade <pkg>

Upgrade all packages

brew upgrade

Cleanup / Remove unused versions

This command is very useful because a lot of space can be wasted on unused versions

brew cleanup

Essential brew packages (with explanations)

Install with brew install

  • awscli
  • bmon - (network monitoring)
  • curl
  • findutils - (GNU findutils gfind, gxargs, ...)
  • gradle
  • [grep] - (ggrep)
  • groovy - (Groovy programming language)
  • moreutils (contains ts for prepending datetime to terminal lines)
  • nmap - (Network mapper)
  • node - (NodeJS)
  • openssl
  • pidof - (find PIDs of named program)
  • swiftlint - (XCode swift linting)
  • tree
  • unrar
  • wget
  • zsh
  • OpenJDK
    • brew tap AdoptOpenJDK/openjdk then brew cask install adoptopenjdk11
    • AdoptOpenJDK

Git for OSX

Install:

brew install git

Or if you want to use git with git-extras you should probably use

brew install git --without-completions

git-extras

According to README.md in ~/.oh-my-zsh/plugins/git-extras:

On OS X with Homebrew, you need to install git with brew install git --without-completions. Otherwise, git's _git will take precedence, and you won't see the completions for git-extras commands.

Then install git-extras itself via brew install git-extras

Monitor network / bandwidth with bmon

brew install bmon

Stay sane

Workarounds

IntelliJ can't find git executable for use in exec()

If you installed git from git-scm.org according to the instructions, you need to symlink /usr/bin/git to /usr/local/git/bin/git otherwise intellij can't find git in exec().

Potentially useful

  • JEnv Set Java Home, locally for a given path if you want.

Launch an app from terminal

Example with Atlassian SourceTree

open -a SourceTree <path/to/repository>

Launch an OSX app from terminal with logs from that app

Example: QuickTime Player

cd /Applications/QuickTime Player.app/Contents/MacOS%
./QuickTime\ Player

File system tracing OSX

Same as Unix/Linux

lsof

Erase SSD / Hard drive

  • Turn on computer
  • When the mac sound plays press ⌘ + R
  • Enter disk utility and mount the disk (if it is encrypted it is not auto mounted)
  • Exit disk utility, enter Terminal via menu bar
  • In terminal write diskutil secureErase freespace 4 /Volumes/Macintosh\ HD
  • If your disk is named something else you need to adapt the command

Source

Somewhat updated list of brew packages (brew list)

% brew list

autoconf    gawk      libffi      mtr     socat
automake    gdbm      libgpg-error    nmap      sqlite
awscli      gettext     libksba     node      stress
bash      git     libogg      openssl     swiftlint
bmon      glib      libpng      openvpn     tcl-tk
cairo     gmp     libquvi     opus      texi2html
cmake     gnu-sed     libtool     pcre      tldr
confuse     gobject-introspection libvo-aacenc    pidof     tree
curl      gradle      libvorbis   pixman      unrar
dos2unix    grep      libyaml     pkg-config    wget
faac      groovy      libzip      protobuf    x264
fdk-aac     harfbuzz    lua     protobuf-swift    xvid
findutils   icdiff      lzo     python3     xz
fontconfig    icu4c     maven     qt      yasm
freetype    lame      mpfr      readline    zeromq
fribidi     libass      mplayer     sdl     zsh

#Windows

Linux

Sudoers

This command edits the sudoers file:

sudo visudo

Here is an explanation on askubuntu.

Another way of doing it is adding only your own user as a sudoer:

myusername     ALL=(ALL:ALL) NOPASSWD:ALL

Java alternatives

Used to select what java versions are used, on Ubuntu Linux (probably other dists as well)

$ sudo update-alternatives --config java
$ sudo update-alternatives --config javac
$ sudo update-alternatives --config jar
$ update-java-alternatives -l

Gnome 3

Gnome HiDPI info on Archlinux wiki.

Basically you first scale up to 2x2 (X only supports integer scaling, Wayland probably will handle floats):

gsettings set org.gnome.desktop.interface scaling-factor 2
# There is a UI setting for this in Gnome, but I didn't feel it went "all the way":
Gnome Tweak Tool -> Windows -> HiDPI -> Window scaling = 2

Now you can "Zoom Out":

# Fetch display name
xrandr | grep -v disconnected | grep connected | cut -d' ' -f1
# Zoom out
xrandr --output <DISPLAY NAME FROM PREVIOUS COMMAND> --scale 1.2x1.2

If you are having problems with e.g. mouse: See archlinux wiki above.

OpenVPN

Example configuration files here

Configure the server

Configuration in /etc/openvpn/. Client config in .ovpn files.

iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o <DEVICE e.g. eth0 but probably something else> -j MASQUERADE

And clear the rule when done

sudo iptables -t nat -F

Using the server:

Update local name.ovpn file with the current correct external IP of the VPN server.

"server" in the command is the name of the configuration file

sudo systemctl start openvpn@server

Restart

sudo systemctl restart openvpn@server

Configure ASUS router

Ubuntu 12.04

$ vboxmanage createhd --size 40960 --variant Fixed --filename new.vdi
$ vboxmanage clonehd old.vdi new.vdi –existing
Then, inside windows: extend partition.
Or, [for dynamic size disks](https://brainwreckedtech.wordpress.com/2012/01/08/howto-convert-vdis-between-fixed-sized-and-dynamic-in-virtualbox/)
$ vboxmanage modifyhd [VDI] --resize [megabytes]
Then, inside windows: extend partition.

Quotes

Collection of development related lol-quotes

Unread blog post pipeline

Incomplete list of nice blog posts and such

About

Use this repository instead of your brain. Super helpful?

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published