Posts

Showing posts with the label macOS

Remove Active Content (Links) from a LaTeX PDF Using Ghostscript

Image
Terminal — flatten a LaTeX PDF $ gs -dNOPAUSE -sDEVICE=pdfwrite \\ -sOUTPUTFILE=NEW_FILE.pdf -dBATCH in.pdf Processing pages 1 through 3. Page 1 ... Page 2 ... Page 3 NEW_FILE.pdf active links removed A PDF produced from LaTeX often carries "active" content: clickable hyperlinks, internal cross-reference links, bookmarks, and sometimes form fields or embedded JavaScript. When you need a flat, static PDF for printing, archiving, or submitting to a system that rejects interactive elements, the simplest reliable tool is Ghostscript. This tutorial shows how to strip that active content by re-distilling the file through Ghostscript's pdfwrite device. Step 1: Install Ghostscript On macOS, install it with Homebrew: brew install ghostscript On Debian or Ubuntu use sudo apt install ghostscript ; on most Linux distributions Ghostscript is packaged as ghostscript and provides the gs command. Step 2: Re-distill the PDF Run the source PDF back through Ghostscript...

[How To] Retrieve API keys in OpenClaw

Image
Agent and CLI tools often save the API credentials you sign in with to a hidden folder in your home directory. If you have been using the openclaw tool and need to find the Anthropic API key or Bearer token it stored, for example to reuse it elsewhere or to rotate it, you can locate it in a few seconds with grep . This short tutorial shows how. Note: "spi keys" in the URL is a typo for "api keys". Step 1: Go to the config directory openclaw keeps its per-agent configuration under a hidden .openclaw folder in your home directory: cd ~/.openclaw/ Step 2: List what is there List the contents, including hidden files, so you can see the agent folders: ls -loa Each agent typically has its own subfolder under agents/ , and the credentials live in an auth-profiles.json file inside it. Step 3: Search for the keys Rather than opening each file by hand, recursively grep the whole directory for the two token formats. Anthropic keys begin with sk-ant- , and OAuth-st...

[Fix] imsg: Bad CPU type in executable

