Skip to content

Instantly share code, notes, and snippets.

@qzchenwl
qzchenwl / homebrew-gnubin.md
Created November 3, 2023 06:05 — forked from skyzyx/homebrew-gnubin.md
Using GNU command line tools in macOS instead of FreeBSD tools

macOS is a Unix, and not built on Linux.

I think most of us realize that macOS isn't a Linux OS, but what that also means is that instead of shipping with the GNU flavor of command line tools, it ships with the FreeBSD flavor. As such, writing shell scripts which can work across both platforms can sometimes be challenging.

Homebrew

Homebrew can be used to install the GNU versions of tools onto your Mac, but they are all prefixed with "g" by default.

All commands have been installed with the prefix "g". If you need to use these commands with their normal names, you can add a "gnubin" directory to your PATH from your bashrc.

# see https://www.topbug.net/blog/2013/04/14/install-and-use-gnu-command-line-tools-in-mac-os-x/
# core
brew install coreutils
# key commands
brew install binutils
brew install diffutils
brew install ed --default-names
brew install findutils --with-default-names
@qzchenwl
qzchenwl / 0_reuse_code.js
Last active August 29, 2015 14:06
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@qzchenwl
qzchenwl / lazy_vs_st.hs
Created March 27, 2012 03:43 — forked from yihuang/lazy_vs_st.hs
lazy vs ST
{-# LANGUAGE BangPatterns #-}
module Main (fib1, fib2, fib3, fib4, main) where
import Control.Monad
import Control.Monad.ST
import Data.STRef
import Data.List (transpose)
import Criterion.Main
fib1 :: Int -> Integer
fib1 n = fst $ fib' n
@qzchenwl
qzchenwl / lazy_vs_st.hs
Created March 26, 2012 17:17 — forked from yihuang/lazy_vs_st.hs
lazy vs ST
{-# LANGUAGE BangPatterns, ViewPatterns #-}
import System.Environment (getArgs)
import Control.Monad
import Control.Monad.ST
import Data.STRef
import GHC.Int
fib1 :: Int -> Integer
fib1 n = fibs !! n
where fibs = 1 : 1 : zipWith (+) fibs (tail fibs)