Skip to content

Instantly share code, notes, and snippets.

@d0rc
d0rc / embeddings-test.py
Created December 22, 2023 16:48
embedding space
import torch
from torch import nn
from tqdm import tqdm
import pandas as pd
from torch.utils.data import Dataset, DataLoader
import torch.nn.functional as F
device = 'cpu'
# Custom Dataset
mvn install -DskipTests=true -Dgpg.skip=true
@d0rc
d0rc / options_generator.ex
Created June 22, 2014 22:53
options_generator.ex
defmodule Options do
@proto_version "1.0"
def process_options(opts) do
log_opt ++
Enum.map(opts, fn
{:in, true} -> ["-in"]
{:err, :out} -> ["-err", "out"]
{:err, :err} -> ["-err", "err"]
{:dir, dir} -> ["-dir", dir]
@d0rc
d0rc / piper.ex
Created May 7, 2014 09:07
pipes pipes pipes
defmodule PipesX do
defmacro pipe_with(fun, pipes) do
IO.puts "Will reduce over: #{inspect Macro.unpipe(pipes)}"
Enum.reduce Macro.unpipe(pipes), &(reduce_with &1, &2, fun)
end
defp reduce_with( {segment, pos}, acc, outer ) do
IO.puts "reduce_with: Got #{inspect segment} at #{inspect pos}"
quote do
inner = fn(x) ->
@d0rc
d0rc / laxer.ex
Created April 24, 2014 12:13
ListDict is dead, long live the ListDict (deflamodule)
defmodule LAXer do
defmodule Transformer do
def exec({ {:., _, [Kernel, :access]} , _, [subj, [key]]}) do
quote do
LAXer.getter(unquote(exec(subj)), unquote(exec(key)))
end
end
def exec({ op, misc, args }) when is_list(args) do
{op, misc, (for arg <- args, do: exec(arg))}
end
@d0rc
d0rc / lax.ex
Created April 24, 2014 02:33
ListDict is dead, long live the ListDict
defmodule LAX do
defmodule Transformer do
def exec({ {:., _, [Kernel, :access]} , misc, [subj, [key]]}) do
quote do
LAX.getter(unquote(exec(subj)), unquote(exec(key)))
end
end
def exec(code), do: code
end
lc cid inlist([398, 980, 810]) do
def list(unquote(cid)), do: unquote(@providers |> Enum.filter(fn
[id: _, name: _, currency: c_id, pattern: _, placeholder: _] when c_id = cid -> true;
_ -> false;
end))
end
@d0rc
d0rc / high_load_serial_requests.ex
Created March 6, 2014 00:35
steps to reproduce erl_prim_loader @100%
defrecord Test, [id: nil, what: nil]
spawn fn -> :etop.start [output: :text] end
case what_to_test do
:json -> Enum.each(1..1000_000, fn _ -> Test[id: 1] |> JSON.encode end)
:inspect -> Enum.each(1..1000_000, fn _ -> inspect Test[id: 1] end)
end
defmodule Parser do
@dict HashDict.new([{"foo", "bar"}, {"baz", "buzz"}])
defrecord :state, [in_match: false, escaping: false, key: ""]
def translate(string) do
translate(string, :state[])
end
defp translate("", _), do: ""
defp translate(<<"\\", rest:: binary>>, state) do
iex(2)> Test.test1
{1474377, :ok}
iex(3)> Test.test2
{755840, :ok}