Skip to content

Commit

Permalink
Cool stuff from mathiasbynens
Browse files Browse the repository at this point in the history
  • Loading branch information
dflems committed Dec 3, 2013
1 parent cae4763 commit 5b9591a
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 6 deletions.
2 changes: 0 additions & 2 deletions bin/lockme

This file was deleted.

14 changes: 14 additions & 0 deletions functions/calc
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,14 @@
local result=""
result="$(printf "scale=10;$*\n" | bc --mathlib | tr -d '\\\n')"
# └─ default (when `--mathlib` is used) is 20
#
if [[ "$result" == *.* ]]; then
# improve the output for decimal numbers
printf "$result" |
sed -e 's/^\./0./' `# add "0" for cases like ".5"` \
-e 's/^-\./-0./' `# add "0" for cases like "-.5"`\
-e 's/0*$//;s/\.$//' # remove trailing zeros
else
printf "$result"
fi
printf "\n"
1 change: 1 addition & 0 deletions functions/digga
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1 @@
dig +nocmd "$1" any +multiline +noall +answer
10 changes: 10 additions & 0 deletions functions/fs
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,10 @@
if du -b /dev/null > /dev/null 2>&1; then
local arg=-sbh
else
local arg=-sh
fi
if [[ -n "$@" ]]; then
du $arg -- "$@"
else
du $arg .[^.]* *
fi
1 change: 1 addition & 0 deletions functions/mkp
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1 @@
mkdir -p "$@" && cd "$@"
5 changes: 5 additions & 0 deletions functions/servit
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,5 @@
local port="${1:-8000}"
sleep 1 && open "http://localhost:${port}/" &
# Set the default Content-Type to `text/plain` instead of `application/octet-stream`
# And serve everything as UTF-8 (although not technically correct, this doesn’t break anything for binary files)
python -c $'import SimpleHTTPServer;\nmap = SimpleHTTPServer.SimpleHTTPRequestHandler.extensions_map;\nmap[""] = "text/plain";\nfor key, value in map.items():\n\tmap[key] = value + ";charset=UTF-8";\nSimpleHTTPServer.test();' "$port"
31 changes: 31 additions & 0 deletions homebrew/Brewfile
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,31 @@
# Make sure we’re using the latest Homebrew
update

# Upgrade any already-installed formulae
upgrade

# Install GNU core utilities (those that come with OS X are outdated)
install coreutils

# Install GRC for coloring
install grc

# Install GNU `find`, `locate`, `updatedb`, and `xargs`, g-prefixed
#install findutils

# Install wget with IRI support
#install wget --enable-iri

# Install more recent versions of some OS X tools
install vim --override-system-vi

# Install other useful binaries
install ack
install git
install ngrep
#install node
install rename
install tree

# Remove outdated versions from the cellar
cleanup
4 changes: 1 addition & 3 deletions homebrew/install.sh
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ if test ! $(which brew)
then then
echo " Installing Homebrew for you." echo " Installing Homebrew for you."
ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)" > /tmp/homebrew-install.log ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)" > /tmp/homebrew-install.log
else
brew update
fi fi


# Install homebrew packages # Install homebrew packages
brew install grc coreutils brew bundle "${0%/*}/Brewfile"


exit 0 exit 0
53 changes: 53 additions & 0 deletions osx/aliases.zsh
Original file line number Original file line Diff line number Diff line change
@@ -1 +1,54 @@
# Quick-open iOS Simulator
alias ios="open /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app" alias ios="open /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app"

# Clean up LaunchServices to remove duplicates in the “Open With” menu
alias lscleanup="/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -kill -r -domain local -domain system -domain user && killall Finder"

# Flush Directory Service cache
alias flush="dscacheutil -flushcache && killall -HUP mDNSResponder"

# Empty the Trash on all mounted volumes and the main HDD
# Also, clear Apple’s System Logs to improve shell startup speed
alias emptytrash="sudo rm -rfv /Volumes/*/.Trashes; sudo rm -rfv ~/.Trash; sudo rm -rfv /private/var/log/asl/*.asl"

# Show/hide hidden files in Finder
alias showhf="defaults write com.apple.finder AppleShowAllFiles -bool true && killall Finder"
alias hidehf="defaults write com.apple.finder AppleShowAllFiles -bool false && killall Finder"

# Hide/show all desktop icons (useful when presenting)
alias hidedesktop="defaults write com.apple.finder CreateDesktop -bool false && killall Finder"
alias showdesktop="defaults write com.apple.finder CreateDesktop -bool true && killall Finder"

# Spotlight
alias spotoff="sudo mdutil -a -i off"
alias spoton="sudo mdutil -a -i on"

# One of @janmoesen’s ProTip™s
for method in GET HEAD POST PUT DELETE TRACE OPTIONS; do
alias "$method"="lwp-request -m '$method'"
done

# PlistBuddy alias, because sometimes `defaults` just doesn’t cut it
alias plistbuddy="/usr/libexec/PlistBuddy"

# Ring the terminal bell, and put a badge on Terminal.app’s Dock icon
# (useful when executing time-consuming commands)
alias badge="tput bel"

# Stuff I never really use but cannot delete either because of http://xkcd.com/530/
alias stfu="osascript -e 'set volume output muted true'"
alias pumpitup="osascript -e 'set volume 7'"
alias hax="growlnotify -a 'Activity Monitor' 'System error' -m 'WTF R U DOIN'"

# Kill all the tabs in Chrome to free up memory
# [C] explained: http://www.commandlinefu.com/commands/view/402/exclude-grep-from-your-grepped-output-of-ps-alias-included-in-description
alias chromekill="ps ux | grep '[C]hrome Helper --type=renderer' | grep -v extension-process | tr -s ' ' | cut -d ' ' -f2 | xargs kill"

# Lock the screen (when going AFK)
alias afk="/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend"

# OS X has no `md5sum`, so use `md5` as a fallback
command -v md5sum > /dev/null || alias md5sum="md5"

# OS X has no `sha1sum`, so use `shasum` as a fallback
command -v sha1sum > /dev/null || alias sha1sum="shasum"
12 changes: 11 additions & 1 deletion system/aliases.zsh
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,4 +7,14 @@ then
alias l="gls -lAh --color" alias l="gls -lAh --color"
alias ll="gls -l --color" alias ll="gls -l --color"
alias la='gls -A --color' alias la='gls -A --color'
fi fi

# Enhanced WHOIS lookups
alias whois="whois -h whois-servers.net"

# URL-encode strings
alias urlencode='python -c "import sys, urllib as ul; print ul.quote_plus(sys.argv[1]);"'

# View HTTP traffic
alias sniff="sudo ngrep -d 'en1' -t '^(GET|POST) ' 'tcp and port 80'"
alias httpdump="sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E \"Host\: .*|GET \/.*\""

0 comments on commit 5b9591a

Please sign in to comment.