Ruby's for keyword is an anti pattern! In fact, it's actually slower than each and uses each in the background.
for n in [1, 2, 3, 4]
puts n| package main | |
| import( | |
| "bufio" | |
| "fmt" | |
| "log" | |
| "os" | |
| "regexp" | |
| ) |
| mapSum :: Num a => (a -> a) -> [a] -> a | |
| mapSum f xs = sum $ map f xs | |
| nestedSum :: Num a => [a] -> [a] -> (a -> a -> a) -> a | |
| nestedSum xs ys f = mapSum (\ x -> mapSum (f x) ys) xs |
| package main | |
| import ( | |
| "os" | |
| "fmt" | |
| ) | |
| func main() { | |
| for _, pair := range os.Environ() { | |
| fmt.Println(pair) |
This benchmark was used for run.
go test -bench=.
Note that there are no dependencies besides Go itself.
| # usage: ruby web_cat.rb URL | |
| require 'nokogiri' | |
| require 'open-uri' | |
| uri = ARGV[0] | |
| doc = Nokogiri::HTML open uri | |
| puts doc.text |
| require 'open-uri' | |
| changelog = open 'https://raw.githubusercontent.com/angular/angular.js/master/CHANGELOG.md' | |
| headlines = changelog.grep(/^# /) | |
| headlines.each do |headline| | |
| version, codename = headline.match(/(\S+) +(\S+) +\([\d-]+\)/).captures | |
| puts "#{version}: #{codename}" | |
| end |
| -- | lookup' @key assocs@ looks up a value in an association list. While lookup | |
| -- finds a tuple where the first value matches and returns the second, lookup' | |
| -- does the opposite. | |
| lookup' :: (Eq b) => b -> [(a,b)] -> Maybe a | |
| lookup' _ [] = Nothing | |
| lookup' key ((x,y):xys) | |
| | key == y = Just x | |
| | otherwise = lookup' key xys | |
| -- Prints "Just 2". |
| main = getContents >>= putStr |
| #!/bin/bash | |
| # Sometimes when you use AirPlay, your Mac's audio may die. | |
| # If so, you can run this script to restart coreaudiod, which should fix your problem. | |
| # Note that this may be slightly interactive because it uses sudo. | |
| sudo killall coreaudiod |