Vavr List
:
List<String> str = List.of("A", "B", "C");
HashSet<String> res = str.foldLeft(
HashSet.empty(),
(set, s) -> set.add(s)
);
Vavr List
:
List<String> str = List.of("A", "B", "C");
HashSet<String> res = str.foldLeft(
HashSet.empty(),
(set, s) -> set.add(s)
);
from typing import Tuple, List | |
"""A 'bin' of observations in the form (average, error, # of observations)""" | |
Bin = Tuple[float, float, int] | |
"""Based on http://isi.ssl.berkeley.edu/~tatebe/whitepapers/Combining%20Errors.pdf""" | |
def combine(a: Bin, b: Bin) -> Bin: | |
a_avg, a_err, n_a = a | |
b_avg, b_err, n_b = b | |
n = n_a + n_b |
# in spec/features_helper.rb | |
# adapted from https://robots.thoughtbot.com/automatically-wait-for-ajax-with-capybara | |
# for legacy Rails apps still using Prototype.js | |
def wait_for_ajax! | |
Timeout.timeout(Capybara.default_max_wait_time) do | |
# Error pages etc. may not have Ajax defined | |
loop until page.evaluate_script("(typeof Ajax === 'undefined') ? 0 : Ajax.activeRequestCount").zero? | |
end | |
end |
#!/usr/bin/env ruby | |
require 'pathname' | |
infile = ARGV[0] | |
fonts_dir = ARGV[1] | |
unless infile && fonts_dir | |
puts "Usage: webfonts-to-local.rb <INPUT-CSS> <FONTS-DIR>" | |
exit(1) |
package main | |
import ( | |
"fmt" | |
"io/ioutil" | |
"log" | |
"github.com/aws/aws-sdk-go/aws" | |
"github.com/aws/aws-sdk-go/aws/session" | |
"github.com/aws/aws-sdk-go/service/s3" |
The seed-dump gem generates db/seeds.rb
for a Rails project from an existing database. It also works outside of Rails with
standalone-migrations, but you
need to jump through a couple of hoops to set up the Rake task and give it access
to your model classes.
In your Gemfile:
gem 'seed_dump'
Decide where you're going to put the compiled library, e.g. ~/lib
. We'll
call this <target-dir>
below.
Clone ralight/sqlite3-pcre
Ensure pcre
is installed (brew install pcre
).
In the sqlite3-pcre
directory, compile with:
cc \
-shared \
-o /sqlite3-pcre.so \
Cf. this StackOverflow answer:
brew install rbenv/tap/openssl@1.0
rvm reinstall 1.8.7-head --with-openssl-dir='/usr/local/Cellar/openssl@1.0/1.0.2t' \
--with-openssl-lib='/usr/local/Cellar/openssl@1.0/1.0.2t/lib' \
--with-openssl-include=/usr/local/Cellar/openssl@1.0/1.0.2t/include
rvm use 1.8.7
# In your Rakefile (after Rails.application.load_tasks, in a Rails project): | |
module TaskExtensions | |
def invoke | |
(@logger ||= Logger.new($stderr)).tap do |logger| | |
logger.info("invoke #{self.name}") # note: you can also dump environment variables etc. here | |
end | |
super | |
end | |
end |
# ######################################## | |
# Start server and manager in background | |
/start-server.sh & | |
SERVER_PID=$! | |
/start-manager.sh & | |
MANAGER_PID=$! | |
# ######################################## |