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
@kidpollo
kidpollo / local.cljs
Last active March 2, 2023 00:52
nbb + ruuter + axios node proxy
(ns local
{:clj-kondo/config '{:lint-as {promesa.core/let clojure.core/let
applied-science.js-interop/fn clojure.core/fn
applied-science.js-interop/defn clojure.core/defn}}}
(:require [cljs-bean.core :refer [->clj ->js]]
[promesa.core :as p]
["http" :as http]
["url"]
[applied-science.js-interop :as j]
[clojure.string :as string]
@kidpollo
kidpollo / proxy.cljs
Last active February 24, 2023 02:05
NBB + Ruuter + Axios Lambda API proxy
(ns foo
{:clj-kondo/config '{:lint-as {promesa.core/let clojure.core/let
applied-science.js-interop/defn clojure.core/defn}}}
(:require [cljs-bean.core :refer [->clj ->js]]
[ruuter.core :as ruuter]
["axios$default" :as axios]
[clojure.string :as string]
[promesa.core :as p]
[applied-science.js-interop :as j]))
@kidpollo
kidpollo / bootstrap.sh
Last active July 11, 2022 02:44
osx bootstrap
# Install iterm 2 https://www.iterm2.com/
# Install 1password
#install homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/paks/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
# packages
brew install git git-crypt gpg autojump kube-ps1 stern asdf rlwrap rg
@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]
@kidpollo
kidpollo / nginx.conf
Created April 8, 2017 08:18
Simple nginx ssl proxy configiration for local development
# do https://gist.github.com/jed/6147872 and then do this to proxy your app
worker_processes 1;
events {
worker_connections 1024;
}
http {
server {
listen 80;
require 'mail'
require 'thread'
require 'parallel'
require 'benchmark'
Mail.defaults do
delivery_method :smtp, options
end
@kidpollo
kidpollo / keybase.md
Created September 23, 2016 06:10
Keybase proof

Keybase proof

I hereby claim:

  • I am kidpollo on github.
  • I am kidpollo (https://keybase.io/kidpollo) on keybase.
  • I have a public key ASD3Rhho5U14SMrLQ9gNilg9-YssXS9hiovYVCkqFw3aFwo

To claim this, I am signing this object:

@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.

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