Skip to content

Instantly share code, notes, and snippets.

View ftes's full-sized avatar

Fredrik Teschke ftes

View GitHub Profile
@ftes
ftes / page_live.ex
Last active October 4, 2021 14:18
Drag'n'drop on the PETAL(S) stack
defmodule PetalsDragNDropWeb.PageLive do
# ...
@impl true
def render(assigns) do
~F"""
...
<GridWithDragAndDrop
dragged="letter_dragged"
@ftes
ftes / grid_with_drag_and_drop.html
Last active October 4, 2021 14:17
Drag and drop on the PETAL(S) stack
<div
x-data="{dragging: false}"
:hook="GridWithDragAndDrop"
>
{#for %{x: x, y: y} = item <- @data}
<div
id={item[:id]}
draggable="true"
...
>
@ftes
ftes / page_live.ex
Created October 1, 2021 21:51
alpine.js + liveview
defmodule PetalsDragNDropWeb.PageLive do
use PetalsDragNDropWeb, :live_view
data world, :string, default: "world!"
@impl true
def render(assigns) do
~F"""
<div
id="page"
@ftes
ftes / configuration.yaml.env
Created January 12, 2020 22:11
zigbee2mqtt dynamic configuration.yaml with env variable substitution (e.g. for dynamic configuration via balena.io cloud)
# Environment variables are escaped by the envsubst entrypoint
homeassistant: false
permit_join: $ZIGBEE2MQTT_PERMIT_JOIN
mqtt:
base_topic: zigbee2mqtt
server: 'mqtt://mqtt'
serial:
port: $ZIGBEE2MQTT_SERIAL_PORT
@ftes
ftes / lambda.js
Created December 18, 2019 22:21
Trigger Travis CI build using AWS lambda webhook
/* Environment variables:
* TRAVIS_API_TOKEN
* TRAVIS_REPO_SLUG (%2F separated, e.g. ftes%2Fsongbook-latex)
*/
const https = require('https')
const url = `https://api.travis-ci.com/repo/${process.env.TRAVIS_REPO_SLUG}/requests`
const options = {
method: 'POST',
headers: {
@ftes
ftes / _seating_plan.html.haml
Created November 20, 2019 21:26
Drag and drop in CSS grid with rails 6, stimulus and rails-ujs
-# https://johnbeatty.co/2018/03/09/stimulus-js-tutorial-how-do-i-drag-and-drop-items-in-a-list/
.grid--draggable{ 'data-controller': 'seating-plan',
'data-seating-plan-endpoint': endpoint,
'data-action': 'dragstart->seating-plan#onDragStart dragover->seating-plan#onDragOver dragenter->seating-plan#onDragEnter drop->seating-plan#onDrop dragend->seating-plan#onDragEnd' }
- seating_plan.each do |seat|
- if seat[:is_empty]
.grid__item.grid__item--empty{ 'data-row': seat[:row],
'data-col': seat[:col],
style: "grid-row: #{seat[:row]}; grid-column: #{seat[:col]};",
class: ('grid__item--border' if seat[:is_border]) }
@ftes
ftes / _error_messages.html.haml
Last active April 27, 2022 20:42
Rails bulma form builder with errors
-# layouts/_error_messages.html.haml
- if f.object.errors.any?
.notification.is-danger Please review the problems below:
- if f.object.errors[:base].present?
.notification.is-danger= f.object.errors[:base].join(', ')
@ftes
ftes / _form.html.haml
Last active August 12, 2021 01:24
simple_form initializer for Bulma (input, select, checkbox)
-# Example form
= simple_form_for @some_model do |f|
-# Show error notification at top (general error text)
= f.error_notification
-# Show base errors at top
= f.error_notification message: (f.error :base) if f.object.errors[:base].present?
-# Regular input
= f.input :name, autofocus: true
-# Select input referencing other model
@ftes
ftes / guitar-chords.csv
Last active September 11, 2019 19:17
Guitar chords as CSV with fingering notation for Latex songs package http://songs.sourceforge.net/songsdoc/songs.html#mac.gtab
We can make this file beautiful and searchable if this error is corrected: It looks like row 5 should actually have 13 columns, instead of 8 in line 4.
base_human , base_tex, maj , sus2 , sus4 , 6 , 7 , 7sus4 , 9 , m , m6 , m7 , m9
C , C , X32010:032010, (335533):113411, X330(11):034011, X3221X:043210, X3231X:032410, X3331X:023410, X3233X:021340, X3554X:013420, X312XX:031200, X(35343):013121, X3133X:021340
C\shrp / D\flt, D& , XXX121:000132, 4:(113311):113411, 4:(113341):112341, X4332X:043210, X4342X:032410, XX0213:000213, X4344X:021340, X421XX:042100, X423XX:031200, X4(242)X:031410, X4244X:021340
D , D , XX0232:000132, 000230:000130, X00233:000134, XX0202:000102, XX0212:000213, XX0213:000213, XX0210:000210, XX0231:000231, XX0201:000201, XX02(11):000211, 5:000120:000120
D\shrp / E\flt, E& , XXX343:000132, 6:(113311):113411, 6:(113341):112341, XX101X:001020, XXX323:000213, XXX324
@ftes
ftes / gist:d17d7e0d543028cb36e37fee16a53da1
Created March 13, 2019 09:22
Convert confluence to adoc
Steps:
1. `npm run start ../html ../md` (https://www.npmjs.com/package/confluence-to-markdown)
2. `for f in *.md; do pandoc "$f" -s -t asciidoc -o "${f%.md}.adoc"; done`
3. Manual cleanup (tables, images)