Skip to content

Instantly share code, notes, and snippets.

@aglassman
aglassman / todo_golf.exs
Last active June 21, 2023 15:56
Elixir Todo Golf
Enum.reduce(Stream.cycle(0..1), [], &(IO.inspect(case String.trim(IO.binread(:line)) do
"l" <> _ -> &1; &2
"a " <> i -> [{i, nil} | &2]
"c " <> i -> Enum.map(&2, fn {^i, _} -> {i, true }; x -> x end)
"x " <> i -> Enum.reject(&2, fn {^i, _} -> true; _ -> false end)
_ -> raise "e"
end)))
defmodule Todo do
import String, only: [split: 3, trim: 1];
@t :todos
@d :dets
def prompt() do IO.write("todo> "); split(trim(IO.binread(:line)), " ", parts: 2) end
def run(:start) do @d.open_file(@t, type: :set); run(">") end
def run(:goodbye), do: @d.close(@t)
def run(_) do
case prompt() do
[c] when c in ["", "ls"] -> @d.match_object(@t, {:"$1", false})
@aglassman
aglassman / async_assigns.ex
Last active July 23, 2023 12:36
LiveView - Async Assigns Helper
defmodule AsyncAssigns do
import Phoenix.LiveView, only: [connected?: 1, assign: 2, assign: 3]
@doc """
Provides ability to assign default values to the socket, and kick off a
process that will send a message to the LiveView. The message payload will
be assigned as specified.
## Usage
Add the following lines to a specific LiveView, or to the web module
weed = {
position={0,0},
new=function(self, position)
local new_weed = {position=position}
setmetatable(new_weed, self)
return new_weed
end,
draw=function(self)

Keybase proof

I hereby claim:

To claim this, I am signing this object:

@aglassman
aglassman / elvis_test.exs
Created October 19, 2021 14:57
Elvis Test
defmodule ElvisTest do
use ExUnit.Case
def a ~> b, do: elvis(a, b)
def elvis(nil, fun), do: nil
def elvis({nil, default_val}, fun), do: elvis(default_val, fun)
def elvis(val, fun), do: fun.(val)
Attaching to process ID 419, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.121-b13
Deadlock Detection:
No deadlocks found.
Thread 2387: (state = BLOCKED)
- sun.misc.Unsafe.park(boolean, long) @bci=0 (Compiled frame; information may be imprecise)
@aglassman
aglassman / Application.java
Created July 19, 2016 19:19
Spring Cloud - Zuul - On Servlet 2.5
package com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Import;
@EnableCircuitBreaker
package com.example;
import org.h2.server.web.WebServlet;
import org.springframework.boot.context.embedded.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class ServiceConfiguration {
@Bean
rg.springframework.http.converter.HttpMessageNotReadableException: Could not read document: Can not instantiate value of type [simple type, class org.gmjm.logistics.domain.Hub] from String value ('http://localhost:8080/hubs/1044'); no single-String constructor/factory method
at [Source: HttpInputOverHTTP@207155db; line: 2, column: 30] (through reference chain: org.gmjm.logistics.domain.Route["originHub"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not instantiate value of type [simple type, class org.gmjm.logistics.domain.Hub] from String value ('http://localhost:8080/hubs/1044'); no single-String constructor/factory method
at [Source: HttpInputOverHTTP@207155db; line: 2, column: 30] (through reference chain: org.gmjm.logistics.domain.Route["originHub"])
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:224) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.http.conver