Skip to content

Instantly share code, notes, and snippets.

View abitdodgy's full-sized avatar
😃
Out to lunch!

Mohamad El-Husseini abitdodgy

😃
Out to lunch!
View GitHub Profile
@staltz
staltz / introrx.md
Last active May 20, 2024 14:59
The introduction to Reactive Programming you've been missing
protocol ArrayRepresentable {
typealias ArrayType
func toArray() -> ArrayType[]
}
extension Range : ArrayRepresentable {
func toArray() -> T[] {
return T[](self)
}
@stevenyap
stevenyap / Heroku_Staging.md
Last active June 11, 2019 16:09
Staging workflow on Heroku

This describes the workflow to use Heroku as a staging environment. It assumes you already have an existing heroku app in production.

# rename your git remote heroku to something else like production
git remote rename heroku production

# so now you will push as: git push production master

# create the staging app
heroku apps:create staging-appname
$.rails.allowAction = function(link) {
if (!link.attr('data-confirm')) {
return true;
}
$.rails.showConfirmDialog(link);
return false;
};
$.rails.confirmed = function(link) {
link.removeAttr('data-confirm');
# config/routes.rb
resources :documents do
scope module: 'documents' do
resources :versions do
post :restore, on: :member
end
resource :lock
end
end
class GroupersController < ApplicationController::Base
def create
@grouper = Grouper.new(leader: current_member)
if @grouper.save
confirm_grouper_via_emails(@grouper)
enqueue_bar_assignment(@grouper)
redirect_to home_path
else
# Elixir v1.0
defmodule Rules do
defmacro __using__(_) do
quote do
import unquote(__MODULE__)
@before_compile unquote(__MODULE__)
@rules []
end
end
@seyhunak
seyhunak / bootstrap-confirmation.js
Created June 28, 2013 09:08
Twitter Bootstrap Confirmation Dialog Modal - Rails UJS
$.rails.allowAction = function(link) {
if (!link.attr('data-confirm')) {
return true;
}
$.rails.showConfirmDialog(link);
return false;
};
$.rails.confirmed = function(link) {
link.removeAttr('data-confirm');
@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.