Skip to content

Instantly share code, notes, and snippets.

Avatar

Stefan Wienert zealot128

View GitHub Profile
@zealot128
zealot128 / simple_form.rb
Created Aug 13, 2022
Rails simple_form Tailwind Daisy UI config
View simple_form.rb
# frozen_string_literal: true
#
# Uncomment this and change the path if necessary to include your own
# components.
# See https://github.com/heartcombo/simple_form#custom-components to know
# more about custom components.
# Dir[Rails.root.join('lib/components/**/*.rb')].each { |f| require f }
#
# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
@zealot128
zealot128 / baudit.rb
Last active Jul 22, 2022
Batch Bundler-audit a whole directory and bundle update all the affected Gems conservatively
View baudit.rb
require 'bundler/inline'
# TODO: Skip Auto udpate when not on master or main branch
gemfile do
source 'https://rubygems.org'
gem 'bundler-audit', "~> 0.9"
gem 'pry'
gem 'tty-prompt'
end
@zealot128
zealot128 / inertia.ts
Created Dec 21, 2021
Vite-rails + Inertia base setup
View inertia.ts
import { createApp, h } from 'vue'
import { createInertiaApp } from '@inertiajs/inertia-vue3'
import i18n from '~/utils/i18n'
createInertiaApp({
resolve: name => import(`/pages/${name}.vue`),
setup({ el, app, props, plugin }) {
createApp({ render: () => h(app, props) })
.use(plugin)
@zealot128
zealot128 / rails-models-to-typescript-schema.rb
Last active Aug 8, 2022
Simple ruby script to generate Active Record Typescript information with enums + associations
View rails-models-to-typescript-schema.rb
# USAGE:
# rails runner rails-models-to-typescript-schema.rb > app/javascript/types/schema.d.ts
Rails.application.eager_load!
models = ActiveRecord::Base.descendants.reject { |i| i.abstract_class? }
belongs_to = true
has_many = true
View AutocompleteInput.vue
<template lang="pug">
form(@submit.prevent.stop="enterCurrentSelected")
.form-autocomplete(@blur.native='blur' @unfocus='blur')
.input-group.form-autocomplete-input
input.form-input.input-lg(
ref='input'
type="text" name="query" v-model.sync="query" placeholder="搜索查询" autocomplete="off" autofocus @blur='blur'
@keydown.right='selectCurrentContinue'
@keydown.up='selectPrevious'
@keydown.down='selectNext'
View d3-sankey-circular.js
import { min, ascending, max, mean, sum } from 'd3-array';
import { map, nest } from 'd3-collection';
import { linkHorizontal } from 'd3-shape';
import findCircuits from 'elementary-circuits-directed-graph';
// For a given link, return the target node's depth
function targetDepth(d) {
return d.target.depth;
}
@zealot128
zealot128 / README.md
Last active Jun 14, 2021
Migrate off rails-assets.org
View README.md

Migrate Gem-assets by vendoring

inspired: https://www.ramblingcode.dev/posts/bye_rails_assets/

This script + initializer can help you to migrate of the "rails-assets.org" hosted assets. If you can not immediately move to Webpack/NPM, you can just copy the asset content into your vendor directory.

Add to your config/initializers/assets.rb:

Rails.application.configure do
@zealot128
zealot128 / d3-sankey-circular.d.ts
Created Dec 11, 2020
d3-sankey-circular typescript types
View d3-sankey-circular.d.ts
type SankeyInputNode = {
name: string
column?: number,
}
type SankeyInputLink = {
source: string,
target: string,
value: number,
optimal: string
}
@zealot128
zealot128 / PageWithSelectableText.vue
Last active May 2, 2022
vue-pdf page with selectable text: Usage: <pdf-viewer :pdf-url="pdfUrl" />
View PageWithSelectableText.vue
<template lang="pug">
.pdf-page--wrapper(:class='{"text-selection": textSelectionEnabled }')
.row.mr-3
.col-sm-3
.col-sm-6.pdf-page--headline {{$t('js.attachment_viewer.page', { page: page })}}
.col-sm-3
.pdf-page--buttons
.btn-group.mr-1(v-if="printable")
button.btn.btn-secondary.btn-sm(type="button" @click="print" data-toggle="tooltip" data-placement="top" :title="$t('js.attachment_viewer.print')")
i.mdi.mdi-printer.mdi-fw
@zealot128
zealot128 / update_pg.sh
Created Nov 13, 2020
Quick Postgresql (Ubuntu) upgrade script
View update_pg.sh
#!/bin/bash
# hint: Run via ssh:
# ssh root@somehost 'bash -s' < upgrade_pg.sh
FROM=9.4
TO=9.6
psql --version
apt update