Skip to content

Instantly share code, notes, and snippets.

View kidpollo's full-sized avatar
💁‍♂️
Potato farming

Paco Viramontes kidpollo

💁‍♂️
Potato farming
  • San Francisco, CA
View GitHub Profile
;;;; francisco.clj
(ns francisco
(require [francisco.pacemaker :as pacemaker]))
(atom current-state-of-being
{:alive true
:body-parts {:heart {:current-heart-rate (rand-int 100)}}})
(while (:alive current-state-of-being)
; ...
@kidpollo
kidpollo / gist:721ee1f8cc70a487a062
Created July 7, 2014 23:03
Brew cask install error
brew install -v brew-cask 2>&1
Error: wrong number of arguments (0 for 1..3)
Please report this bug:
https://github.com/Homebrew/homebrew/wiki/troubleshooting
/usr/local/Library/Homebrew/build_environment.rb:28:in `instance_eval'
/usr/local/Library/Homebrew/build_environment.rb:28:in `modify_build_environment'
/usr/local/Library/Homebrew/requirement.rb:55:in `modify_build_environment'
/usr/local/Library/Homebrew/dependency.rb:54:in `call'
/usr/local/Library/Homebrew/dependency.rb:54:in `modify_build_environment'
/usr/local/Library/Homebrew/build.rb:132:in `each'
@kidpollo
kidpollo / app-server.clj
Created March 29, 2014 06:37
Example compojure app using stuartsierra/component
(ns app.api-server
(:require [compojure.core :as compojure]
[com.stuartsierra.component :as component]
[app.app :as app]
[ring.adapter.jetty :as jetty]))
(compojure/defroutes app
app/handler)
(defrecord AppServer [port server]
class PostCallbacks
def after_create
MagicBus::PostStream.new(self, 'create').enqueue
end
def after_update
MagicBus::PostStream.new(self, 'update').enqueue
end
def after_destroy
module V1
class BaseController < ApplicationController
include V1::ResponseMetaData
include V1::ErrorHandling
include V1::ReadOnly
include Pundit
rescue_from Pundit::NotAuthorizedError, with: :render_401
rescue_from ActiveRecord::RecordInvalid, :with => :render_422
def warden
class V1::PostController < V1::BaseController
def create
@post = Post.new(params[:post])
@post.authorize
@post.save
end
end
@kidpollo
kidpollo / gist:5287007
Created April 1, 2013 19:17
Punditry on scopes

Pundit has a helper method policy_scope that can be used in controllers and views that basicaly a class finder. It is equivalent to:

@posts = policy_scope(Post)
@posts = PostPolicy::Scope.new(current_user, Post).resolve

Using the helper is a nice approach because you dont have to remember what Scope class you need. This is all fine and well on a world where the app is single teanant or the auth logic to reslove scopes needs no other context but the user and the resource that is being requested.

In our world almost all requests are nested under a company context and require a current user to determine membership role to present certain data.

@kidpollo
kidpollo / gist:5046966
Created February 27, 2013 10:29
is_admin
class Post
validate :is_admin
def is_admin
errors.add(:base, 'cant post') if user.admin?
end
end
class Post < ActiveRecord::Base
after_save PostCallbacks.new
end
class PostCallbacks
def after_save(post)
Rails.queue.push(PostNotification.new(post_id,'save'))
end
end
ActiveSupport::Notifications.subscribe do |name, start, finish, id, payload|
Rails.logger.debug(["notification:", name, start, finish, id, payload].join(" "))
end