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-test
module Uu58 | |
# Convert a string UUID to a base58 string representation. | |
# | |
# Output will be padded up to 22 digits if necessary. | |
# | |
# Behaviour is undefined if passing something other than a 128-bit | |
# hex string in network order with optional interstitial hyphens. | |
def self.uuid_to_base58(uuid, alphabet = SecureRandom::BASE58_ALPHABET) | |
ary = uuid.delete("-").to_i(16).digits(58).reverse | |
ary.unshift(0) while ary.length < 22 |
<template lang='pug'> | |
div.drop-zone(:class='{dragging: isDragging }' | |
@dragover.prevent='dragover' | |
@dragenter.prevent='dragover' | |
@drop.prevent.stop='onDrop' | |
@dragleave.prevent='dragleave') | |
div(:class='{ hidden: uploadInProgress }' @click='openFileBrowser') | |
slot | |
i {{label}} | |
input(type='file' :multiple='multiple' ref='input' style='display: none') |
let fnGetFileNameFromContentDispostionHeader = function (header) { | |
let contentDispostion = header.split(';'); | |
const fileNameToken = `filename*=UTF-8''`; | |
let fileName = 'downloaded.pdf'; | |
for (let thisValue of contentDispostion) { | |
if (thisValue.trim().indexOf(fileNameToken) === 0) { | |
fileName = decodeURIComponent(thisValue.trim().replace(fileNameToken, '')); | |
break; | |
} |
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-test
# base58_to_int and int_to_base58 loosely based on base58 gem by Douglas F. Shearer | |
# https://github.com/dougal/base58 | |
ALPHABET = "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ".chars | |
BASE = ALPHABET.size | |
def base58_to_int(base58_val) | |
base58_val.chars | |
.reverse_each.with_index | |
.reduce(0) do |int_val, (char, index)| |
console.log('Loading function'); | |
const https = require('https'); | |
const url = require('url'); | |
// to get the slack hook url, go into slack admin and create a new "Incoming Webhook" integration | |
const slack_url = 'https://hooks.slack.com/services/...'; | |
const slack_req_opts = url.parse(slack_url); | |
slack_req_opts.method = 'POST'; | |
slack_req_opts.headers = {'Content-Type': 'application/json'}; |
class BigDecimal | |
def inspect | |
"#<BigDecimal: #{to_s}>" | |
end | |
end | |
# include from an initializer | |
module HstoreAccessor | |
def self.included(base) | |
base.extend(ClassMethods) | |
end | |
module ClassMethods | |
def hstore_accessor(hstore_attribute, *keys) | |
Array(keys).flatten.each do |key| |
# The worst possible way to memoize something. | |
class X | |
def value | |
@value = really_expensive_operation | |
def value; @value end | |
@value | |
end | |
end |