Frequently used
Git
- Remove local branches not in remote
git pull && git fetch --prune && git branch -vv | grep ': gone]' | awk '{print $1}' | xargs git branch -D
VSCode
-
Select all occurrences of selected word: Cmd + F2
-
Auto Indent Code: Shift + Option + F
-
Goto recent file: Cmd + P
-
Multi-Cursor: Option + Click
-
Navigate Backward/Forward: Ctrl + - / Ctrl + Shift + -
-
Rulers: "editor.rulers": [80,120]
-
Remove trailing spaces:
- Code > Settings > Settings > User Settings > search for "files.trimTrailingWhitespace"
-
Disable Sticky Scroll:
- Code > Settings > Settings > Editor > Sticky Scroll (editor.stickyScroll.enabled)
IntelliJ
-
Reformat Code: Cmd + Option + L
-
Goto Declaration: Cmd + B
-
Goto Implementation: Cmd + Option + B
-
Search Everywhere: Double Shift
-
Navigating Backward and Forward: Cmd + [/]
-
How to change line width:
- Settings > Editor > Code Style > Hard Wrap at
- Settings > Editor > Code Style > Visual Guides
- .editorconfig > max_line_length = ..
-
Remove trailing spaces:
- Settings > Editor > General > Strip trailing spaces on Save
macOS
-
Update from the Terminal
echo '<password>' | sudo softwareupdate -iaR --user <username> --stdinpass && history -p && rm ~/.zsh_history
-
Restart from the Terminal
sudo shutdown -r now
Python dance
- Better Python packaging: UV
### Install.
$ curl -LsSf https://astral.sh/uv/install.sh | sh
$ uv self update
### Sample
$ uv init example
Initialized project `example` at `/home/user/example`
$ cd example
$ uv add ruff
Creating virtual environment at: .venv
Resolved 2 packages in 170ms
Built example @ file:///home/user/example
Prepared 2 packages in 627ms
Installed 2 packages in 1ms
+ example==0.1.0 (from file:///home/user/example)
+ ruff==0.5.0
$ uv run ruff check
All checks passed!
### Tools
$ uv tool install ruff
Resolved 1 package in 6ms
Installed 1 package in 2ms
+ ruff==0.5.0
Installed 1 executable: ruff
$ ruff --version
ruff 0.5.0
- .... otherwise
python3 -m venv venv
source venv/bin/activate
pip3 install -r requirements.txt
python3 main.py
deactivate
Android
-
How to list the avds available on the computer
$ANDROID_HOME/emulator/emulator -list-avds
-
How to start an avd
$ANDROID_HOME/emulator/emulator -avd <avd-name>
-
What is the default location of the develop app built for Android in gradle
./build/outputs/apk/develop/debug/app.apk
-
What is the default location of the test app (using Espresso)
./build/outputs/apk/androidTest/develop/debug/app.apk
-
How to run single instrumentation test class (-q is for quiet). For multiple classes, they can be comma-separated
./gradlew -q -Pandroid.testInstrumentationRunnerArguments.class=<full classpath>#<test name> <app>:connected<Variant Name>AndroidTest
-
How to run a single instrumentation test (-q is for quiet)
./gradlew -q -Pandroid.testInstrumentationRunnerArguments.class=<full classpath> <app>:connected<Variant Name>AndroidTest
-
How to run an instrumented test using adb
./gradlew install<Variant Name>AndroidTest
adb shell am instrument -w -e class com.example.MyInstrumentationTest#testFoo com.example.test/android.support.test.runner.AndroidJUnitRunner
-
How to list all dependencies for an app
./gradlew app:dependencies
For more insights:
./gradlew :app:dependencyInsight --configuration compile --dependency <name>
./gradlew :app:dependencyInsight --configuration testCompile --dependency <name>
./gradlew :app:dependencyInsight --configuration androidTestCompile --dependency <name>
-
How to compile and run a dex file directly on an Android phone
javac <file.java> java <classname> dx –dex –output=<file.dex> <file.class> adb push <file.dex> </data/local/tmp> adb shell dalvikvm –cp </data/local/tmp><file.dex> <classname>
Android Debug Bridge (adb)
-
How to use the laptop as server reachable froma connected Android phone:
adb reverse tcp:3000 tcp:3000
-
Summary of useful adb commands from here
adb help // List all comands
== Adb Server
adb kill-server
adb start-server
== Adb Reboot
adb reboot
adb reboot recovery
adb reboot-bootloader
adb root //restarts adb with root permissions
== Shell
adb shell // Open or run commands in a terminal on the host Android device.
== Devices
adb usb
adb devices //show devices attached
adb devices -l //devices (product/model)
adb connect ip_address_of_device
== Get device android version
adb shell getprop ro.build.version.release
== LogCat
adb logcat
adb logcat -c // clear // The parameter -c will clear the current logs on the device.
adb logcat -d > [path_to_file] // Save the logcat output to a file on the local system.
adb bugreport > [path_to_file] // Will dump the whole device information like dumpstate, dumpsys and logcat output.
== Files
adb push [source] [destination] // Copy files from your computer to your phone.
adb pull [device file location] [local file location] // Copy files from your phone to your computer.
== App install
adb -e install path/to/app.apk
-d - directs command to the only connected USB device...
-e - directs command to the only running emulator...
-s <serial number> ...
-p <product name or path> ...
The flag you decide to use has to come before the actual adb command:
adb devices | tail -n +2 | cut -sf 1 | xargs -IX adb -s X install -r com.myAppPackage // Install the given app on all connected devices.
== Uninstalling app from device
adb uninstall com.myAppPackage
adb uninstall <app .apk name>
adb uninstall -k <app .apk name> -> "Uninstall .apk withour deleting data"
adb shell pm uninstall com.example.MyApp
adb shell pm clear [package] // Deletes all data associated with a package.
adb devices | tail -n +2 | cut -sf 1 | xargs -IX adb -s X uninstall com.myAppPackage //Uninstall the given app from all connected devices
== Update app
adb install -r yourApp.apk // -r means re-install the app and keep its data on the device.
adb install –k <.apk file path on computer>
== Home button
adb shell am start -W -c android.intent.category.HOME -a android.intent.action.MAIN
== Activity Manager
adb shell am start -a android.intent.action.VIEW
adb shell am broadcast -a 'my_action'
adb shell am start -a android.intent.action.CALL -d tel:+972527300294 // Make a call
// Open send sms screen with phone number and the message:
adb shell am start -a android.intent.action.SENDTO -d sms:+972527300294 --es sms_body "Test --ez exit_on_sent false
// Reset permissions
adb shell pm reset-permissions -p your.app.package
adb shell pm grant [packageName] [ Permission] // Grant a permission to an app.
adb shell pm revoke [packageName] [ Permission] // Revoke a permission from an app.
// Emulate device
adb shell wm size 2048x1536
adb shell wm density 288
// And reset to default
adb shell wm size reset
adb shell wm density reset
== Print text
adb shell input text 'Wow, it so cool feature'
== Screenshot
adb shell screencap -p /sdcard/screenshot.png
$ adb shell
shell@ $ screencap /sdcard/screen.png
shell@ $ exit
$ adb pull /sdcard/screen.png
---
adb shell screenrecord /sdcard/NotAbleToLogin.mp4
$ adb shell
shell@ $ screenrecord --verbose /sdcard/demo.mp4
(press Control + C to stop)
shell@ $ exit
$ adb pull /sdcard/demo.mp4
== Key event
adb shell input keyevent 3 // Home btn
adb shell input keyevent 4 // Back btn
adb shell input keyevent 5 // Call
adb shell input keyevent 6 // End call
adb shell input keyevent 26 // Turn Android device ON and OFF. It will toggle device to on/off status.
adb shell input keyevent 27 // Camera
adb shell input keyevent 64 // Open browser
adb shell input keyevent 66 // Enter
adb shell input keyevent 67 // Delete (backspace)
adb shell input keyevent 207 // Contacts
adb shell input keyevent 220 / 221 // Brightness down/up
adb shell input keyevent 277 / 278 /279 // Cut/Copy/Paste
0 --> "KEYCODE_0"
1 --> "KEYCODE_SOFT_LEFT"
2 --> "KEYCODE_SOFT_RIGHT"
3 --> "KEYCODE_HOME"
4 --> "KEYCODE_BACK"
5 --> "KEYCODE_CALL"
6 --> "KEYCODE_ENDCALL"
7 --> "KEYCODE_0"
8 --> "KEYCODE_1"
9 --> "KEYCODE_2"
10 --> "KEYCODE_3"
11 --> "KEYCODE_4"
12 --> "KEYCODE_5"
13 --> "KEYCODE_6"
14 --> "KEYCODE_7"
15 --> "KEYCODE_8"
16 --> "KEYCODE_9"
17 --> "KEYCODE_STAR"
18 --> "KEYCODE_POUND"
19 --> "KEYCODE_DPAD_UP"
20 --> "KEYCODE_DPAD_DOWN"
21 --> "KEYCODE_DPAD_LEFT"
22 --> "KEYCODE_DPAD_RIGHT"
23 --> "KEYCODE_DPAD_CENTER"
24 --> "KEYCODE_VOLUME_UP"
25 --> "KEYCODE_VOLUME_DOWN"
26 --> "KEYCODE_POWER"
27 --> "KEYCODE_CAMERA"
28 --> "KEYCODE_CLEAR"
29 --> "KEYCODE_A"
30 --> "KEYCODE_B"
31 --> "KEYCODE_C"
32 --> "KEYCODE_D"
33 --> "KEYCODE_E"
34 --> "KEYCODE_F"
35 --> "KEYCODE_G"
36 --> "KEYCODE_H"
37 --> "KEYCODE_I"
38 --> "KEYCODE_J"
39 --> "KEYCODE_K"
40 --> "KEYCODE_L"
41 --> "KEYCODE_M"
42 --> "KEYCODE_N"
43 --> "KEYCODE_O"
44 --> "KEYCODE_P"
45 --> "KEYCODE_Q"
46 --> "KEYCODE_R"
47 --> "KEYCODE_S"
48 --> "KEYCODE_T"
49 --> "KEYCODE_U"
50 --> "KEYCODE_V"
51 --> "KEYCODE_W"
52 --> "KEYCODE_X"
53 --> "KEYCODE_Y"
54 --> "KEYCODE_Z"
55 --> "KEYCODE_COMMA"
56 --> "KEYCODE_PERIOD"
57 --> "KEYCODE_ALT_LEFT"
58 --> "KEYCODE_ALT_RIGHT"
59 --> "KEYCODE_SHIFT_LEFT"
60 --> "KEYCODE_SHIFT_RIGHT"
61 --> "KEYCODE_TAB"
62 --> "KEYCODE_SPACE"
63 --> "KEYCODE_SYM"
64 --> "KEYCODE_EXPLORER"
65 --> "KEYCODE_ENVELOPE"
66 --> "KEYCODE_ENTER"
67 --> "KEYCODE_DEL"
68 --> "KEYCODE_GRAVE"
69 --> "KEYCODE_MINUS"
70 --> "KEYCODE_EQUALS"
71 --> "KEYCODE_LEFT_BRACKET"
72 --> "KEYCODE_RIGHT_BRACKET"
73 --> "KEYCODE_BACKSLASH"
74 --> "KEYCODE_SEMICOLON"
75 --> "KEYCODE_APOSTROPHE"
76 --> "KEYCODE_SLASH"
77 --> "KEYCODE_AT"
78 --> "KEYCODE_NUM"
79 --> "KEYCODE_HEADSETHOOK"
80 --> "KEYCODE_FOCUS"
81 --> "KEYCODE_PLUS"
82 --> "KEYCODE_MENU"
83 --> "KEYCODE_NOTIFICATION"
84 --> "KEYCODE_SEARCH"
85 --> "KEYCODE_MEDIA_PLAY_PAUSE"
86 --> "KEYCODE_MEDIA_STOP"
87 --> "KEYCODE_MEDIA_NEXT"
88 --> "KEYCODE_MEDIA_PREVIOUS"
89 --> "KEYCODE_MEDIA_REWIND"
90 --> "KEYCODE_MEDIA_FAST_FORWARD"
91 --> "KEYCODE_MUTE"
92 --> "KEYCODE_PAGE_UP"
93 --> "KEYCODE_PAGE_DOWN"
94 --> "KEYCODE_PICTSYMBOLS"
...
122 --> "KEYCODE_MOVE_HOME"
123 --> "KEYCODE_MOVE_END"
// https://developer.android.com/reference/android/view/KeyEvent.html
== ShPref
# replace org.example.app with your application id
# Add a value to default shared preferences.
adb shell 'am broadcast -a org.example.app.sp.PUT --es key key_name --es value "hello world!"'
# Remove a value to default shared preferences.
adb shell 'am broadcast -a org.example.app.sp.REMOVE --es key key_name'
# Clear all default shared preferences.
adb shell 'am broadcast -a org.example.app.sp.CLEAR --es key key_name'
# It's also possible to specify shared preferences file.
adb shell 'am broadcast -a org.example.app.sp.PUT --es name Game --es key level --ei value 10'
# Data types
adb shell 'am broadcast -a org.example.app.sp.PUT --es key string --es value "hello world!"'
adb shell 'am broadcast -a org.example.app.sp.PUT --es key boolean --ez value true'
adb shell 'am broadcast -a org.example.app.sp.PUT --es key float --ef value 3.14159'
adb shell 'am broadcast -a org.example.app.sp.PUT --es key int --ei value 2015'
adb shell 'am broadcast -a org.example.app.sp.PUT --es key long --el value 9223372036854775807'
# Restart application process after making changes
adb shell 'am broadcast -a org.example.app.sp.CLEAR --ez restart true'
== Monkey
adb shell monkey -p com.myAppPackage -v 10000 -s 100 // monkey tool is generating 10.000 random events on the real device
== Paths
/data/data/<package>/databases (app databases)
/data/data/<package>/shared_prefs/ (shared preferences)
/data/app (apk installed by user)
/system/app (pre-installed APK files)
/mmt/asec (encrypted apps) (App2SD)
/mmt/emmc (internal SD Card)
/mmt/adcard (external/Internal SD Card)
/mmt/adcard/external_sd (external SD Card)
adb shell ls (list directory contents)
adb shell ls -s (print size of each file)
adb shell ls -R (list subdirectories recursively)
== Device onformation
adb get-statе (print device state)
adb get-serialno (get the serial number)
adb shell dumpsys iphonesybinfo (get the IMEI)
adb shell netstat (list TCP connectivity)
adb shell pwd (print current working directory)
adb shell dumpsys battery (battery status)
adb shell pm list features (list phone features)
adb shell service list (list all services)
adb shell dumpsys activity <package>/<activity> (activity info)
adb shell ps (print process status)
adb shell wm size (displays the current screen resolution)
dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp' (print current app's opened activity)
== Package info
adb shell list packages (list package names)
adb shell list packages -r (list package name + path to apks)
adb shell list packages -3 (list third party package names)
adb shell list packages -s (list only system packages)
adb shell list packages -u (list package names + uninstalled)
adb shell dumpsys package packages (list info on all apps)
adb shell dump <name> (list info on one package)
adb shell path <package> (path to the apk file)
==Configure Settings Commands
adb shell dumpsys battery set level <n> (change the level from 0 to 100)
adb shell dumpsys battery set status<n> (change the level to unknown, charging, discharging, not charging or full)
adb shell dumpsys battery reset (reset the battery)
adb shell dumpsys battery set usb <n> (change the status of USB connection. ON or OFF)
adb shell wm size WxH (sets the resolution to WxH)
== Device Related Commands
adb reboot-recovery (reboot device into recovery mode)
adb reboot fastboot (reboot device into recovery mode)
adb shell screencap -p "/path/to/screenshot.png" (capture screenshot)
adb shell screenrecord "/path/to/record.mp4" (record device screen)
adb backup -apk -all -f backup.ab (backup settings and apps)
adb backup -apk -shared -all -f backup.ab (backup settings, apps and shared storage)
adb backup -apk -nosystem -all -f backup.ab (backup only non-system apps)
adb restore backup.ab (restore a previous backup)
adb shell am start|startservice|broadcast <INTENT>[<COMPONENT>]
-a <ACTION> e.g. android.intent.action.VIEW
-c <CATEGORY> e.g. android.intent.category.LAUNCHER (start activity intent)
adb shell am start -a android.intent.action.VIEW -d URL (open URL)
adb shell am start -t image/* -a android.intent.action.VIEW (opens gallery)
== Logs
adb logcat [options] [filter] [filter] (view device log)
adb bugreport (print bug reports)
== Other
adb backup // Create a full backup of your phone and save to the computer.
adb restore // Restore a backup to your phone.
adb sideload // Push and flash custom ROMs and zips from your computer.
fastboot devices
// Check connection and get basic information about devices connected to the computer.
// This is essentially the same command as adb devices from earlier.
//However, it works in the bootloader, which ADB does not. Handy for ensuring that you have properly established a connection.
--------------------------------------------------------------------------------
Shared Preferences
# replace org.example.app with your application id
# Add a value to default shared preferences.
adb shell 'am broadcast -a org.example.app.sp.PUT --es key key_name --es value "hello world!"'
# Remove a value to default shared preferences.
adb shell 'am broadcast -a org.example.app.sp.REMOVE --es key key_name'
# Clear all default shared preferences.
adb shell 'am broadcast -a org.example.app.sp.CLEAR --es key key_name'
# It's also possible to specify shared preferences file.
adb shell 'am broadcast -a org.example.app.sp.PUT --es name Game --es key level --ei value 10'
# Data types
adb shell 'am broadcast -a org.example.app.sp.PUT --es key string --es value "hello world!"'
adb shell 'am broadcast -a org.example.app.sp.PUT --es key boolean --ez value true'
adb shell 'am broadcast -a org.example.app.sp.PUT --es key float --ef value 3.14159'
adb shell 'am broadcast -a org.example.app.sp.PUT --es key int --ei value 2015'
adb shell 'am broadcast -a org.example.app.sp.PUT --es key long --el value 9223372036854775807'
# Restart application process after making changes
adb shell 'am broadcast -a org.example.app.sp.CLEAR --ez restart true'
--------------------------------------------------------------------------------
=== Few bash snippets ===
@Source (https://jonfhancock.com/bash-your-way-to-better-android-development-1169bc3e0424)
=== Using tail -n
//Use tail to remove the first line. Actually two lines. The first one is just a newline. The second is “List of devices attached.”
$ adb devices | tail -n +2
=== Using cut -sf
// Cut the last word and any white space off the end of each line.
$ adb devices | tail -n +2 | cut -sf -1
=== Using xargs -I
// Given the -I option, xargs will perform an action for each line of text that we feed into it.
// We can give the line a variable name to use in commands that xargs can execute.
$ adb devices | tail -n +2 | cut -sf -1 | xargs -I X echo X aw yiss
=== Three options below together
// Will print android version of all connected devices
adb devices | tail -n +2 | cut -sf -1 | xargs -I X adb -s X shell getprop ro.build.version.release
=== Using alias
-- Example 1
alias tellMeMore=echo
tellMeMore "hi there"
Output => hi there
-- Example 2
// Define alias
alias apkinstall="adb devices | tail -n +2 | cut -sf 1 | xargs -I X adb -s X install -r $1"
// And you can use it later
apkinstall ~/Downloads/MyAppRelease.apk // Install an apk on all devices
-- Example 3
alias rmapp="adb devices | tail -n +2 | cut -sf 1 | xargs -I X adb -s X uninstall $1"
rmapp com.example.myapp // Uninstall a package from all devices
-- Example 4
alias clearapp="adb devices | tail -n +2 | cut -sf 1 | xargs -I X adb -s X shell pm clear $1"
clearapp com.example.myapp // Clear data on all devices (leave installed)
-- Example 5
alias startintent="adb devices | tail -n +2 | cut -sf 1 | xargs -I X adb -s X shell am start $1"
startintent https://twitter.com/JonFHancock // Launch a deep link on all devices
Setting up your .bash_profile
Finally, to make this all reusable even after rebooting your computer (aliases only last through the current session), we have to add these to your .bash_profile. You might or might not already have a .bash_profile, so let’s make sure we append to it rather than overwriting it. Just open a terminal, and run the following command
touch .bash_profile && open .bash_profile
This will create it if it doesn’t already exist, and open it in a text editor either way. Now just copy and paste all of the aliases into it, save, and close.
alias startintent="adb devices | tail -n +2 | cut -sf 1 | xargs -I X adb -s X shell am start $1"
alias apkinstall="adb devices | tail -n +2 | cut -sf 1 | xargs -I X adb -s X install -r $1"
alias rmapp="adb devices | tail -n +2 | cut -sf 1 | xargs -I X adb -s X uninstall $1"
alias clearapp="adb devices | tail -n +2 | cut -sf 1 | xargs -I X adb -s X shell pm clear $1"
===============================================================
Sources:
- Internet
- https://www.automatetheplanet.com/adb-cheat-sheet/
Ansible
-
How to learn the basics of Ansible: Basic course
-
How to run commands directly
ansible -i agents.txt all -a 'zsh -c "ls"'
-
How to run commands with a playbook
ansible-playbook -i agents.txt commands.yml
Utilities with Automator
How to paste the cliboard as keyboard for the apps that don't allow cmd-v (e.g. for security)
- Launch Automator (yup it comes with BigSur and already installed, no need to install it)
- New Document
- Click Quick Action
- Change "Workflow Receives" to "No Input"
- On the left scroll down and double click "Run AppleScript"
- Erase the Template Text and Paste the Code above "I used the basic workflow script" (you dont need both scripts)
- Save the Script - I called mine Clip2Keystrokes NOTE: You will need to add the Automator and ANY app you plan to run this script on to the Accessibility Permissions.
- Copy your text to the clipboard
- Then switch to the App you want to paste in (in my case it was a Teamviewer session)
- Click the App name in the top left (next to the apple icon), you will see a Services Menu option.
- Mouse over the Services menu and you will see your script name, "Clip2Keystrokes" in my case.
- Be sure the cursor is already where you need it to be as clicking on the script will cause it to start typing.
The script
on run
tell application "System Events"
keystroke (the clipboard)
end tell
end run
Random notes on AWS
-
How to send an email using SES
sudo pip install awscli aws configure aws ses send-email \ --from "john@gmail.com" \ --destination "ToAddresses=mike@gmail.com" \ --message "Subject={Data=from ses,Charset=utf8},Body={Text={Data=ses says hi,Charset=utf8},Html={Data=,Charset=utf8}}"
Random notes on Azure
-
How to set an organization as default using the az cli
az devops configure --defaults organization <organization url, e.g. https://dev.azure.com/...>
-
How to set a Personal Access Token (PAT) for all az commands
export AZURE_DEVOPS_EXT_PAT=<personal_pat>
-
How to use git with PAT: PAT tokens with git.
(also works using "Authorization: Bearer $PAT" instead of basic and b64).
For git LFS use something like:git config http.$origin_url.extraheader "AUTHORIZATION: bearer $SYSTEM_ACCESSTOKEN" git fetch -f origin develop:develop git config --unset http.$origin_url.extraheader
-
How to get the list of builds for a pipeline
az pipelines build list --project <projectname> --definition-ids <definition_id>
-
How to enforce using Java 11 in Azure DevOps pipelines
- script: | echo "##vso[task.setvariable variable=JAVA_HOME]$(JAVA_HOME_11_X64)" echo "##vso[task.setvariable variable=PATH]$(JAVA_HOME_11_X64)/bin:$(PATH)" displayName: "Set java 11"
-
How to create WorkItems in Azure boards via cli: Create work items in Azure Boards
-
How to call the Azure DevOps REST API: Get PAT Token Make REST call using Basic Authentication with username and PAT (as password) e.g.
curl "https://dev.azure.com/cbsp-abnamro/_apis/projects?api-version=7.0" -u "mario.negro.ponzi:<PAT>"
- Also usfeul: REST call with Azure CLI
-
How to create Azure Functions with the REST API: Creating Azure Function with REST API
-
How to edit a PAT via REST API: PAT Editing REST API
-
How to format the output in the pipelines in azure DevOps: Format output
TL;DR##[group]Beginning of a group ##[warning]Warning message ##[error]Error message ##[section]Start of a section ##[debug]Debug text ##[command]Command-line being run ##[endgroup]
-
How to use pipeline parameters and read them in a bash script
parameters: - name: publish displayName: Publish? type: boolean default: true ... - bash: | echo ${{ parameters.publish }} if [ ${{ parameters.publish }} == 'True' ] then echo "true" else echo "false" fi displayName: 'Echo and check'
Bash
-
zip all files returned by find
find ./report -maxdepth 1 -name '*.csv' | zip ./report/report.zip -m@
Bazel
Bookmarks
-
Slint: GUI for embedded systems, written in Rust, support Rust, javascript, C++
-
OpenCore Legacy Patcher: Patch system to install the latest macOS on old systems
-
Screeps: Programmable Game
-
Gladiabots: Programmable Game
-
Cursorless: Voice programming
-
Talon Excercises: Practice Talon Voice
-
Twine/Twinery: Tool for interactive non linear stories
-
How to download videos from Teams/Stream:
Open Firefox (or the browser of your choice) and load the SharePoint page with the video that you want to download, then open the page inspector (Ctrl + Shift + C). Click on the Network tab. Type videomanifest where it says "Filter URLs". Press F5 to refresh the page. When the page reloads, copy the file URL. Use ffmpeg to download the video by pasting the URL from above: ffmpeg -i "https://copied_videomanifest_url" -codec copy video.mp4 UPD: If you have an error (cannot parse file etc.) probably videomanifest url requires credentials. Then instead of copying the url you can 'Copy Response' and save it to the file (e.g. paste response to notepad and save the file). In the command line above replace the url by path to the saved file
-
Carbon.sh: Create and share beautiful images of your source code
-
Awesome Static Website Generators: curated list of static web sites generators
Rust
- A Gentle Introduction To Rust
- Rust book
- Slint: cross-platform language-agnostic UI library for desktop and embedded, not only for Rust
To be checked
- Virtual USB aka USB over internet
- Santa: Santa is a binary and file access authorization system for macOS.
- Hono: Fast lightweight JS "edge" framework
- Jest: Testing in JS
Certificates
- Old reference
- OpenSSL Cheat
- How to use OpenSSL to test SSL connectivity
- How to convert cer to pem
- How to check Python openssl
- Various OpenSSL commands
Java
- See also here
New
If one needs to add root certificates (e.g. because inside a corporate network) on macOS, having it in the keychain is not enough.
Root certificates must be added to all tools using their own keychain/keystore.
- Download the .cer and .pem file from the Keychain
- Get pem directly via cli:
openssl s_client -showcerts -connect server.edu:443 </dev/null 2>/dev/null|openssl x509 -outform PEM >mycertfile.pem
- Android Studio (or similar Java)
"/Applications/Android Studio.app/Contents/jre/Contents/Home/bin/keytool" -import -keystore "/Applications/Android Studio.app/Contents/jre/Contents/Home/lib/security/cacerts" -file "$HOME/Downloads/MYROOT.cer" -alias "MYROOT"
- Python
... libexec/lib/python3.10/site-packages/certifi/cacert.pem ... libexec/lib/python3.10/site-packages/pip/_vendor/certifi/cacert.pem
- Ruby
(and possibly also export PATH="/usr/local/opt/openssl@1.1/bin:$PATH")export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@1.1)"
- Npm
npm config set cafile "$HOME/Downloads/certificates/MYROOT.pem"
CLI
-
How to get the CPU name
sysctl -a | grep machdep.cpu.brand_string
-
How to get system info
system_profiler SPSoftwareDataType SPHardwareDataType
-
Collection #1: https://switowski.com/blog/favorite-cli-tools
-
Collection #2: from here
bat
iscat
with syntax highlighting and line numbers- diff-so-fancy shows best-looking diffs you'll ever see
- fx is the best JSON viewer you'll ever use
- fzf is an insanely fast fuzzy search written in @golang
- exa is
ls
but with coloring - duff shows a better du summary
- htop is a modern
top
replacement - hexyl is a beautiful hex viewer
- @fig is next-gen autocompletion
-
restart from terminal
sudo shutdown -r now
-
sudo with no password
sudo visudo ... <username> ALL=(ALL) NOPASSWD:ALL
If one wants to just increase the time before re-entering the sudo password, add
Defaults timestamp_timeout=3
-
update command line tools
sudo xcode-select -s /Applications/Xcode_13.2.1.app sudo rm -rf /Library/Developer/CommandLineTools sudo xcode-select --install softwareupdate --all --install --force
Note: this leaves the popup open in the GUI...
-
Create a build agent like those on Github
https://github.com/actions/virtual-environments/issues/1783 https://github.com/actions/virtual-environments/blob/main/images/macos/templates/macOS-12.json
-
Check which process is listening to which port
sudo lsof -nP -i4TCP:$POST | grep LISTEN
-
Follow the end of a log (e.g. mongo)
tail -f /opt/homebrew/var/log/mongodb/mongo.log
-
access the keychain from cli. In the command $USER refer to the current user keychain source
# store environment variable security add-generic-password -a "$USER" -s 'name_of_your_key' -w 'passphrase' # retrieve key to environment variable security find-generic-password -a "$USER" -s 'name_of_your_key' -w # store it locally NAME_OF_YOUR_KEY=$(security find-generic-password -a "$USER" -s "name_of_your_key" -w) # or NAME_OF_YOUR_KEY=`security find-generic-password -a "$USER" -s 'name_of_your_key' -w`
-
Debug startup time in the terminal
Write all steps in the file
trace
PS4='+%D{%s.%9.}:%N:%i>' zsh -c -i -x exit > trace 2>&1
Make times differential
<trace awk -F: '{printf "+%.09f", $1 - t; t=$1; $1=""; print}'
-
Prevent word wrap:
tput rmam
-
Restore word wrap:
tput smam
-
Timing shell commands:
set -x
, disabling it:set +x
-
get process that has a port open
sudo lsof -nP -i4TCP:$PORT | grep LISTEN
-
force macOS to sync time:
sudo sntp -sS time.apple.com
curl/httpie
curl
-
Follow redirects
curl -L ...
-
Upload form file:
curl -F ‘data=@path/to/local/file’ UPLOAD_ADDRESS
-
Add user agent
curl -A "user-agent-name-here" [URL] e.g. "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/81.0"
-
Download file:
curl -L -o do-bots.txt https://www.digitalocean.com/robots.txt
-
Access Token DevOps with git
MY_PAT=yourPAT # replace "yourPAT" with "PatStringFromWebUI" B64_PAT=$(printf ":%s" "$MY_PAT" | base64) git -c http.extraHeader="Authorization: Basic ${B64_PAT}" clone https://dev.azure.com/yourOrgName/yourProjectName/_git/yourRepoName
-
Access Token DevOps with curl (e.g. for feed)
MY_PAT=yourPAT # replace "yourPAT" with "PatStringFromWebUI" B64_PAT=$(printf ":%s" "$MY_PAT" | base64) curl -L -H "Authorization: Basic ${B64_PAT}" "https://feeds.dev.azure.com/${org}/${project}}/_apis/Packaging/Feeds/$feed/Packages" | jq ".value[0].versions[0].version
-
Extra header
curl https://whatever -H "X-Custom-Header: value" -H "Content-Type: application/json" -H "Authorization: bearer ********"
-
Extra header
curl https://whatever -H "X-Custom-Header: value" -H "Content-Type: application/json" -H "Authorization: basic ********"
httpie
Dart
- create dart cli project
dart create -t console-full cli
- shell interaction lib
- add dependency from cli
dart pub add [--dev] [test]
- run dart cli
dart run
Docker (macOS)
-
Install Docker Desktop with either:
brew install docker --cask
- download from Docker
-
Install Docker CLI with:
brew install docker
-
Add to the PATH the credential desktop:
export PATH=$PATH:/Applications/Docker.app/Contents/Resources/bin
-
Login to the images repo:
docker login -u <username> -p <password> <url>:<port>
-
Try ubuntu:
docker pull ubuntu
-
Check it is there:
docker images
-
Run it interactively and attach to terminal:
docker run -i -t ubuntu /bin/bash
(-d
also runs in background) -
Create a folder
folder
-
Create a Dockerfile within
folder
likeFROM ubuntu RUN apt-get update RUN apt-get install –y python3 curl CMD [“echo”,”Image created”]
-
Build and tag the image:
docker build -t ubuntu-python folder
-
Run interactively the tagged iamge:
docker run -i -t ubuntu-python /bin/bash
-
Inside the image check which version of Python got installed:
python3 --version
-
Exit:
exit
-
List containers:
docker container ls -a
-
Remove container:
docker container rm <container_id> ...
-
List images:
docker image ls
-
Remove images:
docker image rm <image name or id>
English
Expect
Automate the terminal. E.g.
#!/bin/bash
echo "Hello, who are you?"
read $REPLY
echo "Can I ask you some questions?"
read $REPLY
echo "What is your favorite topic?"
read $REPLY
#!/usr/bin/expect -f
set timeout -1
spawn ./questions
expect "Hello, who are you?\r"
send -- "Im Adam\r"
expect "Can I ask you some questions?\r"
send -- "Sure\r"
expect "What is your favorite topic?\r"
send -- "Technology\r"
expect eof
The second can be called directly.
Important comands for expect are:
- spawn Starts a script or a program.
- expect Waits for program output.
- send Sends a reply to your program.
- interact Allows you to interact with your program.
Fastlane
Assuming Fastlane match is setup and profiles are stored in a git repo.
- Create the bundle id in the Apple portal
- Add a development profile using match
bundle exec fastlane match development --app_identifier "com.negroponzi.dev.*"
- have all team use it
bundle exec fastlane match --readonly development
Flutter
- Create project:
flutter create --project-name [project_name] --org com.negroponzi [project_folder]
- List existing emulators:
flutter emulators
- Launch iOS simulator:
flutter emulators --launch apple_ios_simulator
- List running devices and emulators:
flutter devices
- Run app on a specific device:
flutter run -d [device_id]
- Add package;
flutter pub add provider
- Run all tests:
flutter test
- Run specific test (regex):
flutter test --name="Counter value should.*"
- Testing Provider
fd
-
patterns are by default but do not forget the quotes!
fd '[mn]ands'
-
Search files with extension
fd -e <ext>
-
Search ignoring case and not ingoring anything and following links
fd -iIL <name>
-
Search from a specific path
fd -e pem . '<path>'
Find
- find and zip:
find . -name "<pattern>" | zip ./targets.zip -m@
- find and execute on all results:
find . -name "<pattern>" -exec cmd {} +
git
-
Show file content (any branch):
git cat-file main:<filename>
Ref. git cat-file -
Rename current branch:
git branch -m <newname>
-
Show local branch name:
git rev-parse --abbrev-ref HEAD
-
Update and merge main into current branch:
git fetch origin main:main
git merge origin/main
-
Push all branches:
git push -u origin --all
-
Swap remote:
git remote set-url origin <new_origin_url>
-
Check which branches have been merged :
git branch --merged
-
Compare 2 branches:
git diff branch1..branch2
-
Show commits in the current branch only
git log <branchoff_name>^..HEAD
(where branchoff_name is the name of the branch the current one has been branched off from) -
Remove last (local-only) commit:
git reset --soft HEAD~
-
Remove more than one (N) commit:
git reset --soft HEAD~N
-
Change case of a file when working on macOS:
git mv UPPERCASE uppercase
-
Fix broken commits and push: On undoing, fixing, or removing commits in git
-
Cleaning up repos
-
Analyze (git-sizer or git-filter-repo)
brew install git-sizer
git-sizer
or
pip install git-filter-repo
git-filter-repo --analyze
open .git/filter-repo/analysis
-
Remove files from history Ref. git-filter-repo
git-filter-repo --invert-paths --path '<filename>'
or use a text file with the list of paths to be deleted
git-filter-repo --invert-paths --paths-from-file <tobedeleted_file_list>
-
-
Find a file in any branch
git log --all -<filepath>
or
git log --all -'**/<filename>'
-
Find branch where a file is
-
git log --all -somefile
returns commit_nr
git branch -a --contains <commit_nr>
returns otherbranch
-
-
Show the commit tree in the cli:
git log --pretty=oneline --graph --decorate --all
-
Remove untracked files
git clean -n
(dry run)git clean -f
-
Automate access token
-
For multiple repos
B64_PAT=$(printf ":%s" "$SYSTEM_ACCESSTOKEN" | base64) git config --global http.https://dev.azure.com/.extraheader "Authorization: Basic $B64_PAT" git config --global --unset http.https://dev.azure.com/.extraheader
But the above leaves the token in the git config file. So remember to remove it with:
git config --global --unset http.https://dev.azure.com/.extraheader
-
For only one repo
git -c http.extraheader="Authorization: Basic $B64_PAT" clone ...
Note: Bearer often does not work.
-
-
Squash commits on merge
git merge --squash # automatic, might fail
git rebase -i # interactive
-
Work with multiple branch at the same time
git worktree add <path> <branch_name> git worktree list git worktree remove <worktree-name>
-
Rename local and remote branch
git checkout <old_name> git branch -m <new_name> git push origin -u <new_name> git push origin --delete <old_name>
-
Rewrite commit author and committer
git filter-branch --commit-filter ' if [ "$GIT_COMMITTER_EMAIL" = "WRONG_COMMITTER_EMAIL" ]; then GIT_AUTHOR_NAME="RIGHT_COMMITTER"; GIT_AUTHOR_EMAIL="RIGHT_COMMITTER_EMAIL"; GIT_COMMITTER_NAME="RIGHT_COMMITTER"; GIT_COMMITTER_EMAIL="RIGHT_COMMITTER_EMAIL"; git commit-tree "$@"; else git commit-tree "$@"; fi' HEAD git push -f --all
Submodules
- Add
git submodule add http://submodule submodule git add . git commit -m “added submodule” git push
- Clone
git clone --recursive --jobs 6 https://module cd module
- Pull
git pull --recurse-submodules
- Update submodule updated elsewehre
cd submodule git checkout master git pull # pull the latest commit from the submodule repo cd .. git add . git commit -m “updated submodule” git push
- Updated submodule with local changes
cd submodule touch changedfile.txt git add . git commit -m “changes to submodule” git push cd .. git add . git commit -m “updated submodule” git push
- Avoid pushing module before submodule.
If we make the following mistake:
We must correct it this way:cd submodule touch changedfile.txt git add . git commit -m “added changedfile.txt” # here we forget git push cd .. git add . git commit -m “updated submodule” git push
git clone --recursive --jobs 6 https://module # the above will return some errors trying to clone submodule cd module/submodule git checkout master git pull cd .. git add . git commit -m “fixed submodule” git push
- Remove a submodule
git rm submodule git add . git commit -m “removed submodule” git push
References
-
getting a page in Gogle search:
Gradle
-
Create a gradle task that runs a script (example)
task myTask(dependsOn: ['assembleDebug', 'assembleRelease']) {
group 'My group'
description 'My description'
doLast {
exec {
executable "sh"
args "-c", "runscript.sh"
}
}
}
In Kotlin
tasks.register("myTask") {
doLast {
val result = exec {
commandLine("echo", "hi")
}
println(result.exitValue)
}
}
- Remove old-ish cache
find ~/.gradle -type f -atime +30 -delete
find ~/.gradle -type d -mindepth 1 -empty -delete
Homebrew
-
-
list all installed packages
brew list
-
list isntalled cask packages
brew installed --cask
-
General package info
brew info X
-
What are X dependencies
brew deps X
-
What depends on X
brew uses X --installed
-
Do not use brew leaves to find what can be uninstalled (see link above)
-
Save current brew installed list (to Brewfile)
brew bundle dump
To restore
brew bundle install
-
Hurl
Making REST calls sequences easy for the terminal chaps
iOS
-
Start simulator
open -a Simulator.app
-
Simulate location in Simulator
xcrun simctl location {booted_device.udid} start --speed 10 {lat},{lng} {lat},{lng} {lat},{lng} ...
Note that{booted_device.udid}
can be replaced bybooted
-
List simulators
xcrun simclt list
-
Select Xcode
sudo xcode-select -s /Applications/<Xcode version>
-
Run stuff as if on x86
arch -x86_64 <cmd>
-
Run stuff forcing arm (when within a x86 app)
arch -arm64 <cmd>
-
Generic xcodebuild command
env NSUnbufferedIO=YES xcodebuild -workspace <workspace filename> -scheme <scheme name> -derivedDataPath ./DerivedData -destination 'platform=iOS Simulator,name=iPhone SE (3rd generation),arch=x86_64' -resultBundlePath './output/result.xcresult' OTHER_SWIFT_FLAGS=<other flags> build test
Note the arch parameter in the destination if you want to force running with Rosetta2
Managing iOS Simulators
(from here)
List all simulators created
$ xcrun simctl list --json
Delete old and unavailable simulators
$ xcrun simctl delete unavailable
Open Simulator.app
$ open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/
Boot specific simulators
You can find the id/name by listing all simulators $ xcrun simctl list
.
$ xcrun simctl boot AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEE // UUID Hex string
$ xcrun simctl boot "iPhone XS Max" // Name of simulator
Create a simulator with a specific name
You can name simulators and use them for specific purposes.
$ xcrun simctl create iPhone7-my-app com.apple.CoreSimulator.SimDeviceType.iPhone-8 com.apple.CoreSimulator.SimRuntime.iOS-10–3
Shutdown Simulator
$ xcrun simctl shutdown booted
$ xcrun simctl shutdown AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEE
$ xcrun simctl shutdown "iPhone7-my-app"
$ xcrun simctl shutdown "iPhone XS"
$ xcrun simctl shutdown all
Erase contents in Simulator
Similar to running a factory restore on your device
$ xcrun simctl erase AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEE
$ xcrun simctl erase "iPhone7-my-app"
$ xcrun simctl erase "iPhone XS"
$ xcrun simctl erase all
Add media to simulator
$ xcrun simctl addmedia booted ./video_01.mp4
$ xcrun simctl addmedia "iPhone XS" ./video_01.mp4
Working with apps
Install App
$ xcrun simctl install booted "./path/to/ios-app.app"
$ xcrun simctl install "iPhone XS Max" "./path/to/ios-app.app"
Uninstall App
$ xcrun simctl uninstall booted com.mycompany.myapp
$ xcrun simctl uninstall "iPhone XS Max" com.mycompany.myapp
Launch app
$ xcrun simctl launch booted com.mycompany.myapp
$ xcrun simctl launch "iPhone XS Max" com.mycompany.myapp
Terminate app
$ xcrun simctl terminate booted com.mycompany.myapp
$ xcrun simctl terminate "iPhone XS Max" com.mycompany.myapp
Open URL
Can also be used to open an app, if you open the app using a url the first time it will give you an alert asking if you want to navigate to that app.
$ xcrun simctl openurl booted https://google.com
$ xcrun simctl openurl "iPhone XS Max" https://google.com
$ xcrun simctl openurl booted myapp://
$ xcrun simctl openurl "iPhone XS Max" myapp://
Record simulator video
$ xcrun simctl io booted recordVideo — type=mp4 ./simulator-record_001.mp4
$ xcrun simctl io "iPhone XS Max" recordVideo — type=mp4 ./simulator-record_001.mp4
Screenshot simulator
$ xcrun simctl io booted screenshot ./simulator-screenshot_001.png
$ xcrun simctl io "iPhone XS Max" screenshot ./simulator-screenshot_001.png
More help provided using help command
$ xcrun simctl help
Example scripts
Run an app on many simulators
I created and use this script for running the app I am developing in all possible screen sizes at once to verify that everything looks and works as intended.
#!/bin/bash
# List of simulators: `$ xcrun simctl list`
SIMULATORS=("iPhone SE" "iPhone 8" "iPhone 8 Plus" "iPhone XS" "iPhone XS Max" "iPhone XR")
# Comment or remove variables to skip a step
APP_PATH="/path/to/my/build/directory/when/running/a/build/in/xcode/app.app"
APP_IDENTIFIER="com.mycompany.myapp" # Identifier from info.plist
OPEN_URL="myapp://some/page/in/app" # Deep linking
echo "Running on ${#SIMULATORS[*]} simulators."
for index in ${!SIMULATORS[*]}
do
SIMULATOR=${SIMULATORS[$index]}
echo "Booting ${SIMULATOR}..."
xcrun simctl boot "${SIMULATOR}"
if [ ! -z "$APP_PATH" ]
then
echo "${SIMULATOR} installing: ${APP_PATH##*/}"
xcrun simctl install "${SIMULATOR}" "${APP_PATH}"
fi
if [ ! -z "$APP_IDENTIFIER" ]
then
echo "${SIMULATOR} opening app: ${APP_IDENTIFIER}"
xcrun simctl launch "${SIMULATOR}" "${APP_IDENTIFIER}"
fi
if [ ! -z "$OPEN_URL" ]
then
echo "${SIMULATOR} opening url: ${OPEN_URL}"
xcrun simctl openurl "${SIMULATOR}" "${OPEN_URL}"
fi
done
References:
- https://medium.com/@ankitkumargupta/ios-simulator-command-line-tricks-ee58054d30f4
- https://medium.com/xcblog/simctl-control-ios-simulators-from-command-line-78b9006a20dc
- https://nshipster.com/simctl/
- https://www.linuxjournal.com/content/bash-arrays
Java
Android keystore
The keystore format has changed around Java 8.0.3xx (check value of JAVA_HOME)
Using an older version of Java one gets an error
[old_java]/bin/keytool -list -v -keystore "$HOME/.android/debug.keystore"
-alias androiddebugkey -storepass android -keypass android
Using an newer version of Java everything works
[new_java]/bin/keytool -list -v -keystore "$HOME/.android/debug.keystore"
-alias androiddebugkey -storepass android -keypass android
-
Support multiple java environments (same line as PyEnv and RbEnv): jenv
-
java_home: remember the command
/usr/libexec/java_home
-
Add a certificate:
$JAVA_HOME/bin/keytool -importcert -file "<filepath.cer>" -cacerts -alias "<alias>" -storepass changeit
-
Delete a certificate:
keytool -delete -alias <alias> -keystore -storepass changeit
-
List certificates:
keytool -list -v -cacerts -storepass changeit
-
Show java properties:
java -XshowSettings:properties -version
-
Show java settings
java -XshowSettings:all -version
-
Automate the creation of native macOS java apps with installers: MacJava which is a guide for jpackage
JavaScript
nvm ls
nvm ls-remote
nvm install 18.18.2
nvm use 18.18.2
npm config set cafile "$HOME/certs/TIAROOTCA2022.pem"
npm init -y
npm install eslint --save-dev
npx eslint --init
npm install lite-server --save-dev
npm run dev
adb reverse tcp:3000 tcp:3000
Run processes
Use Execa
Summary
brew install nvm
nvm ls
nvm install node
ornvm install vx.y.z
nvm use x.y.z
jq
Kotlin
- Build cli apps in Kotlin: clikt
Launchctl
Set environment variables in macOS for GUI apps
In general environment variables for GUI apps in macOS are stored in /etc/launchd.conf
.
Otherwise one can:
launchctl setenv <KEY> "<VALUE>"
Maven
- How to manually download a dependency (e.g. robolectric)
mvn -DgroupId=org.robolectric -DartifactId=android-all-instrumented -Dversion=11-robolectric-6757853-i4 dependency:get
1.1 Better yet
mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:get -Dartifact=groupId:artifactId:version:packaging -Dtransitive=false
Using a .m2/settings.xml like
<settings>
<servers>
<server>
<id>central</id>
</server>
<server>
<id>google</id>
</server>
<server>
<id>jcenter</id>
</server>
<server>
<id>github</id>
<username>[username]</username>
<password>[github token]</password>
</server>
</servers>
<profiles>
<profile>
<id>myprofile</id>
<repositories>
<repository>
<id>central</id>
<url>https://repo1.maven.org/maven2/</url>
</repository>
<repository>
<id>jcenter</id>
<url>https://jcenter.bintray.com/</url>
</repository>
<repository>
<id>google</id>
<url>https://maven.google.com/</url>
</repository>
<repository>
<id>github</id>
<name>Github</name>
<url>https://maven.pkg.github.com/...</url>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>myprofile</activeProfile>
</activeProfiles>
</settings>
- How to upload a jar dependency to a local folder for testing
mvn deploy:deploy-file -Dfile=./test.jar -Durl=file:///Users/marionegroponzi/Developer/Workspace/tbd/deploy -DgroupId=com.org -DartifactId=test -Dversion=1.0 -DgeneratePom=true
mdbook
The tool used to build this site.
Mojo
Ref
https://docs.modular.com/mojo/manual/
Quick start
python3 -m venv mojo-venv && source mojo-venv/bin/activate
modular install mojo
Multitime
-
Run the same command multiple time and measure
multitime -q -n 10 <cmd>
nslookup
OBS
How to setup a video background in a call
Work in progress, still not working with Teams, and often it crashes
- Install OBS
- Install OBS plugin to remove background
- Download a video desktop background
- Add media source with video in the background
- Add video capture and apply to it Filters > Video Filter "Background Removal"
Performance
-
Time
-
gtime (gtime -v also gives info about memory usage, etc.)
-
wrk: Load generator
Python
-
Virtualenv
python -m venv venv source venv/bin/activate pip install -r requirements.txt python main.py deactivate
-
Requirements
pip freeze -r > requirements.txt
or
pip install pipreqs pipreqs path/to/project
-
Install with custom certificate
pip --cert $HOME/certs/MYCERT.pem install ...
or find the certificate repos (e.g. in the current virtual environment)
fd -e pem . venv cat $HOME/certs/MYCERT.pem >> venv/lib/python3.9/site-packages/pip/_vendor/certifi/cacert.pem
ripgrep
- Fast search
- Find log4j:
sudo rg JndiLookup --binary -z / 2>/dev/null
- Find a string in files with extension:
rg '<string>' -g '*.<ext>'
Robolectric
- Robolectric downloads dynamically dependencies. It does not respect the repositories settings. To amke sure it uses a source that is not MavenCentral one must add the following in the root build.gradle.kts file.
allprojects {
tasks.withType<Test> {
systemProperty("robolectric.dependency.repo.id", "nexus")
systemProperty("robolectric.dependency.repo.url", "https://<nexus_internal_url>:8443/repository/android-group/")
systemProperty("javax.net.ssl.trustStoreType", "JKS") // required for Robolectric 4.3.1 and JDK11
systemProperty("robolectric.logging", "stdout")
}
}
Ruby
Rust
Minimal Web Servers
Various solution for similar problems
-
python -m http.server 8080
-
while true; do nc -l 127.0.0.1 8889 < foo.html; done
-
nc -l 127.0.0.1 8889 < foo.html
-
while true ; do nc -l -p 1500 -c 'echo -e "HTTP/1.1 200 OK\n\n $(date)"'; done
-
while true ; do nc -l -p 1500 -e /path/to/yourprogram ; done
restart
-
restart from terminal
sudo shutdown -r now
ssh
-
Create ssh keypair
ssh-keygen -t rsa
-
Example config file
Putting the file below (named
config
) within the .ssh folder one can connect usingssh server1
host * AddKeysToAgent yes ServerAliveInterval 100 ServerAliveCountMax 2 ForwardAgent yes IdentityFile $HOME/.ssh/myuser/id_rsa user myuser StrictHostKeyChecking no ConnectTimeout 3 host server1 # here it uses the user myuser hostname xxx.xxx.xxx.xxx host server2 IdentityFile $HOME/.ssh/anotheruser/id_rsa user anotheruser hostname yyy.yyy.yyy.yyy
scp
-
copy files among remote machines (directly)
scp [OPTION] [user@]SRC_HOST:]file1 [user@]DEST_HOST:]file2
-
same as above but passing through the local machine
scp [OPTION] -3 [user@]SRC_HOST:]file1 [user@]DEST_HOST:]file2
Swift
-
Mint: A package manager that installs and runs Swift command line tool packages (why should I use it?)
-
Ice: A developer friendly package manager for Swift; 100% compatible with Swift Package Manager (why should I use it?)
-
5.1 Create new executable app
swift package init --type executable
5.2 Build
swift build
5.3 Run
swift run
5.4 Test
swift test
thermal throttling
-
Check if the cpu thermal throttle (does not work on M1)
pmset -g thermlog
-
On Apple Silicon
sudo powermetrics -s thermal
TODO
nginx
better ansible with files
git annex and git lfs
remove git history
Various from everywhere
Convert svg to png via cli
brew install librsvg
rsvg-convert test.svg -o test.png
Visual Studio Code
macOS <=> Windows Command <=> Ctrl option <=> Alt
macOS Commands
-
Select all occurrences of selected word: Command + F2
-
Select all occurrences of selected word one-by-one: Command + D
-
Auto Indent Code: Shift + Option + F
VNC
- VNC over ssh (from here)
Open VNC tossh -L 5900:localhost:5900 REMOTE_IP
localhost:5900
xcinfo
Intall multiple version of Xcode from the cli
-
Available versions
xcinfo list
-
Install a specific version
xcinfo install 13.2.1
xcodes
Xcode
-
Xcode command line uploader (e.g. for Log4j) - possibly outdated
xcrun iTMSTransporter
-
xcodes to download multiple xcode versions
-
Install Xcode and runtimes
unxip --version || brew install unxip
unxip Xcode_15.1.xip
sudo mv -f ./Xcode.app /Applications/Xcode_15.1.app
sudo xcode-select -s /Applications/Xcode_15.1.app
sudo xcodebuild -license accept
sudo /Applications/${{ xcode.Value.targetFileName }}/Contents/Developer/usr/bin/xcodebuild -runFirstLaunch
xcodebuild -downloadPlatform iOS
- Kill all Simulator instances:
killall Simulator
Zip
-
zip folder:
zip <name>.zip <folder>/**/*
-
unzip:
unzip <name>.zip
Zola
A static website generator in Rust. More flexible than mdbook.
zsh
-
cp -a
preserves flags and dates (and implies -r) -
clear history
exec rm "$HISTFILE"
-
execute a command every time one cd-ing into a foler:
function cd {
# actually change the directory with all args passed to the function
builtin cd "$@"
# if there's a regular file named "todo.txt"...
if [ -f "todo.txt" ] ; then
# display its contents
cat todo.txt
fi
}
-
time how long it takes to load zsh:
/usr/bin/time zsh -i -c exit
-
optimize nvm loading time:
export NVM_DIR="$HOME/.nvm" # [ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh" # This loads nvm (commented out) [ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion alias nvm="unalias nvm; [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"; nvm $@" # added
-
~/.zshrc
export HISTFILE=~/.zsh_history
export HISTFILESIZE=1000000000
export HISTSIZE=1000000000
setopt INC_APPEND_HISTORY
export HISTTIMEFORMAT="[%F %T] "
setopt EXTENDED_HISTORY
setopt HIST_IGNORE_ALL_DUPS
# Lang
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
# Example aliases
alias zshconf="code ~/.zshrc"
# comment for performance
# test -e "${HOME}/.iterm2_shell_integration.zsh" && source "${HOME}/.iterm2_shell_integration.zsh"
# Editor
export EDITOR=nano
export VISUAL=nano
# Homebrew
export PATH=/opt/homebrew/bin:/usr/local/sbin:/usr/local/bin:$PATH
# OpenSSL - prioritise to Homebrew openssl so PyEnv and RbEnv use it for Python installations
export PATH="/usr/local/opt/openssl@3/bin:$PATH"
export RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@3)"
# for compilers
# export LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib"
# export CFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib"
# export CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include"
# Java
export JAVA_STUDIO_HOME="/Applications/Android Studio.app/Contents/jbr/Contents/Home"
export JAVA_IDEA_HOME="/Applications/IntelliJ IDEA CE.app/Contents/jbr/Contents/Home"
export JAVA_GRAALVM_HOME="/Library/Java/JavaVirtualMachines/graalvm-community-openjdk-17.0.9+9.1/Contents/Home"
alias jstudio='export JAVA_HOME="$JAVA_STUDIO_HOME" && export PATH="$JAVA_HOME/bin:$PATH"'
alias jidea='export JAVA_HOME="$JAVA_IDEA_HOME" && export PATH="$JAVA_HOME/bin:$PATH"'
alias j11='export JAVA_HOME="`/usr/libexec/java_home -v 11`";export PATH="$JAVA_HOME/bin:$PATH"'
alias jgraal='export JAVA_HOME="$JAVA_GRAALVM_HOME" && export PATH="$JAVA_HOME/bin:$PATH"'
# Default to IntelliJ JBR
jidea
# Android
export ANDROID_HOME=$HOME/Library/Android/sdk
export ANDROID_SDK=$ANDROID_HOME
export ANDROID_SDK_ROOT=$ANDROID_HOME
export PATH="$ANDROID_HOME/platform-tools:$ANDROID_HOME/cmdline-tools/latest/bin:$PATH"
# RbEnv
export PATH="$HOME/.rbenv/bin:$PATH:"
eval "$(rbenv init -)"
# PyEnv
export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
# jenv
# export PATH="$HOME/.jenv/bin:$PATH"
# eval "$(jenv init -)"
# Flutter
export PATH="$HOME/Developer/flutter/bin:$PATH"
# Dart
export PATH="$PATH":"$HOME/.pub-cache/bin"
# alias px-off="unset http_proxy https_proxy ALL_PROXY JAVA_OPTS JAVA_TOOL_OPTIONS"
# alias px-on="source ~/.zshrc"
# mongodb
export PATH="/usr/local/opt/mongodb-community@4.4/bin:$PATH"
# cli apps
export PATH="$HOME/cliapps:$PATH"
# aliases
alias g='git'
alias hh='history -E -1000'
alias ls='exa -lag --header'
alias up='brew update && brew upgrade && flutter upgrade'
alias gt='gtime -f "time result\ncmd:%C\nreal %es\nuser %Us \nsys %Ss \nmemory:%MKB \ncpu %P"'
alias fd='fd -HI'
alias push='git push'
alias pull='git pull'
alias merge='git merge'
alias commit='git commit'
alias switch='git switch'
alias branch='git branch'
alias checkout='git checkout'
alias status='git status'
alias clone='git clone'
alias glog='git log --graph --decorate --oneline'
alias worktree='git worktree'
alias gtree='git worktree'
alias gdiff='git diff'
alias greset='git reset'
alias certs='$HOME/certs/certs.sh'
export PATH="/Applications/sonar-scanner-5.0.1.3006-macosx/bin/:$PATH"
# Node
export NVM_DIR="$HOME/.nvm"
# [ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh" # This loads nvm
[ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion
alias nvm="unalias nvm; [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"; nvm $@"
# export PATH="/opt/homebrew/opt/node@18/bin:$PATH"
eval "$(starship init zsh)"
function cd {
# actually change the directory with all args passed to the function
builtin cd "$@"
# if there's a regular file named "readme.md"...
if [ -f "readme.md" ] ; then
# display its content
cat readme.md
fi
}
Contributors
Mario Negro Ponzi
Site hosted in GitHub Pages.
Site built with mdbook