Skip to content

Instantly share code, notes, and snippets.

View robacarp's full-sized avatar
🐢
Bacon//Pickle

Rob robacarp

🐢
Bacon//Pickle
View GitHub Profile
@robacarp
robacarp / aa_usage.md
Created April 3, 2024 17:10
Asset Renderer and Manifest Builder in Crystal

In config/assets.cr:

require "../src/lib/asset_renderer"
require "../src/lib/import_map"

AssetRenderer.configure do |c|
  c.source_path = Path.new("src")
  c.output_path = Path.new("public/h/")
 c.rendered_path = Path.new("/h/")
@robacarp
robacarp / fan-out-in.cr
Created May 7, 2023 02:11
Mosquito Fan-out-in example
class FanOutInJob < Mosquito::QueuedJob
params(
root : String,
fan_state : String = "starting",
parent_job_id : String = "",
branch : String = ""
)
def perform
case fan_state
export default class Builder {
static tag(name, text) {
const tag = document.createElement(name)
tag.textContent = text
return tag
}
static link(href, text) {
const link = Builder.tag("a", text)
link.href = href
@robacarp
robacarp / crystal_lucky.md
Created October 6, 2021 01:52
Crystal+Lucky on M1

Mac+M1+Crystal+Lucky

This is the series of steps I followed to get Crystal and Lucky running on a Mac M1 from scratch, as of Oct. 2021.

Prerequisites

  • Ensure ~/bin and /opt both exist.
  • /opt will have to be created with sudo but should be owned by your user.
  • Make sure your $PATH includes ~/bin. Doing so is up to you and will vary a bit depending on your shell.
@robacarp
robacarp / .gitignore.diff
Last active January 30, 2022 07:22
Lucky with Parcel Bundler
+public/_entrypoint.html
+public/*.js
+public/*.css
+public/*.map
FROM crystallang/crystal:0.27.2
WORKDIR /opt/src
# Install nodejs
COPY bin ./bin
RUN bin/nodesource_11.x
RUN apt-get update && apt-get install -y nodejs
# npm install
# src/actions/browser_action.cr
abstract class BrowserAction < Lucky::Action
include Lucky::ProtectFromForgery
include Auth::SessionManagement
include Auth::SessionEnforcement
require_logged_in!
expose current_user
module Auth::RedirectIfSignedIn
macro included
include Auth::SkipRequireSignIn
before redirect_if_signed_in
# Most notably, this is removed everywhere. All actions now depend on a current_user.
# unexpose current_user
end
# ...
@robacarp
robacarp / stdin.cr
Created August 2, 2018 21:37
crystal single character read from stdin
print "Type something: "
entered_chars = [] of Char
STDIN.raw do
loop do
char = STDIN.read_char
next if char.nil?
##########################
# CONFIG
##########################
# select and require the appropriate database driver here:
require "pg"
# require "sqlite"
# require "mysql"
TABLE_NAME = "schema_version"