This gist will collects all issues we solved with Rails 5.2 and Webpacker
# Last few parameters(--skip-* part) is only my habbit not actully required
$ rails new <project_name> --webpack=stimulus --database=postgresql --skip-coffee --skip-testThis gist will collects all issues we solved with Rails 5.2 and Webpacker
# Last few parameters(--skip-* part) is only my habbit not actully required
$ rails new <project_name> --webpack=stimulus --database=postgresql --skip-coffee --skip-test| const webpack = require('webpack') | |
| const { environment } = require('@rails/webpacker') | |
| // Don't use commons chunk for server_side_render chunk | |
| const entries = environment.toWebpackConfig().entry | |
| const commonsChunkEligible = Object.keys(entries).filter(name => name !== 'server_side_render') | |
| environment.plugins.set('CommonsChunkVendor', new webpack.optimize.CommonsChunkPlugin({ | |
| name: 'vendor', | |
| minChunks: (module, count) => { |
| #!/bin/bash | |
| # Copyright © 2017 Google Inc. | |
| # Licensed under the Apache License, Version 2.0 (the "License"); | |
| # you may not use this file except in compliance with the License. | |
| # You may obtain a copy of the License at | |
| # | |
| # http://www.apache.org/licenses/LICENSE-2.0 | |
| # | |
| # Unless required by applicable law or agreed to in writing, software |
| -- Enable pl/v8: | |
| CREATE EXTENSION plv8; | |
| -- Create json history table: | |
| CREATE TABLE json_history (id BIGSERIAL PRIMARY KEY, tstamp timestamp DEFAULT now(), table_name text, column_name text, target_id bigint, transform json); | |
| -- Create test table: | |
| CREATE TABLE test_json (id BIGSERIAL PRIMARY KEY, data JSON); | |
| -- Enable history tracking on test_json.data: |
| require 'therubyracer' | |
| require 'commonjs' | |
| webpack_path = `which webpack`.chomp | |
| webpack_content = File.open(webpack_path).read.sub("#!/usr/bin/env node\n", '') | |
| ctx = V8::Context.new | |
| env = CommonJS::Environment.new(ctx, path: '/usr/local/lib/node_modules') | |
| ctx['require'] = lambda { |this, module_id| env.require(module_id) } |
| Ansible playbook to setup HTTPS using Let's encrypt on nginx. | |
| The Ansible playbook installs everything needed to serve static files from a nginx server over HTTPS. | |
| The server pass A rating on [SSL Labs](https://www.ssllabs.com/). | |
| To use: | |
| 1. Install [Ansible](https://www.ansible.com/) | |
| 2. Setup an Ubuntu 16.04 server accessible over ssh | |
| 3. Create `/etc/ansible/hosts` according to template below and change example.com to your domain | |
| 4. Copy the rest of the files to an empty directory (`playbook.yml` in the root of that folder and the rest in the `templates` subfolder) |
| defmodule JSONMapBuilder do | |
| def to_map(list) when is_list(list) and length(list) > 0 do | |
| case list |> List.first do | |
| {_, _} -> | |
| Enum.reduce(list, %{}, fn(tuple, acc) -> | |
| {key, value} = tuple | |
| Map.put(acc, binary_to_atom(key), to_map(value)) | |
| end) | |
| _ -> | |
| list |
| #!/bin/env/ruby | |
| # gem "aws-sdk", "~> 2" | |
| require "rubygems" | |
| require "zlib" | |
| require "rubygems/package" | |
| require "securerandom" | |
| gem "aws-sdk" | |
| require "aws-sdk" |
| # This is just a cheat sheet: | |
| # On production | |
| sudo -u postgres pg_dump database | gzip -9 > database.sql.gz | |
| # On local | |
| scp -C production:~/database.sql.gz | |
| dropdb database && createdb database | |
| gunzip < database.sql.gz | psql database |