Image
Terminal — fixing Bad CPU type $ arch i386 $ imsg .../libexec/imsg: Bad CPU type in executable $ make build Built bin/imsg (arm64 x86_64) universal imsg is a handy command line tool that reads the macOS Messages database so you can query your iMessages from the terminal. After installing it with Homebrew, you may hit this error the moment you run it: /usr/local/bin/imsg: line 2: /usr/local/Cellar/imsg/0.5.0/libexec/imsg: Bad CPU type in executable /usr/local/bin/imsg: line 2: /usr/local/Cellar/imsg/0.5.0/libexec/imsg: Undefined error: 0 This post explains what causes it and the fix that actually worked: building a universal binary from source. What "Bad CPU type in executable" means That error appears when the architecture of the binary does not match the architecture your shell is running under. On an Intel Mac, or on an Apple Silicon Mac running a terminal under Rosetta, the process expects an x86_64 binary, but the installed imsg binary was built only for arm64 (...

[How To] Install SEAL-Python In macOS

Image
Run the following commands from the Terminal in the given order: 1. brew install cmake autoconf automake libtool shtool gflags 2. xcode-select --install 3. git clone https://github.com/Huelse/SEAL-Python.git 4. cd SEAL-Python 5. pip3 install numpy pybind11 6. git submodule update --init --recursive 7. cd SEAL 8. cmake -S . -B build -DSEAL_USE_MSGSL=OFF -DSEAL_USE_ZLIB=OFF -DSEAL_THROW_ON_TRANSPARENT_CIPHERTEXT=OFF -DCMAKE_C_COMPILER=/usr/local/Cellar/llvm/16.0.1/bin/clang -DCMAKE_CXX_COMPILER=/usr/local/Cellar/llvm/16.0.1/bin/clang++ 9. cmake --build build 10. cd .. 11. python3 setup.py build_ext -i 12. cp seal.*.so examples 13. cd examples 14. python3 4_bgv_basics.py This guide installs SEAL-Python on macOS, the Python binding for Microsoft SEAL, by installing the build tools, cloning the project with its submodules, and building the wrapper. Microsoft SEAL is a homomorphic encryption library. Homomorphic encryption lets you compute on encrypted data without decrypting it. The buil...

[Solved] Fix "ld: library not found for -lc++" errors in macOS

Image
Linker Error: Run Build Command(s):/usr/local/Cellar/cmake/3.26.3/bin/cmake -E env VERBOSE=1 /usr/local/bin/gmake -f Makefile cmTC_2eb92/fast && /usr/local/bin/gmake   -f CMakeFiles/cmTC_2eb92.dir/build.make CMakeFiles/cmTC_2eb92.dir/build     gmake[1]: Entering directory '/Users/devharsh/Downloads/SEAL-Python/SEAL/build/CMakeFiles/CMakeScratch/TryCompile-p29bdr'     Building CXX object CMakeFiles/cmTC_2eb92.dir/testCXXCompiler.cxx.o     /Library/Developer/CommandLineTools/usr/bin/c++     -MD -MT CMakeFiles/cmTC_2eb92.dir/testCXXCompiler.cxx.o -MF CMakeFiles/cmTC_2eb92.dir/testCXXCompiler.cxx.o.d -o CMakeFiles/cmTC_2eb92.dir/testCXXCompiler.cxx.o -c /Users/devharsh/Downloads/SEAL-Python/SEAL/build/CMakeFiles/CMakeScratch/TryCompile-p29bdr/testCXXCompiler.cxx     Linking CXX executable cmTC_2eb92     /usr/local/Cellar/cmake/3.26.3/bin/cmake -E cmake_link_script CMakeFiles/cmTC_2eb92.dir/link.txt --verbose=1   ...

[Fix] Free up disk space in macOS

Image
This hack worked for me when I was running low on disk space on my MacBook Pro, stopping me from upgrading to the latest version of Xcode and macOS. Run these quick and easy commands from the macOS terminal to clean system data over 100 GB . rm -rf Library/Logs rm -rf Library/Caches rm -rf System/Library/Caches rm -rf ~/Library/Logs rm -rf ~/Library/Caches

List Supported CPU Instructions Set [Solved]

Image
You may find these terminal commands useful if you are looking for ways to list all supported instructions set by the CPU on a macOS machine. For instance, you can check for Intel® Streaming SIMD Extensions 4 ( Intel® SSE4) or Intel® Software Guard Extensions (Intel® SGX) features for your device. % sysctl -n "machdep.cpu.brand_string" Intel(R) Core(TM) i5-8279U CPU @ 2.40GHz % sysctl -a | grep machdep.cpu.features machdep.cpu.features: FPU VME DE PSE TSC MSR PAE MCE CX8 APIC SEP MTRR PGE MCA CMOV PAT PSE36 CLFSH DS ACPI MMX FXSR SSE SSE2 SS HTT TM PBE SSE3 PCLMULQDQ DTES64 MON DSCPL VMX EST TM2 SSSE3 FMA CX16 TPR PDCM SSE4.1 SSE4.2 x2APIC MOVBE POPCNT AES PCID XSAVE OSXSAVE SEGLIM64 TSCTMR AVX1.0 RDRAND F16C % sysctl -a | grep machdep.cpu.leaf7_features machdep.cpu.leaf7_features: RDWRFSGS TSC_THREAD_OFFSET SGX BMI1 AVX2 SMEP BMI2 ERMS INVPCID FPU_CSDS MPX RDSEED ADX SMAP CLFSOPT IPT MDCLEAR TSXFA IBRS STIBP L1DF ACAPMSR SSBD % sysctl -a | grep AVX2 machdep.cpu.leaf7_feature...

[How To] Install HElib on macOS

Image
HElib is an open-source (Apache License v2.0) software library that implements homomorphic encryption (HE). Currently, available schemes are the implementations of the Brakerski-Gentry-Vaikuntanathan (BGV) scheme and the Approximate Number scheme of Cheon-Kim-Kim-Song (CKKS), along with many optimizations to make homomorphic evaluation runs faster, focusing mostly on effective use of the Smart-Vercauteren ciphertext packing techniques and the Gentry-Halevi-Smart optimizations. To install HElib on macOS , follow these steps: brew update && brew upgrade && brew autoremove && brew cleanup cd Downloads/ git clone https://github.com/homenc/HElib.git Cloning into 'HElib'... remote: Enumerating objects: 14133, done. remote: Counting objects: 100% (292/292), done. remote: Compressing objects: 100% (211/211), done. remote: Total 14133 (delta 127), reused 172 (delta 54), pack-reused 13841 Receiving objects: 100% (14133/14133), 13.04 MiB | 5.81 MiB/s, done....

[Solved] Error: No such keg: /usr/local/Cellar/gcc

Image
If you are facing issues with Homebrew while installing or updating the GCC package (or any other module), follow this guide. The error occurred for me recently during my periodic homebrew updates on my MacBook Pro. devharsh@Devharshs-MacBook-Pro ~ % brew update && brew upgrade && brew cleanup                                                           Already up-to-date. Warning:  Skipping gcc: most recent version 12.1.0 not installed For some reason, I had a warning flashing up for GCC. So I tried to install the missing version. devharsh@Devharshs-MacBook-Pro ~ % brew install -f gcc@12 Error:  gcc 12.1.0_1 is already installed To install 12.1.0, first run:    brew unlink gcc Which unsurprisingly did not work, so I tried unlinking it.  devharsh@Devharshs-MacBook-Pro ~ % brew unlink gcc Error:  No su...

[How To] Install Pyfhel in macOS

Image
  Tested on Intel-based (x86_64) MacBook, not tested on M1/M2 (ARM) Apple Clang does not support  -fopenmp  and  -libseal , use GCC or CLANG % git clone --recursive https://github.com/ibarrond/Pyfhel 2.a) create  requirements.txt  file "setuptools<=60.9", "wheel", "cython>=3.0.0a9", "numpy>=1.20", "cmake>=3.15", "toml>=0.10" 2.b)  % pip3 install -r requirements.txt edit  pyproject.toml Line #111 [ Afhel ] extra_compile_args {Darwin = ["-std=c++17","-O3","-fopenmp"]}, extra_link_args {Darwin = ["-fopenmp","-dynamiclib"]}, Repeat the above for [ CYTHON EXTENSIONS ]

[Solved] ld: library not found for -lntl

Image
NTL: A Library for doing Number Theory NTL is a high-performance, portable C++ library providing data structures and algorithms for manipulating signed, arbitrary length integers and for vectors, matrices, and polynomials over the integers and over finite fields. You might face a linking error with NTL in macOS using the Apple Clang compiler: % make                                 Consolidate compiler generated dependencies of target degrees [ 25%] Linking CXX executable degrees ld: library not found for -lntl clang: error: linker command failed with exit code 1 (use -v to see invocation) Solution: % brew install NTL % export LIBRARY_PATH=/usr/local/lib % make This linker error means the build was told to link NTL, the C++ number theory library, but cannot find it. NTL provides arbitrary length integers and operations on polynomials and matrices over rings and finite fields. Installing NTL and poin...

[How To] Run MinimaxComp_degrees in macOS

Image
MinimaxComp_degrees This algorithm finds optimized degrees for comparison/max/ReLU algorithms using minimax composite polynomial on the RNS-CKKS scheme, which was proposed in https://ieeexplore.ieee.org/document/9517029 and https://eprint.iacr.org/2021/1215 . How to run on macOS using the Apple Clang compiler: 1. % brew install NTL 2. % export LIBRARY_PATH=/usr/local/lib 3. % git clone  https://github.com/eslee3209/MinimaxComp_degrees 4. % cd MinimaxComp_degrees 5. % cmake -S . -B build 6. % cd build 7. % make 8. % ./degrees Output: ------------------------------------ alpha: 20 epsilon: 0.2002716064453125e-4 mintime: 162 depth: 22 0.39825903512705770933e-4 7 13 15 15 59   This guide runs MinimaxComp_degrees on macOS, an algorithm that finds optimized polynomial degrees for comparison, max, and ReLU operations under the RNS-CKKS homomorphic encryption scheme, based on the referenced research. CKKS can only evaluate polynomials on encrypted data, so non-polyn...

[How To] Install CRC RevEng on macOS

Image
CRC RevEng CRC RevEng is a portable, arbitrary-precision CRC calculator and algorithm finder. It calculates CRCs using any 111 preset algorithms or a user-specified algorithm to any width. It calculates reversed CRCs to give the bit pattern that produces a desired forward CRC. CRC RevEng also reverse-engineers any CRC algorithm from good, correctly formatted message-CRC pairs and optional known parameters. It comprises powerful input interpretation options. Installation instructions for macOS: 1. Download reveng from SourceForge:  https://sourceforge.net/projects/reveng/files/ 2. Unzip the downloaded reveng zip file 3. % cd Downloads/reveng-3.0.3 4. % make gcc -O3 -Wall -ansi -fomit-frame-pointer -DPRESETS -DBMPTST -o bmptst bmpbit.c ( ./bmptst && touch bmptst ) || ( rm bmptst bmptst.exe && false ) reveng: configuration fault.   Update config.h with these definitions and recompile: #define BMP_BIT   64 #define BMP_SUB   32 rm: bmptst.exe: No suc...

[How To] Run HELR (Homomorphic Encryption Logistic Regression) in macOS

Image
HELR is a software project for performing a logistic regression training on encrypted data (Secure Logistic Regression based on Homomorphic Encryption: Design and Evaluation ( https://medinform.jmir.org/2018/2/e19/ )). Step 1: brew install GMP Step 2: brew install NTL Step 3: git clone  https://github.com/K-miran/HELR.git Step 4: cd HELR

[How To] Print with staples in macOS

Image
Step 1/3: If you have opened a PDF from Google Chrome, go to the Print dialogue box and click on the link "Print using system dialog.." Step 2/3: Click on the dropdown menu that says "Media & Quality" and change it to "Finishing Options" Step 3/3: Click on Staple dropdown options and select the number of staples and the orientation where you want the pages to be stapled.

[Solved] Install matplotlib / basemap in macOS

Image
I have been trying to import the basemap module in my python script using " from mpl_toolkits.basemap import Basemap " but with no luck! I ran into issues while installing basemap with pip. Excerpt from the error:    Installing build dependencies ... error    error :  subprocess-exited-with-error       ×   pip subprocess to install build dependencies  did not run successfully.    │  exit code:  1    ╰─>   [552 lines of output]         Ignoring numpy: markers 'python_version >= "3.10"' don't match your environment         Ignoring numpy: markers 'python_version == "2.6" or (python_version >= "3.2" and python_version <= "3.3")' don't match your environment         Ignoring cython: markers 'python_version == "3.2"' don't match your environment ... ...             note: This error ...