Skip to content

Instantly share code, notes, and snippets.

@mudge
mudge / threequals.rb
Last active August 29, 2015 14:16
More noodling with #to_proc but, this time, through #===, c.f. http://mudge.name/2014/11/26/data-structures-as-functions.html
require 'set'
# Let's provide a default to_proc in terms of threequals
class Object
def to_proc
method(:===).to_proc
end
end
class Set
@mudge
mudge / faraday.rb
Last active August 29, 2015 14:19
How to set request timeouts for various network clients
Faraday.new(site, request: { timeout: 30 })
@mudge
mudge / proc.rb
Last active August 29, 2015 14:22
Composing Procs to explore ideas in Transproc (http://solnic.github.io/transproc/)
class Proc
def compose(g)
proc { |*args, &blk| call(g.call(*args, &blk)) }
end
end
symbolize = ->(x) { x.to_sym }
upcase = ->(x) { x.upcase }
symbolize_and_upcase = symbolize.compose(upcase)
@mudge
mudge / gist:4092
Created August 5, 2008 16:04
Install git's man pages.
GIT_VERSION=`git --version | awk '{print $3}'`
curl -O http://www.kernel.org/pub/software/scm/git/git-manpages-${GIT_VERSION}.tar.bz2
sudo tar xjv -C /usr/local/share/man -f git-manpages-${GIT_VERSION}.tar.bz2
@mudge
mudge / gist:4088
Created August 5, 2008 15:50
I always forget this one.
$COMMAND_WITH_OUTPUT_TO_SUPPRESS >/dev/null 2>&1
@mudge
mudge / gist:6168
Created August 19, 2008 10:12
Delete files by a pattern
find /path_to_search -type f -name "*the_pattern*" -exec rm {} \;
@mudge
mudge / gist:7518
Created August 27, 2008 16:07
git tests to skip on Solaris Nevada.
# git tests to skip on Solaris Nevada (mainly iconv-related).
make test GIT_SKIP_TESTS='t3900 t3901 t5100 t9301'
@mudge
mudge / gist:7492
Created August 27, 2008 14:37
Methods to test whether an object is numeric or not.
class Object
# Test if the object is an integer.
#
# "54".is_i? #=> true
# "54_000".is_i? #=> true
def is_i?
!!Integer(self) rescue false
end
@mudge
mudge / gist:14328
Created October 2, 2008 09:44
Display orphan gems (those that are not depended upon).
#!/usr/bin/env ruby
gems = {}
`gem dependency -R`.split("\n\n").each do |gem|
unless gem["Used by"]
version = gem[/\d+\.\d+\.\d+$/]
name = gem[4..-1][/^.*(?=-\d\.)/]
(gems[name] ||= []) << version
end
end
@mudge
mudge / gist:17385
Created October 17, 2008 09:57
Parser for the jQuery Tablesorter Plugin to sort European dates
/* Parser for the jQuery Tablesorter Plugin to sort European dates, e.g. 30/02/08 */
$.tablesorter.addParser({
id: 'dates',
is: function(s) { return false },
format: function(s) {
var dateArray = s.split('/');
return "20" + dateArray[2] + dateArray[1] + dateArray[0];
},
type: 'numeric'
});