by Ossi Hanhinen, @ohanhi
with the support of Futurice 💚.
Licensed under CC BY 4.0.
require "json" | |
require "net/http" | |
require "uri" | |
# The standard library Net::HTTP module is a bit convoluted, but here is an example of a flexible | |
# system for making different kinds of HTTP requests. To see some convenience methods you can | |
# consult the docs: https://ruby-doc.org/stdlib-2.5.5/libdoc/net/http/rdoc/Net/HTTP.html | |
class HttpConnection | |
def get(url, params = nil) |
class Expectation | |
def to(matcher = nil, &block) | |
if block_given? | |
puts "block passed to `to` method" | |
yield | |
end | |
end | |
end | |
def expect |
#!/bin/sh | |
# Simplified from this script, (less robust and more to the point): | |
# http://gmodarelli.com/2015/02/code-reviews-rubocop-git-pre-commit/ | |
# Installation: copy this code into <REPO>.git/hooks/pre-commit.sh | |
# Select only staged Ruby files | |
FILES="$(git diff --cached --name-only --diff-filter=AMC | grep "\.rb$" | tr '\n' ' ')" |
The goal of this is to have an easily-scannable reference for the most common syntax idioms in Ruby and Rust so that programmers most comfortable with Ruby can quickly get through the syntax differences and feel like they could read and write basic Rust programs.
What do you think? Does this meet its goal? If not, why not?
Ruby:
# This algorithm takes a *sorted* list of integers, probably record | |
# IDs and compresses them into a series of ranges. It also includes a | |
# verification check that no values were lost. | |
def compress(ary) | |
range_start = ary.first | |
compressed = [] | |
ary.each_with_index do |value, index| | |
# TODO: This could skip indices that have already been considered. |
First, you install ruby-build and chruby. ruby-build is a program that knows how to download and build different ruby versions. chruby manages $PATH
to control which ruby
gets invoked in your shell. They work completely independently.
sudo su
cd /usr/src
git clone https://github.com/sstephenson/ruby-build.git
cd ruby-build
./install.sh
cd -
# Adapted from from: http://nestegg.rubyforge.org/ | |
module NestedException | |
# Public: Initializes a new nested error, the original error defaults | |
# to the global error variable so that it doesn't need to be explicity | |
# provided when re-raising an exception. | |
def initialize(message = nil, cause = $!) | |
@cause = cause | |
super(message || cause && cause.message) | |
end |
<?php | |
class Curl { | |
const HEAD = 'POST'; | |
const GET = 'GET'; | |
const POST = 'POST'; | |
const PUT = 'PUT'; | |
const DELETE = 'DELETE'; | |
const LOCK = 'LOCK'; | |
const UNLOCK = 'UNLOCK'; |