Skip to content

Instantly share code, notes, and snippets.

@mcrumm
mcrumm / app.js
Last active March 4, 2025 13:07
flatpickr + LiveView example
// assets/js/app.js
// ...
import Pickr from "./pickr"
const hooks = {
Pickr
}
// ...
@jxxe
jxxe / Cache.php
Last active September 25, 2024 20:51
A quick and dirty PHP class to cache JSON data
<?php
const MONTH = "Y-m"; // 2000-01
const DAY = "Y-m-d"; // 2000-01-01
const HALF_DAY = "Y-m-d-A"; // 2000-01-01-AM
const HOUR = "Y-m-d-H"; // 2000-01-01-24
const MINUTE = "Y-m-d-H-i"; // 2000-01-01-24-60
class Cache {
@wosephjeber
wosephjeber / instructions.md
Last active October 16, 2025 17:50
Ecto migration for renaming table with indexes and constraints

Renaming table in Ecto migration

I recently wanted to rename a model and its postgres table in a Phoenix app. Renaming the table was simple and documented, but the table also had constraints, sequences, and indexes that needed to be updated in order for the Ecto model to be able to rely on default naming conventions. I couldn't find any examples of what this would look like but was eventually able to figure it out. For anyone else in the same situation, hopefully this example helps.

In the example below, I'm renaming the Permission model to Membership. This model belongs to a User and an Account, so it has foreign key constraints that need to be renamed.

defmodule MyApp.Repo.Migrations.RenamePermissionsToMemberships do
  use Ecto.Migration
@joshnuss
joshnuss / udp_server.exs
Last active February 5, 2026 18:03
Fault tolerant UDP Server in Elixir
# to run:
# > elixir --no-halt udp_server.exs
# to test:
# > echo "hello world" | nc -u -w0 localhost 2052
# > echo "quit" | nc -u -w0 localhost 2052
# Let's call our module "UDPServer"
defmodule UDPServer do
# Our module is going to use the DSL (Domain Specific Language) for Gen(eric) Servers
use GenServer
@davoclavo
davoclavo / up-and-running-with-edeliver-on-do.md
Last active June 6, 2022 11:55 — forked from mattweldon/up-and-running-with-edeliver-on-do.md
Getting Elixir / Phoenix running on Digital Ocean with edeliver

Build Server

  • Go to Digital Ocean
  • Create new ubuntu droplet

Setup Server

@daggerhart
daggerhart / simple-template-class.php
Last active September 28, 2024 20:26
A simple PHP template class.
<?php
/**
* Class Template - a very simple PHP class for rendering PHP templates
*/
class Template {
/**
* Location of expected template
*
@matiaskorhonen
matiaskorhonen / sign-pdf.rb
Last active March 21, 2025 02:34
Quick and dirty PDF signing in Ruby (using Origami)
#!/usr/bin/env ruby
require "openssl"
require "time"
begin
require "origami"
rescue LoadError
abort "origami not installed: gem install origami"
end
@Rodrigo54
Rodrigo54 / php-html-css-js-minifier.php
Last active February 18, 2026 09:38 — forked from taufik-nurrohman/php-html-css-js-minifier.php
PHP Function to Minify HTML, CSS and JavaScript
<?php
/**
* -----------------------------------------------------------------------------------------
* Based on `https://github.com/mecha-cms/mecha-cms/blob/master/system/kernel/converter.php`
* -----------------------------------------------------------------------------------------
*/
// HTML Minifier
function minify_html($input) {
@sdieunidou
sdieunidou / rabbitmq.txt
Created October 22, 2015 19:51
create admin user on rabbitmq
rabbitmqctl add_user test test
rabbitmqctl set_user_tags test administrator
rabbitmqctl set_permissions -p / test ".*" ".*" ".*"
@mattweldon
mattweldon / up-and-running-with-edeliver-on-do.md
Last active September 3, 2021 16:48
Getting Elixir / Phoenix running on Digital Ocean with edeliver

Build Server

  • Go to Digital Ocean
  • Create new droplet
  • London
  • Ubuntu
  • No apps
  • Add SSH keys