Skip to content

Instantly share code, notes, and snippets.

View frsyuki's full-sized avatar

Sadayuki Furuhashi frsyuki

View GitHub Profile
@frsyuki
frsyuki / ft_bigram.sql
Last active June 23, 2021 22:34
PostgreSQL bi-gram full text search without application code
-- ref: https://www.clear-code.com/blog/2020/12/22.html
create type fts_bigram_token as (token text, position bigint);
create or replace function fts_bigram_tokenize(value text)
returns setof fts_bigram_token as $$
select trim(coalesce(lag(c) over (), '') || c), row_number() over ()
from (
select unnest(
regexp_matches(regexp_replace(value, '[[:punct:]]', ' ', 'g') || ' ', '(?!\s\s).', 'g')
import java.io.File;
import java.io.IOException;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Source;
import org.graalvm.polyglot.Value;
public class GraalPolyglot {
public static void main(String[] args) throws IOException {
Source source = Source.newBuilder("ruby", new File(args[0])).build();
import java.io.File;
import java.io.IOException;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Source;
import org.graalvm.polyglot.Value;
public class GraalPolyglot {
public static void main(String[] args) throws IOException {
Source source = Source.newBuilder("ruby", new File(args[0])).build();
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Value;
public class GraalPolyglot {
public static void main(String[] args) {
try (Context context = Context.newBuilder().allowAllAccess(true).build()) {
Value v = context.eval("ruby", "'Ruby String'");
context.getBindings("js").putMember("v", v);
context.eval("js", "print('v=' + v)"); //=> v=Ruby String
}
./configure \
$(ruby -e "puts RbConfig::CONFIG['configure_args']") \
CFLAGS=$(ruby -e "puts RbConfig::CONFIG['CFLAGS'] + ' -flto'") \
LDFLAGS=$(ruby -e "puts RbConfig::CONFIG['LDFLAGS'] + ' -flto'") \
--enable-shared \
--prefix=$(pwd)/install
require 'benchmark'
Benchmark.bmbm do |x|
  x.report("Array.push") do
    arrays = []
    1000.times do |i|
      arrays[i] = []
      (0...500000).each do |j|
        arrays[i] = j
      end

No optimization:

        user     system      total        real
0.1kb   1.204809   0.005060   1.209869 (  1.210884)
1kb     1.309668   0.004896   1.314564 (  1.315971)
10kb    2.674302   0.077470   2.751772 (  2.755213)
100kb  29.982771  22.375113  52.357884 ( 52.386822)
500kb 122.625423  82.284026 204.909449 (205.018250)
600kb 1.006700 0.003676 1.010376 ( 1.010782)
require 'benchmark'
require 'json'
require 'yajl'
require 'msgpack'
here = File.dirname(File.expand_path(__FILE__))
# https://catalog.data.gov/dataset/consumer-complaint-database
VIEWS_OBJ = JSON.load(File.read("#{here}/views.json"))
VIEWS_MSGPACK = MessagePack.pack(VIEWS_OBJ)
public class Multistage<P>
{
public static class State<T>
{
private Object nextLambdaArgument;
private boolean isNext;
private State(Object nextLambdaArgument, boolean isNext)
{
source 'https://rubygems.org/'
gemspec