This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Regexp | |
def to_proc | |
Proc.new { |arg| arg =~ self } | |
end | |
end | |
# select behaves like as Enumerable#grep: | |
%w(foo bar baz boo fooz goo).select &/oo/ # => ["foo", "boo", "fooz", "goo"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc 'Locate lines of code, that are too long.' | |
task :longlines do | |
pattern = ENV['PATTERN'] || '**/*.rb' | |
length_limit = ENV['LENGTH_LIMIT'] || 80 | |
ignore_comments = (ENV['IGNORE_COMMENTS'] == 'false' ? false : true) | |
Dir.glob pattern do |file| | |
File.foreach(file).with_index(1) do |line, index| | |
if file.end_with?('.rb') && ignore_comments | |
next if line =~ /^\s*#/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
=begin | |
Test network by investigating connection to servers in different geographical | |
locations. | |
Prints results to stdout. | |
Shells out to mtr(1) (http://www.bitwizard.nl/mtr/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(eval-when-compile | |
(require 'cl-lib)) | |
(defun foo (count) | |
"Inserts at point position COUNT metasyntactic variable names separated by spaces. | |
Compatible with RFC-3092." | |
(interactive "p") | |
(insert | |
(mapconcat | |
'identity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--color | |
--format progress | |
--order random |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func main() { | |
fizz_buzz() | |
} | |
func fizz_buzz() { | |
for num := 1; num <= 100; num++ { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
require 'forwardable' | |
require 'minitest/autorun' | |
class Fibonacci | |
extend Forwardable | |
def_delegator :generator, :take |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
/* | |
concurrent hello world | |
*/ | |
func main() { | |
sayHello := make(chan bool) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
IO.popen('git log --name-only --pretty=format:""') | |
.readlines | |
.map(&:chomp) | |
.reject(&:empty?) | |
.select { |file| File.exists?(File.expand_path(file, ENV['GIT_WORK_TREE'])) } | |
.each_with_object(Hash.new(0)) { |file, changes| changes[file] += 1 } | |
.to_a | |
.sort_by(&:last) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def quick_sort(list) | |
return list.dup unless list.size > 1 | |
x = list.sample | |
h = list.group_by { |item| item <=> x } | |
h.default = [] | |
less, equal, more = h[-1], h[0], h[1] |