Skip to content

Instantly share code, notes, and snippets.

Avatar

Stefan Wienert zealot128

View GitHub Profile
@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 Sep 29, 2021
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 Nov 24, 2020
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
@zealot128
zealot128 / Dockerfile
Last active Jan 18, 2022
Basis Docker setup for Rails app (Postgres)
View Dockerfile
FROM ruby:2.7.1-alpine
ENV BUNDLER_VERSION=2.0.2
RUN apk add --update --no-cache \
binutils-gold \
build-base \
curl \
file \
g++ \
@zealot128
zealot128 / run_shell_script.sh
Created Oct 23, 2020
MacOS Automator: Convert file with Handbrake CLI Quick Action
View run_shell_script.sh
# I use this script to quickly convert Screencasts with HandbrakeCLI to Gmail Large 3 minutes,
# which has an OK quality for a screencast but is very small -
# Perfect for quickly showing collegues/customers some new features/Worflows.
#
#
# Create Automator -> New -> Quick Action
# Add Run Shell Script
# Select "Receive input as argument"
# paste script