Skip to content

Instantly share code, notes, and snippets.

@dhoss
dhoss / application.conf
Last active August 29, 2015 14:21
play-slick app config
slick.dbs.default.driver="slick.driver.PostgresDriver$"
@dhoss
dhoss / build.sbt
Created May 15, 2015 20:57
play 2.4 + play-slick 1.0/slick 3.0 build.sbt and plugins.sbt example
name := """steel"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.11.5"
resolvers ++= Seq(
"Typesafe repository" at "https://repo.typesafe.com/typesafe/releases/",
"Typesafe Maven Repository" at "http://repo.typesafe.com/typesafe/maven-releases/",
# Scenario:
# We run a youtube production company and we make videos for paying members.
# Paying members can likewise access paid for premium content, and guests can access free content.
# Pretty straight forward.
#
# Next Scenario:
# We decide, one day, to open source all of our content. All videos, text posts, tutorials, etc
# are now available to *all* users.
#
# What's the most optimal way to be able to ship such a feature, with all tests passing.
@dhoss
dhoss / results.html.erb
Last active August 29, 2015 14:15
fluorescent view
<% if params[:q] %>
<% if @results.formatter.formatted_results.any? %>
<div class="search-results">
<% @results.formatter.formatted_results.each do |r| %>
<div class="blog-post">
<div><%= link_to r[:title].html_safe, post_path(r[:id]) %></div>
<div class="blog-post-meta">
by <%= link_to User.find(r[:user_id]).name, user_path(r[:user_id]) %>
on <%= r[:published_on] %>
</div>
@dhoss
dhoss / search_controller.rb
Last active August 29, 2015 14:15
fluorescent search controller
class SearchController < ApplicationController
def index
@results = []
if params[:q]
@results = Post.search(params.to_h)
respond_to do |format|
format.html { render action: "index" }
format.json { render json: @results }
end
end
@dhoss
dhoss / search.rb
Last active August 29, 2015 14:15
fluorescent search
class Post < ActiveRecord::Base
include PgSearch
include Search
# ...
scope :with_author, -> { eager_load(:user) }
@dhoss
dhoss / results.rb
Last active August 29, 2015 14:15
fluorescent results
require 'fluorescent'
require 'pp'
module Search
class Result
attr_reader :formatter, :raw
def initialize args
@formatter = Fluorescent.new(args)
@raw = args[:results]
end
end
@dhoss
dhoss / result.rb
Last active August 29, 2015 14:15
fluorescent search examples
require 'fluorescent'
module Search
class Result
attr_reader :formatter, :raw
def initialize args
@formatter = Fluorescent.new(args)
@raw = args[:results]
end
end
end
@dhoss
dhoss / instance.txt
Created January 21, 2015 20:20
library + instance app structure
src/
github.com/golang/example/
.git/ # Git repository metadata
stringutil/
reverse.go # package source
reverse_test.go # test source
app/
main.go
@dhoss
dhoss / app.txt
Created January 21, 2015 19:58
basic golang app structure
bin/
hello # command executable
outyet # command executable
pkg/
linux_amd64/
github.com/golang/example/
stringutil.a # package object
src/
github.com/golang/example/
.git/ # Git repository metadata