Skip to content

Instantly share code, notes, and snippets.

View todd-a-jacobs's full-sized avatar

Todd A. Jacobs todd-a-jacobs

View GitHub Profile
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`!()\[\]{};:'".,<>?«»“”‘’]))
The regex patterns in this gist are intended only to match web URLs -- http,
https, and naked domains like "example.com". For a pattern that attempts to
match all URLs, regardless of protocol, see: https://gist.github.com/gruber/249502
# Single-line version:
(?i)\b((?:https?:(?:/{1,3}|[a-z0-9%])|[a-z0-9.\-]+[.](?:com|net|org|edu|gov|mil|aero|asia|biz|cat|coop|info|int|jobs|mobi|museum|name|post|pro|tel|travel|xxx|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|dd|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|s
# username = "my_username"
# pwd = "my_password"
# target_path = "my_target_path"
# saving auth cookie
system %Q{wget --save-cookies /tmp/cookie.txt --keep-session-cookies --post-data "username=#{username}&password=#{pwd}" -O - \
https://rubytapas.dpdcart.com/subscriber/login?__dpd_cart=d08391e6-5fe2-4400-8b27-2dc17b413027}
(25..600).each do |i|
@todd-a-jacobs
todd-a-jacobs / any_vs_intersection.rb
Last active August 29, 2015 14:06
Benchmark Enumerable#any? vs. Array#&
require 'benchmark'
ITERATIONS = 100_000
Benchmark.bmbm do |x|
x.report('Array#&') do
ITERATIONS.times do
([2, 6, 13, 99, 27] & [6, 13]).any?
end
end
x.report('Enumerable#any?') do
@todd-a-jacobs
todd-a-jacobs / kernel_rand_with_range.rb
Created September 22, 2014 20:26
Testing Kernel#rand with a Range of FIXNUM_MIN..FIXNUM_MAX
FIXNUM_MAX = (2**(0.size * 8 -2) -1)
FIXNUM_MIN = -(2**(0.size * 8 -2))
1_000_000.times do
r = rand(FIXNUM_MIN..FIXNUM_MAX)
fail if r > FIXNUM_MAX or r.class != Fixnum
fail if r < FIXNUM_MIN or r.class != Fixnum
end
@todd-a-jacobs
todd-a-jacobs / xcode.exp
Created September 27, 2014 05:49
Accept xcodebuild license agreement non-interactively.
#!/usr/bin/expect -f
# vim: sw=4:et:ft=expect:fdm=indent
set timeout -1
log_user 0
spawn sudo xcodebuild -license
match_max 100000
expect {
"Hit the Enter key" {
send -- "\r"
@todd-a-jacobs
todd-a-jacobs / xcodebuild_license_accept.sh
Created September 27, 2014 05:55
Auto-accept Apple's Xcode EULA.
#!/bin/bash
sudo xcodebuild -license accept
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`!()\[\]{};:'".,<>?«»“”‘’]))
@todd-a-jacobs
todd-a-jacobs / nsw.sh
Last active August 29, 2015 14:10
What time is it "Down Under" in New South Wales?
#!/usr/bin/env bash
TZ='Australia/Sydney' date
@todd-a-jacobs
todd-a-jacobs / caller_to_symbol.rb
Created December 15, 2014 17:33
Return name of calling method as a Symbol.
#!/usr/bin/env ruby
def foo
caller[0].match(/`\K[^']+/).to_s.to_sym
end
def bar
foo
end