Skip to content

Instantly share code, notes, and snippets.

View ConradIrwin's full-sized avatar

Conrad Irwin ConradIrwin

View GitHub Profile
>> $KCODE
=> "NONE"
>> "\xc2\xb7" =~ /\w/
=> nil
>> "\xc2\xb7" =~ /[\w]/
=> nil
>> $KCODE="UTF8"
=> "UTF8"
>> "\xc2\xb7" =~ /\w/
=> 0
diff --git a/lib/net.js b/lib/net.js
index 0bbbdf0..0bd4c7a 100644
--- a/lib/net.js
+++ b/lib/net.js
@@ -896,6 +896,10 @@ Stream.prototype.connect = function () {
dns.lookup(arguments[1], function (err, ip, addressType) {
if (err) {
self.emit('error', err);
+ // If the stream is destroyed during the DNS lookup, by an extravagent timeout for example
+ // then continuing is futile.
module URI
# When given a string, returns true if the string represents an http or https URL
# When given no arguments, returns a lambda with the same properties.
#
# URI.valid_link?("http://rapportive.com")
# # => true
# ["httq://rapportive.com", "http://rapportive.com"].select(&URI.valid_link?)
# # => ["http://rapportive.com"]
def self.valid_link?(*args)
if args.present?
require 'blankslate'
# The Ampex library provides a metavariable X that can be used in conjunction
# with the unary ampersand to create anonymous blocks in a slightly more
# readable way than the default. It was inspired by the clever `Symbol#to_proc`
# method which handles the most common case very elegantly, and discussion with
# Sam Stokes who implemented an earlier version of the idea.
#
# At its simplest, &X can be used as a drop-in replacement for
# `Symbol#to_proc`:
@ConradIrwin
ConradIrwin / .vimrc
Created May 6, 2011 03:51
# Comment vim text-object
function! SelectComment()
let curindent = indent(".")
" bail if not a comment
if getline(".")[curindent] != "#"
return
endif
" find the first commented line
while line(".") - 1 && indent(line(".") - 1) == curindent && getline(line(".") - 1)[curindent] == "#"
#!/bin/bash
# Git uncommit allows you to remove changes from your previous commit,
# without loosing any unstaged changes you may have.
# When called with no arguments, removes the entire commit (git reset HEAD^)
# When called with <filename>, removes changes to that file from the commit.
# Also useful is git uncommit -p, which allows you to select which chunks to uncommit.
#
if [ "$#" = 0 ]; then
git reset HEAD^
" ~/.vim/after/syntax/eruby.vim
" Highlight javascript_tag in the same way as <script>.
syn region javaScript start=+<% *javascript_tag *do *%>+ keepend end=+<% *end *%>+me=s-1 contains=@htmlJavaScript,htmlCssStyleComment,htmlScriptTag,@htmlPreproc
function! JsBra()
iunmap (
if match(getline(".")[0 : col(".") - 1], '\<f$') == -1
exec 'normal a('
else
exec 'normal aunction ('
endif
@ConradIrwin
ConradIrwin / pre-commit
Created June 17, 2011 19:02
jslint & whitespace on pre-commit
#!/bin/sh -e
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
Pry.config.commands.command "edit-line", "Edits the current line in your editor" do
require 'tempfile' unless defined? Tempfile
to_edit = (eval_string =~ /^\s*$/ ? target.eval('inp[-1] || ""') : eval_string)
temp_file = Tempfile.new('edit-line')
temp_file.puts to_edit
temp_file.close
# HACK 1. this is a helper in the default command set.