Skip to content

Instantly share code, notes, and snippets.

@rtrppl
rtrppl / dired4attachments.el
Last active November 10, 2024 15:31
Use Dired to pick attachments for mu4e
(defvar attachment-folder "~/Desktop/")
(defvar compose-buffer nil)
(with-eval-after-load 'mu4e
(define-key mu4e-compose-mode-map (kbd "C-c C-a") 'lt/mml-attach-file))
(with-eval-after-load 'dired
(define-key dired-mode-map (kbd "E") 'lt/process-marked-files-as-attachments))
(defun lt/mml-attach-file ()
"Opens a Dired buffer to select attachments. The keybinding to send these back to the email draft is E."
@oplanre
oplanre / Sorter.php
Last active June 27, 2024 00:54
Light abstraction layer for sorting arrays in php
<?php
class Sorter {
public function __construct(private array $array) {}
/**
* Sort the array by a specific key in ascending or descending order.
*
* @param string $key The key to sort by.
* @param string $order The order direction, 'asc' for ascending or 'desc' for descending. Default is 'asc'.
* @return self
@ralphschindler
ralphschindler / use-ffi-to-write-to-file-via-low-level-standard-c-library-functions.php
Last active February 1, 2025 12:00
PHP Write to stdout via /proc/1/fd/1 using FFI (useful for logging inside a container)
<?php
// php can't write directly to a non-regular-file due to the php filesystem
// abstraction in place. But, we can use direct calls to the low level standard
// library to achieve this.
// normally, you should use the dio extension:
// - https://pecl.php.net/package/dio
// - https://github.com/php/pecl-system-dio/tree/master
@srcrip
srcrip / error_html.ex
Created February 15, 2024 19:42
Custom Phoenix error pages
# goes in lib/your_app_web/controllers/error_html.ex
defmodule ExampleWeb.ErrorHTML do
use ExampleWeb, :html
def render("404.html" = template, assigns) do
assigns =
assigns
|> Map.merge(%{__changed__: %{}})
|> assign(:message, Phoenix.Controller.status_message_from_template(template))
// code updates are now there:
// https://github.com/Bleuje/processing-animations-code/blob/main/code/fractalsliding2d/fractalsliding2d.pde
// Processing code by Etienne JACOB
// for collab with Yann Le Gall (https://demozoo.org/graphics/322553/)
// motion blur template by beesandbombs
// See the license information at the end of this file.
// View the rendered result at: https://bleuje.com/gifanimationsite/single/2dfractalslidingsquares/
// using double instead of float makes the code a bit more complicated
@caspg
caspg / 1_searchbar_live.ex
Last active February 23, 2025 13:52
Example of real-time search bar implementation in Phoenix LiveView and Tailwind. Working example on https://travelermap.net/parks/usa
defmodule TravelerWeb.SearchbarLive do
use TravelerWeb, :live_view
alias Phoenix.LiveView.JS
alias Traveler.Places
def mount(_params, _session, socket) do
socket = assign(socket, places: [])
{:ok, socket, layout: false}
end
@lgmoneda
lgmoneda / org-yank-link.el
Last active April 10, 2023 23:24
Copy Slack behavior of automatically creating link when pasting url with text selected
@joshnuss
joshnuss / streaming_http_requests.ex
Last active March 31, 2023 09:02
Streaming HTTP requests
defmodule MyApp.Integrations.Skubana do
@host "..."
@headers [ ... ]
# returns a stream of shipments
def get_shipments do
# start with page 1
start = fn -> 1 end
# create a stream, it will make HTTP requests until the page returned is empty
@GromNaN
GromNaN / RouterTest.php
Created December 15, 2021 20:43
Symfony Integration test for route configuration: controller does neither exist as service nor as class
<?php
namespace Tests\Integration;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\Routing\RouterInterface;
@lukaseder
lukaseder / postgis-mandelbrot.sql
Created November 14, 2021 10:03
PostGIS Mandelbrot
with recursive
dims (r1, r2, i1, i2, s, it, p) as (values (-2::float, 1::float, -1.5::float, 1.5::float, 0.01::float, 100, 256.0::float)),
sprites (s) as (values (st_makepolygon(st_geomfromtext('linestring (0 0, 0 1, 1 1, 1 0, 0 0)')))),
n1 (r, i) as (select r, i from dims, generate_series((r1 / s)::int, (r2 / s)::int) r, generate_series((i1 / s)::int, (i2 / s)::int) i),
n2 (r, i) as (select r::float * s::float, i::float * s::float from dims, n1),
l (cr, ci, zr, zi, g, it, p) as (
select r, i, 0::float, 0::float, 0, it, p from n2, dims
union all
select cr, ci, zr*zr - zi*zi + cr, 2 * zr * zi + ci, g + 1, it, p from l where g < it and zr*zr + zi*zi < p
),