Skip to content

Instantly share code, notes, and snippets.

View Fire-Dragon-DoL's full-sized avatar

Francesco Belladonna Fire-Dragon-DoL

View GitHub Profile
@Fire-Dragon-DoL
Fire-Dragon-DoL / ProtectedMethod.cpp
Last active August 29, 2015 14:08
Ruby (2.1+) protected method weirdness. Fails with "NoMethodError", accessing protected method. See Ruby code in action: https://eval.in/209730 See Java code in action: http://ideone.com/2B3CEq See C# code in action: http://ideone.com/RJjn4f See C++ code in action: http://ideone.com/7Ihvw0 See Ruby alternative code in action: https://eval.in/209934
#include <iostream>
using namespace std;
class A;
class B;
class C;
class A
{
public:
@Fire-Dragon-DoL
Fire-Dragon-DoL / Why software estimates are complex
Created August 31, 2014 17:13
Why software estimates are complex (from HN)
Yet another place where intuitions derived from the normal distribution about the behavior of distributions screws people.
An explanation I like, from michaelochurch:
      Let's say that you have 20 tasks. Each involves rolling a 10-sided die.
   If it's a 1 through 8, wait that number of minutes. If it's a 9, wait 15
   minutes. If it's a 10, wait an hour.
      How long is this string of tasks going to take? Summing the median time
   expectancy, we get a sum 110 minutes, because the median time for a task is
   5.5 minutes. The actual expected time to completion is 222 minutes, with 5+
@Fire-Dragon-DoL
Fire-Dragon-DoL / application_controller.rb
Last active August 29, 2015 14:05
Token authentication for APIs using rails-api, interactor-rails, jsend-rails, cancancan, skipping Devise (only 2 functions used)
class ApplicationController < ActionController::API
include AbstractController::Translation
include ActionController::MimeResponds
include ActionController::ImplicitRender
include ActionController::StrongParameters
# Gems that tries to include something in ActionController::Base
include JSend::Rails::Controller
include CanCan::ControllerAdditions
@Fire-Dragon-DoL
Fire-Dragon-DoL / ability.rb
Created August 18, 2014 02:11
ActiveAdmin 1.0.0.pre user management page, simple setup with proper user handling for a website backoffice through CanCan, Devise and StrongParameters for Rails 4
class Ability
include CanCan::Ability
attr_reader :current_user
def initialize(user)
alias_action :create, :update, :destroy, :to => :write
@current_user = user || User.new
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: postgresql
encoding: utf8
database: nome_del_db
@Fire-Dragon-DoL
Fire-Dragon-DoL / Autohotkey.ahk
Created July 25, 2014 18:56
Cygwin inside ConsoleZ (ex Console2), use in Yakuake-like fashion and open new tab in specified path, useful with Sublime Text Terminal plugin
; This must be always running in background
OpenShellIfNotRunning()
{
Opening := False
DetectHiddenWindows, on
IfWinNotExist ahk_class Console_2_Main
{
ConsolePath := "PATH\TO\Console.exe"
EnvGet UserProfile, UserProfile
Run %ConsolePath%, "-d", %UserProfile%
@Fire-Dragon-DoL
Fire-Dragon-DoL / SCREEN.md
Last active August 29, 2015 14:04
Yakuake-like Mintty console for Windows with Autohotkey and Cygwin
bundle exec rspec spec/controllers/readers_controller_spec.rb
..FF**
Pending:
ReadersController POST create when save message returns to true redirects to root url
# Not yet implemented
# ./spec/controllers/readers_controller_spec.rb:45
ReadersController POST create when save message returns to true assigns a success flash message
# Not yet implemented
# ./spec/controllers/readers_controller_spec.rb:46
@Fire-Dragon-DoL
Fire-Dragon-DoL / user_sessions_controller.rb
Last active August 29, 2015 13:59
Gist login/logout controller
class UserSessionsController < ApplicationController
skip_before_action :get_current_user, only: [:create]
def create
authorize! :create, UserSessionsController
interactor = SignInUser.perform(users_session_params)
create_context interactor
if interactor.success?
@Fire-Dragon-DoL
Fire-Dragon-DoL / stock photos.md
Created January 29, 2014 00:44
Stock photos websites from various newsletters, use them for your website!