Skip to content

Instantly share code, notes, and snippets.

View zhaocai's full-sized avatar
🤨
I may be slow to respond.

Zhao Cai zhaocai

🤨
I may be slow to respond.
View GitHub Profile
@zhaocai
zhaocai / Liberal Regex Pattern for URLs
Created October 16, 2016 23:07 — forked from winzig/Liberal Regex Pattern for URLs
Updated @gruber's regex with a modified version that looks for 2-13 letters rather than trying to look for specific TLDs. Given the recent addition of ~1400 gTLDs, it may be time to give up on that front.
# Single-line version:
(?i)\b((?:https?:(?:/{1,3}|[a-z0-9%])|[a-z0-9.\-]+[.](?:[a-z]{2,13})(?:[^\s()<>{}\[\]]+|\([^\s()]*?\([^\s()]+\)[^\s()]*?\)|\([^\s]+?\))+(?:\([^\s()]*?\([^\s()]+\)[^\s()]*?\)|\([^\s]+?\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’])|(?:(?<!@)[a-z0-9]+(?:[.\-][a-z0-9]+)*[.](?:[a-z]{2,13})\b/?(?!@)))
# Commented multi-line version:
(?xi)
\b
( # Capture 1: entire matched URL
(?:

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
@zhaocai
zhaocai / Objective-C to MacRuby method translate
Created November 28, 2012 00:19 — forked from ryecroft/Objective-C to MacRuby method translate
Ruby script to translate Objective-C method calls into MacRuby
#!/usr/bin/env ruby
# Translates an objective C method call on the pasteboard,
# as copied from the docs, into MacRuby syntax, placing it
# back on the pasteboard.
# @example
# '+ (NSColor *)colorWithCalibratedRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha'
# => 'colorWithCalibratedRed(red, green:green, blue:blue, alpha:alpha)'
string = `pbpaste`
@zhaocai
zhaocai / colortrans.py
Created August 28, 2012 13:17 — forked from MicahElliott/colortrans.py
Convert values between RGB hex codes and xterm-256 color codes.
#! /usr/bin/env python
""" Convert values between RGB hex codes and xterm-256 color codes.
Nice long listing of all 256 colors and their codes. Useful for
developing console color themes, or even script output schemes.
Resources:
* http://en.wikipedia.org/wiki/8-bit_color
* http://en.wikipedia.org/wiki/ANSI_escape_code
@zhaocai
zhaocai / growlnotify.rb
Created August 4, 2012 06:35 — forked from ttscoff/growlnotify.rb
Seamless drop-in to turn existing growlnotify calls into Mountain Lion Notifications
#!/usr/bin/env ruby
# encoding: utf-8
# == Synopsis
# Requires the terminal-notifier gem ([sudo] gem install terminal-notifier)
# growlnotify wrapper to turn Growl alerts into Mountain Lion notifications
# Uses growlnotify option syntax to keep your old scripts working with the new shiny.
#
# If you use Growl via growlnotify in your shell scripting, this script
# will replace Growl's alerts with Mountain Lion notifications.
@zhaocai
zhaocai / bash-stack.bash
Created November 9, 2011 02:04 — forked from tlrobinson/bash-stack.bash
Bash XML parser and stack, plus Gmail XML feed parsing example
#!/usr/bin/env bash
# Bash Stack
set -o errtrace
set -o errexit
set -o nounset
declare -a stack