Skip to content

Instantly share code, notes, and snippets.

View zealot128's full-sized avatar

Stefan Wienert zealot128

View GitHub Profile
@zealot128
zealot128 / inertia.ts
Created December 21, 2021 14:53
Vite-rails + Inertia base setup
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 February 18, 2024 12:11
Simple ruby script to generate Active Record Typescript information with enums + associations
# 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
<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'
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 June 14, 2021 19:35
Migrate off rails-assets.org

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 December 11, 2020 18:43
d3-sankey-circular typescript types
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 02:36
vue-pdf page with selectable text: Usage: <pdf-viewer :pdf-url="pdfUrl" />
<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 November 13, 2020 13:20
Quick Postgresql (Ubuntu) upgrade script
#!/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 January 18, 2022 17:15
Basis Docker setup for Rails app (Postgres)
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 October 23, 2020 12:44
MacOS Automator: Convert file with Handbrake CLI Quick Action
# 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