Skip to content

Instantly share code, notes, and snippets.

View mitchellhenke's full-sized avatar

Mitchell Henke mitchellhenke

  • GSA (work) + Personal Projects
  • Milwaukee, WI
View GitHub Profile
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Padrino Admin</title>
<%= stylesheet_link_tag :base, "themes/default/style" %>
</head>
<body>
<div id="container">
<div id="box">
module Review
module Account
class ReviewImagesController < ApplicationController
def create
puts params
render :json => {:stuff=>params}.to_json
end
end
after_connect = proc do |connection|
connection.query("UPDATE items set text='testing' where id = 34;")
end
Sequel::Model.db = Sequel.connect(ENV['DATABASE_URL'], after_connect: after_connect)
defmodule User do
use Ecto.Model
schema "users" do
field :username, :string
end
end
defmodule Repo.Migrations.UserSearch do
use Ecto.Migration
def up do
execute "CREATE extension if not exists pg_trgm;"
execute "CREATE INDEX users_username_trgm_index ON users USING gin (username gin_trgm_ops);"
end
def down do
execute "DROP INDEX users_username_trgm_index;"
defmodule User do
use Ecto.Model
schema "users" do
field :username, :string
end
def search(query, search_term) do
from(u in query,
where: fragment("? % ?", u.username, ^search_term),
User |> User.search("mitch") |> Repo.all
# [debug] SELECT u0."id", u0."username" FROM "users" AS u0 WHERE (u0."name" % $1) ORDER BY similarity(u0."name", $2) DESC ["mitch", "mitch"] (1.9ms)
[%User{__meta__: %Ecto.Schema.Metadata{source: "users", state: :loaded},
username: "mitch"},
%User{__meta__: %Ecto.Schema.Metadata{source: "users", state: :loaded},
username: "mitch3"}]
defmodule User do
use Ecto.Model
schema "users" do
field :username, :string
end
def search(query, search_term, limit = 0.3) do
from(u in query,
where: fragment("similarity(?, ?) > ?", u.username, ^search_term, ^limit),
defmodule App.Mixfile do
use Mix.Project
def project do
[app: :app,
version: "0.0.1",
elixir: "~> 1.2",
elixirc_paths: elixirc_paths(Mix.env),
compilers: [:phoenix] ++ Mix.compilers,
build_embedded: Mix.env == :prod,
1) test node_name/1 returns the node name (Phoenix.PubSubTest)
deps/phoenix_pubsub/test/shared/pubsub_test.exs:68
** (MatchError) no match of right hand side value: []
stacktrace:
lib/phoenix/pubsub.ex:287: Phoenix.PubSub.call/3
deps/phoenix_pubsub/test/shared/pubsub_test.exs:69: (test)
Finished in 0.3 seconds