Skip to content

Instantly share code, notes, and snippets.

View tylerhunt's full-sized avatar

Tyler Hunt tylerhunt

View GitHub Profile
@aflatter
aflatter / password.rb
Created March 12, 2015 14:37
SCrypt::Password attribute type for Virtus
require 'scrypt'
module Virtus
class Attribute
class Password < ::Virtus::Attribute
primitive SCrypt::Password
def coerce(value)
value ? SCrypt::Password.new(value) : nil
rescue SCrypt::Errors::InvalidHash
@jasonvanlue
jasonvanlue / newYorkGuide.md
Last active April 12, 2019 17:42
New York Guide

A Guide to New York City

Areas

  • Upper West Side — North of 59th Street, bordered by the Hudson on the west and Central Park on the east. Mostly residential, with some museums and a good portion of the city's top high-end restaurants.
  • Upper East Side - North of 59th Street, bordered by Central Park on the west and the East River. Ultra high-end residential, high-end boutiques, The Metropolitan Museum of Art, and some decent restaurants.
  • Midtown — Essentially the area between 59th Street and 34th Street. Tons of things to do, places to eat, and most of the tourist traps are also here. Solid place to stay because you can get to/from anywhere from here.
  • Hells Kitchen - Basically "East Midtown", the area east of 8th Avenue. Mostly residential, though there are some decent restaurants and bars in this area.
  • Chelsea — East of the Avenue of the Americas between 34th St and 14th St. Really swanky area, lots of outstanding restaurants, bars, nighlife, and residential.
@chris-zwickilton
chris-zwickilton / gist:6625578
Last active December 23, 2015 10:59
A flavor of Hexagonal Rails with factory created use cases
class UsersController < ApplicationController
def create
create_user = UserUseCaseFactory.create_user(Responder.new(self)
create_user.do(params[:email], params[:password[)
end
class Responder < SimpleDelegator
def success(user)
render json: UserSerializer.new(user)
@skwp
skwp / watch_listing.rb
Last active December 15, 2015 18:09
Hexagonal extraction of a controller action from reverb.com, showing reuse between controller and Grape/Roar based API. This is sample code stripped down to the essentials and is not guaranteed to work as-is :)
class Reverb::Actions::WatchListing
def self.watch(user, product, listener)
if product.owner?(user)
listener.failure(I18n.t('flash.watchlist.error_own'))
else
Reverb::Analytics.track(user, :watch_product) # FIXME, this doesn't belong here
user.user_watch_products.create(:product_id => product.id)
listener.success
end
end
@krisleech
krisleech / 01-trips_controller.rb
Created February 13, 2013 22:35
Using focused_controller to provide service object with hooks for callbacks
class TripsController < ApplicationController
class Action < ApplicationController::Action
end
class New < Action
expose(:trip) { Trip.new(params[:trip]) }
end
class Create < New
def call
@geeksam
geeksam / gist:3875462
Created October 11, 2012 21:02
Roles in Ruby
class Role < Module
IncompleteInterface = Class.new(RuntimeError)
def included(receiver)
missing_methods = @public_api.map(&:to_sym) - receiver.public_instance_methods.map(&:to_sym)
unless missing_methods.empty?
raise IncompleteInterface,
"#{receiver} must implement these methods: #{missing_methods.inspect}"
end
@steveklabnik
steveklabnik / _comment.html.erb
Created October 9, 2012 06:05
Presenters in Rails?
<article>
<header>
<h3><%= comment.author %></h3>
</header>
<%= comment.body %>
</article>
@nickawalsh
nickawalsh / gist:2923581
Created June 13, 2012 11:41
Pseudo Caret
/* Sample usage: +caret(bottom, 8px, #000); */
=caret($side, $size, $color)
$opposite: opposite-position($side)
+stretch(50%,auto,auto,50%)
border: $size solid transparent
border-#{$opposite}: $size solid $color
border-#{$side}: 0
content: ''
display: block
@mbleigh
mbleigh / gist:1081663
Created July 14, 2011 00:58
Notes from converting my AppleTV into a media server and NAS.

AppleTV as Headless Media NAS

I don't use my AppleTV and I've had a 500GB external HD sitting around that isn't really getting use either. I thought I'd make use of both of these things and see if I could turn my AppleTV into a NAS device that would also allow for BitTorrent downloading and act as a transcoding DLNA MediaServer that I could access from my Xbox 360 and/or PS3.

Feature List

@twbell
twbell / factual_local_mappings.json
Created June 29, 2011 21:56
Provides a machine-readable mapping between Factual's Global Local Schema and country-specific attributes, denotes which attributes are supported within a specific country, and provides a country-to-table lookup
{
"countries": {
"ar": {
"country": "Argentina",
"table": "PfldJg",
"attributes": {
"factual_id": {
"supported": true,
"mapping": "Factual ID"
},