CoffeeScript 1.7 is shaping up to be a pretty kick-ass release with significant improvements. Here are the ones I'm most excited about, in order of my own excitement.
Years of being wished for, finally granted!
| # Given an array of arrays s = [ [1,2,3], [4,5,6], ... ] | |
| # compute the Cartesian product among the elements of s. | |
| require 'pp' | |
| s = [[1, 2], [3, 4, 5], [6, 7, 8, 9]] | |
| pp s[1..-1].inject(s[0]){ |m,v| m = m.product(v).map(&:flatten) } | |
| [[1, 3, 6], | |
| [1, 3, 7], | |
| [1, 3, 8], |
| Ruby 2.1.0 in Production: known bugs and patches | |
| Last week, we upgraded the github.com rails app to ruby 2.1.0 in production. | |
| While testing the new build for rollout, we ran into a number of bugs. Most of | |
| these have been fixed on trunk already, but I've documented them below to help | |
| anyone else who might be testing ruby 2.1 in production. | |
| @naruse I think we should backport these patches to the ruby_2_1 branch and | |
| release 2.1.1 sooner rather than later, as some of the bugs are quite critical. | |
| I'm happy to offer any assistance I can to expedite this process. |
| require 'stringio' | |
| require 'timeout' | |
| class Object | |
| def methods_returning(expected, *args, &blk) | |
| old_stdout = $> | |
| $> = StringIO.new | |
| methods.select do |meth| | |
| Timeout::timeout(1) { dup.public_send(meth, *args, &blk) == expected rescue false } rescue false |
CoffeeScript 1.7 is shaping up to be a pretty kick-ass release with significant improvements. Here are the ones I'm most excited about, in order of my own excitement.
Years of being wished for, finally granted!
| public class Perlin { | |
| public int repeat; | |
| public Perlin(int repeat = -1) { | |
| this.repeat = repeat; | |
| } | |
| public double OctavePerlin(double x, double y, double z, int octaves, double persistence) { | |
| double total = 0; |
| require "net/http" | |
| def start_server | |
| # Remove the X to enable the parameters for tuning. | |
| # These are the default values as of Ruby 2.2.0. | |
| @child = spawn(<<-EOC.split.join(" ")) | |
| XRUBY_GC_HEAP_FREE_SLOTS=4096 | |
| XRUBY_GC_HEAP_INIT_SLOTS=10000 | |
| XRUBY_GC_HEAP_GROWTH_FACTOR=1.8 | |
| XRUBY_GC_HEAP_GROWTH_MAX_SLOTS=0 |
It's now here, in The Programmer's Compendium. The content is the same as before, but being part of the compendium means that it's actively maintained.
| name: CI | |
| on: [push] | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| container: | |
| image: ruby:2.6.5 |
Let's say you want to use Ruby for the backend of a basic webapp but React on the frontend. Here's how.
(Note: All tested on January 13, 2025 with Ruby 3.3, Sinatra 4.1.1, and React 18.3. Configs may change over time.)
First, create the app folder and set up Sinatra:
mkdir my-sinatra-react-app