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
@abitdodgy
abitdodgy / authable.rb
Created January 30, 2016 13:22
API on Rails example with fake controller and concern.
module Authable
def current_user
@current_user ||= User.find_by(auth_token: request.headers['Authorization'])
end
def authenticate_with_token!
render json: { errors: "Not authenticated" }, status: :unauthorized unless current_user.present?
end
end
@abitdodgy
abitdodgy / authable_test.rb
Created January 30, 2016 12:25
A MiniTest version of API on Rails Chapter 5, listing 5.11
require 'test_helper'
class DummyController < ApplicationController
include Authable
end
class AuthableTest < ActionController::TestCase
setup do
include_default_request_headers
@dummy = DummyController.new
def alert_tag(options, &block)
content_tag :div, options do
yield
end
end
class UpdateDocument
def self.call_on_collection(documents, attributes)
Document.transaction do
documents.map { |document| new(document) }.each { |service| service.call_without_job(attributes) }
end.each(&:queue_job)
end
attr_reader :document
def initialize(document)
1_0_0_1_
'{ "1": 0, "2": 1, "3": 0, "4": 0 }'
{ "1" => 0, "2" => 1, "3" => 0, "4" => 0, }.hash
WorkspaceTypes:
id: [Int]
name: [String]
@doc ~s"""
Takes a string and an atom that refers to any function name in `Gibran.Counter`.
It tokenises the string, then applies the given function to the resulting tokens. The function
name must be an `atom`. You can pass a list of options to the tokeniser as `opts` and a list
of options to the receiving function as `fn_opts`.
For example, the following two calls are equivalent:
Gibran.from_string("The Prophet", :token_count)
@abitdodgy
abitdodgy / Heroku_Staging.md
Last active August 29, 2015 14:27 — forked from stevenyap/Heroku_Staging.md
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
- provide :title, ts(:title)
- page_header :projects
= form_for [@workspace, @project, Upload.new], html: { class: 'form-horizontal' } do |f|
div class="panel panel-default panel-upload"
/ div class="panel-heading"
div class="panel-title" Upload Files
/ div class="panel-body text-center"
@abitdodgy
abitdodgy / documents.rb
Last active August 29, 2015 14:23 — forked from dhh/documents.rb
# config/routes.rb
resources :documents do
scope module: 'documents' do
resources :versions do
post :restore, on: :member
end
resource :lock
end
end
@abitdodgy
abitdodgy / turbolinks_example.js
Created April 18, 2015 15:19
Turbolinks example. Binding on document.ready and page:change.