Skip to content

Instantly share code, notes, and snippets.

View Archimidis's full-sized avatar

Nikolas Vourlakis Archimidis

View GitHub Profile
class ApplicationController < ActionController::Base
...
# FORCE to implement content_for in controller
def view_context
super.tap do |view|
(@_content_for || {}).each do |name,content|
view.content_for name, content
end
end
end
@Archimidis
Archimidis / application_controller.rb
Created July 29, 2013 14:05 — forked from gonzedge/application_controller.rb
Custom dynamic 404 and 500 pages
class ApplicationController < ActionController::Base
# ...
unless Rails.application.config.consider_all_requests_local
rescue_from Exception, with: lambda { |exception| render_error 500, exception }
rescue_from ActionController::RoutingError, ActionController::UnknownController, ::AbstractController::ActionNotFound, ActiveRecord::RecordNotFound, with: lambda { |exception| render_error 404, exception }
end
private
def render_error(status, exception)
@Archimidis
Archimidis / in_model.rb
Last active December 24, 2015 11:29
Paperclip wrong attachment url on validation errors: http://stackoverflow.com/a/5995636/2425581
class ModelName
# declare papaerclip :avatar file
# ...
after_validation :avatar_reverted?
def avatar_reverted?
unless self.errors[:avatar_file_size].blank? or self.errors[:avatar_content_type].blank?
self.avatar.instance_write(:file_name, self.avatar_file_name_was)
self.avatar.instance_write(:file_size, self.avatar_file_size_was)
self.avatar.instance_write(:content_type, self.avatar_content_type_was)
@Archimidis
Archimidis / remote_rake_recipe.rb
Created November 6, 2013 10:26
Capistrano recipe for remote rake invocation.
namespace :remote_rake do
desc 'Run a task on a remote server.'
# run like: cap remote_rake:invoke task="db:reset"
task :invoke do
run("cd #{deploy_to}/current && bundle exec rake #{ENV['task']} RAILS_ENV=#{rails_env}")
end
end
@Archimidis
Archimidis / async_load_share_buttons.html
Created January 10, 2014 12:02
Load third party scripts async, after onload
<script>
(function(w, d, s) {
function go(){
var js, fjs = d.getElementsByTagName(s)[0], load = function(url, id) {
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.src = url; js.id = id;
fjs.parentNode.insertBefore(js, fjs);
};
load('//connect.facebook.net/en_US/all.js#appId=272697932759946&xfbml=1', 'fbjssdk');
load('https://apis.google.com/js/plusone.js', 'gplus1js');
@Archimidis
Archimidis / new_invitation.html.erb
Created January 19, 2014 02:33 — forked from mikeatlas/new_invitation.html.erb
Rails: Invitations with devise_invitable
<!-- /app/views/admin/users/new_invitiations.html.erb -->
<h2>Send invitation</h2>
<%= form_for @user, :url => send_invitation_admin_users_path do |f| %>
<table style='width: 50%'>
<tr>
<td><%= f.label :first_name %></td>
<td><%= f.text_field :first_name %></td>
@Archimidis
Archimidis / 0_reuse_code.js
Created January 27, 2014 08:42
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@Archimidis
Archimidis / cached_repository_through_proxy.js
Last active April 26, 2016 23:08
Exploring an idea on how to use javascript proxies. The aim is to add caching behaviour to an object that performs queries to a database. In order to run the example Proxy and Reflect must be defined. This is tested on nodejs v6.0.0.
'use strict';
function createPersonRepository() {
const persons = [{
id: 1,
name: 'Archimedes'
}, {
id: 2,
name: 'Plato'
}, {
@Archimidis
Archimidis / gist:13bd1b5c54cb342ad075
Created March 10, 2016 09:55 — forked from skroah/gist:9c22697521626c7b388b
Reactive Systems Design

##Reactive System Design Links

#Articles and Papers