Skip to content

Instantly share code, notes, and snippets.

@gruber
gruber / Liberal Regex Pattern for All URLs
Last active April 29, 2026 12:46
Liberal, Accurate Regex Pattern for Matching All URLs
The regex patterns in this gist are intended to match any URLs,
including "mailto:foo@example.com", "x-whatever://foo", etc. For a
pattern that attempts only to match web URLs (http, https), see:
https://gist.github.com/gruber/8891611
# Single-line version of pattern:
(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))
-(void)drawInContext:(CGContextRef)myContext {
CGContextSaveGState(myContext);// 6
CGFloat potentialFlip = 1.0;
CGFloat shadowBlur = 4;
CGFloat shadowOffset = 4;
CGFloat shadowOffsetNeg = shadowOffset * -1.0;
CGFloat x = self.bounds.origin.x + shadowOffset;
CGFloat y = self.bounds.origin.y + shadowOffset;
CGFloat wd = self.bounds.size.width - (shadowOffset * 2);
@ulfmagnetics
ulfmagnetics / joyent-smartos.erb
Created February 6, 2012 18:42 — forked from benjaminws/joyent-smartos.erb
joyent-smartos.erb
# shove this in ~/.chef/bootstrap/joyent-smartos.erb
# run knife bootstrap <hostname> -d joyent-smartos
bash -c '
if [ ! -f /opt/local/bin/chef-client ]; then
cd /tmp
pkgin -y install gcc-compiler gcc-runtime gcc-tools-0 ruby19 scmgit-base scmgit-docs gmake
wget http://production.cf.rubygems.org/rubygems/rubygems-1.8.10.tgz
tar -xzf rubygems-1.8.10.tgz
cd rubygems-1.8.10
@robinsloan
robinsloan / langoliers.rb
Last active December 3, 2025 18:13
The Langoliers, a tweet deletion script
require "rubygems"
require "twitter"
require "json"
# things you must configure
TWITTER_USER = "your_username"
MAX_AGE_IN_DAYS = 1 # anything older than this is deleted
# get these from dev.twitter.com
CONSUMER_KEY = "your_consumer_key"
@capotej
capotej / load-test.rb
Last active December 10, 2015 07:18
basic skeleton for executing tasks in parallel in jruby
require 'java'
java_import 'java.util.concurrent.ThreadPoolExecutor'
java_import 'java.util.concurrent.TimeUnit'
java_import 'java.util.concurrent.LinkedBlockingQueue'
java_import 'java.util.concurrent.FutureTask'
java_import 'java.util.concurrent.Callable'
java_import 'java.util.concurrent.Executors'
### SETTINGS
@idan
idan / autoenv.fish
Last active February 8, 2016 15:14
My fish config. I was using oh-my-fish but it seems to introduce a bunch of bugginess.
if not set -q AUTOENVFISH_FILE
set -g AUTOENVFISH_FILE ".env.fish"
end
# Automatic env loading
function _autoenvfish --on-variable PWD
if status --is-command-substitution # doesn't work with 'or', inexplicably
return
end
@k4ml
k4ml / docs.txt
Last active April 12, 2023 20:21
Python client for Webfaction API
# API Reference¶
The WebFaction [XML-RPC](http://en.wikipedia.org/wiki/XML-RPC) API provides
methods to make many account tasks scriptable. This documentation is a
complete reference to all of the possible API methods.
Please note that XML-RPC parameters are positional (order matters), and many
parameters are required. Parameters may only be omitted if omitted parameters
have default values and follow all other parameters to which you have supplied
a value.
#!/bin/sh
# hackyfix ze puppets to run on mavericks
cd /usr/lib/ruby/site_ruby/2.0.0
for i in "facter hiera hiera_puppet.rb puppet.rb puppetx.rb facter.rb hiera.rb puppet puppetx semver.rb"
do
sudo ln -s ../1.8/${i} ${i}
done
#! /usr/bin/env ruby
require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'optparse'
options = {}
optparse = OptionParser.new { |opts|
opts.banner = "Usage : howmuch.rb [-c <city> -s <state>] | [-z <zip>]
@ftrain
ftrain / rhymes.clj
Last active July 14, 2023 22:20
Annotated rhyming dictionary
;; This is at: https://gist.github.com/8655399
;; So we want a rhyming dictionary in Clojure. Jack Rusher put up
;; this code here:
;;
;; https://gist.github.com/jackrusher/8640437
;;
;; I'm going to study this code and learn as I go.
;;
;; First I put it in a namespace.