Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

The Linux Console

linuxcommand.org


Now what?

You have Linux installed and running. The GUI is working fine, but you are getting tired of changing your desktop themes. You keep seeing this "terminal" thing.

@stoffie
stoffie / eslfc.md
Last active December 18, 2015 08:35

Spunti esercizi

  • Dichiarazione di array
  • accesso agli array
  • free di ogni nodo usato (curare i mem leack?)
  • deallocazione variabili locali (riparare lo scope)
  • implementare il tipo di dato nativo float

Authorization in ruby on rails


Web framework

In a web framework, when we handle a request in our application, we always do the same things, every time:

  • Authenticate the user
  • Authorize the request

"CanCan is an authorization library for Ruby on Rails which restricts what resources a given user is allowed to access. All permissions are defined in a single location (the Ability class) and not duplicated across controllers, views, and database queries."


Installation

Add this to your Gemfile and run the bundle install command

gem 'cancancan', '~> 1.10'
class Object
def my_method(sym)
MyMethod.new(self, sym)
end
end
class MyMethod
def initialize(obj, method)
@obj, @method = obj, method
end

"A pundit is a person who offers to mass media their opinion or commentary on a particular subject area (typically political analysis, the social sciences, technology or sport) on which they are knowledgeable, or considered a scholar in said area" - Wikipedia


"Pundit provides a set of helpers which guide you in leveraging regular Ruby classes and object oriented design patterns to build a simple, robust and scaleable authorization system" - Github

Installation

In your Gemfile:

# http://codegolf.stackexchange.com/questions/64650/generate-toothpick-sequence
n = ARGV[0].to_i
$t = (n * 2).times.map { [' '] * n * 2}
def add_backslash_top (n,m,c)
if $t[n] && $t[n][m] == " " && c!=0
$t[n][m] = '\\'
add_slash_left(n,m-1,c-1)
damiano.stoffie@sci-b106pc035x:~$ lex --version
lex 2.5.35
array = ["america", "europe", "asia", "africa", "france", "usa", "spain", "paris", "los angeles"]
definitions = {
"continent" => ["america", "europe", "asia", "africa"],
"country" => ["france", "usa", "spain"],
"city" => ["paris", "los angeles"],
"planet" => ["mars","earth"]
}
inverse_array = definitions.map {|k,v| v.map { |e| [e, k]}}.flatten(1)