Skip to content

Instantly share code, notes, and snippets.

@uraimo
uraimo / swift_compiler_generate_swift.xcodeproj.md
Created April 29, 2020 08:50
How to generate Swift.xcodeproj for the apple/swift compiler without building everything

Clone the Swift compiler and all the related subprojects and then just create the build directories without compiling:

mkdir swiftlang
cd swiftlang
git clone https://github.com/apple/swift.git
./swift/utils/update-checkout --clone
cd swift
utils/build-script --release-debuginfo --xcode --skip-build
@uraimo
uraimo / new_homebrew_formula.md
Last active November 9, 2022 17:12
Create a new homebrew formula and submit it/private tap

Creating a new Homebrew formula

Simplified procedure extracted from the contribution guidelines and the guide.

Example for a new go application, the install step and the dependencies will be different if you are building something else.

  1. Update brew:

    brew update

@uraimo
uraimo / swift_globals_checks.md
Created July 2, 2019 08:50
Check if a function is defined in the global namespace in Swift
guard dlsym(nil,"iDontExistOnThisPlatformSorry") != nil else {print("Doesn't exist!");exit(0)}
  • Link gcc and g++ to clang and clang++ respectively if necessary

  • Move /bin/uname to /bin/uname.orig and override it with a /bin/uname script that calls /bin/uname.orig "$@" | sed 's/armv7l/armv6l/g'

  • Force armv6l for build-impl-script instead of using python's platform.machine() that calls the uname syscall (setarch cannot be used since armv6 cannot be set...):

    diff --git a/utils/swift_build_support/swift_build_support/targets.py b/utils/swift_build_support/swift_build_support/targets.
    py
    index 2859677fac..b7d65c4f9a 100644
    

--- a/utils/swift_build_support/swift_build_support/targets.py

How to squash an image with multiple layers in a single new one (losing history).

Enable experimental features in Docker

Using --squash requires a Docker with and API version greater than 1.13 (can be checked with docker version).

Edit /etc/docker/daemon.json adding:

  {

"experimental": true

Just some useful one liners.

  • A better way to get the ARCH for a binary:

readelf -a -W | grep CPU

@uraimo
uraimo / fuse-ext2-macos.md
Created May 17, 2019 13:35
Install fuse-ext2 with minimal effort on macOS

Install the dependencies:

brew install m4 autoconf automake libtool e2fsprogs

Clone and build:

git clone https://github.com/alperakcan/fuse-ext2.git	
cd fuse-ext2
@uraimo
uraimo / multiple_github_accounts_guide.md
Last active April 12, 2020 13:26
Configuring multiple github accounts for work and private

In this short guide two sample user will be used: leisure and work.

  1. Create two ssh keys, one of each user, and register them with their github account on the site. Let's suppose you have created id_rsa_work and id_rsa_leisure.

  2. Configure ssh using two virtual hosts, one for work and one for leisure, each one linked to one of the keys:

     # Personal GitHub account
     Host leisure-github.com
    

HostName github.com

@uraimo
uraimo / snmp_guide.md
Last active June 3, 2022 09:16
The bare minimum you need to query an SNMP service

To traverse the tree of public data (i.e. "public" community), starting from the "iso" root:

  snmpwalk -v 2c -Cc -c public -m ALL 10.0.0.1 iso

To print out private data ("private" community, enterprises leaf(1.3.6.1.4)):

snmpwalk -v 2c -c private -l authPriv -u "user" -a MD5 -A "pass" -x DES -X "pass" -m ALL 10.0.0.1 1.3.6.1.4

@uraimo
uraimo / python_3.6_tensorflow_homebrew.md
Last active February 5, 2019 16:15
Installing Python 3.6.5 on macOS Mojave for Tensorflow

Since Tensorflow is not yet available via pip for Python 3.7 and pyenv can't build python on the latest macOS, let's install 3.6.5_1 via homebrew and use it in conjunction with pyenv to create an enclosed environment that will use 3.6 only when we need it:

brew unlink python
brew install --ignore-dependencies https://raw.githubusercontent.com/Homebrew/homebrew-core/f2a764ef944b1080be64bd88dca9a1d80130c558/Formula/python.rb
brew switch python 3.7.2_1

Install pyenv if you haven't already, we'll use it to switch to 3.6.5 only when we need it (e.g. jupyter), leaving the latest Python from homebrew as default release (e.g. 3.7.2_1):

brew install pyenv

pyenv rehash