Skip to content

Instantly share code, notes, and snippets.

View ulfurinn's full-sized avatar

Valeri Sokolov ulfurinn

View GitHub Profile
@ulfurinn
ulfurinn / README.md
Last active September 23, 2023 20:42
IntoArray

An Elixir implementation of the output iterator/IntoIterator idiom over Collectable and Arrays.

@ulfurinn
ulfurinn / gist:45d94d8bcc99e0a10025
Created July 1, 2014 14:24
http over unix socket
// A quick and dirty demo of talking HTTP over Unix domain sockets
package main
import (
"fmt"
"io"
"net"
"net/http"
"os"
@ulfurinn
ulfurinn / README.md
Last active March 24, 2023 21:57
Phoenix PubSub over AMQP

A simple PubSub adapter that sends messages between nodes over AMQP.

The app supervisor needs to be configured with:

{Phoenix.PubSub, name: App.PubSub, adapter: Phoenix.PubSub.AMQP, amqp: [connection: amqp_connection_id]},
@ulfurinn
ulfurinn / README.md
Created March 22, 2023 18:10
Locale extraction from URL in Phoenix

This is a quick stab at a problem that the set_locale package is supposed to solve but seems to be broken and unsupported, or at least that's what its issue list indicates.

We want to extract the locale from the path prefix; i.e. "/en/users" and "/sv/users" should correctly set the current Gettext locale for the request. "/users" should keep the default locale.

We're not considering cookies or Accept-Language in this scope. We also don't do redirecting; the unlocalized path will hit the action as usual.

Using this solution requires two changes to the router:

  1. Paths that should be localized need to be wrapped in a localized/2 macro. It simply repeats its content with and without a scope /:locale so that both versions are visible to the route inspector and play nicely with verified routes.
  2. The browser pipeline needs to include a plug that extracts the param and sets the current Gettext locale. It also creates an assign for convenience.

Keybase proof

I hereby claim:

  • I am ulfurinn on github.
  • I am ulfurinn (https://keybase.io/ulfurinn) on keybase.
  • I have a public key ASAnUU569hnVj7NyM68L19fWt4pJlJzpPnUoOqyHnisfzwo

To claim this, I am signing this object:

@ulfurinn
ulfurinn / amqp_rpc.rb
Created October 11, 2012 08:55
RPC with AMQP
require "amqp"
require "fiber"
module AMQP_RPC
module Client
def subscribe
response_queue.subscribe do |header, body|
id = header.correlation_id
@ulfurinn
ulfurinn / my-project-generator.rb
Created June 19, 2013 08:33
deploying with hooks and amqp
#!/usr/bin/env ruby
require "dante"
require "amqp"
require "oj"
$0 = "My project generator"
Dir.chdir "/var/www/my-project"
Dante.run "my-project", pid_path: '/var/www/my-project-generator.pid', user: 'www-data', group: 'www-data' do
@ulfurinn
ulfurinn / thin.sh
Created August 24, 2012 09:37
thin init.d script supporting individual servers
#!/bin/bash
### BEGIN INIT INFO
# Provides: thin
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: thin initscript
# Description: thin
### END INIT INFO