Skip to content

Instantly share code, notes, and snippets.

@ebragaparah
ebragaparah / init.el
Last active November 17, 2020 22:15
my emacs settings
(setq inhibit-startup-message t)
(setq inhibit-splash-screen t)
(tool-bar-mode -1)
(menu-bar-mode -1)
(setq tab-width 2)
(setq indent-tabs-mode nil)
(global-linum-mode t)
;; packages
(when (>= emacs-major-version 24)
(require 'package)
(package-initialize)
(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/") t)
)
@ebragaparah
ebragaparah / truncateString.js
Last active April 4, 2016 03:13
It's an approach that truncate a string given the maximum size, but following some conditions
function truncateString(str, num) {
var points = '...';
return num < str.length ?
((num < points.length) ?
str.substr(0, num).concat(points) :
str.substr(0, num - points.length).concat(points)) :
str;
}
@ebragaparah
ebragaparah / confirmEnding.js
Created April 4, 2016 02:15
Check if a string ends with another.
function confirmEnding(str, target) {
var counter = 0;
strLastCharPosition = str.length - 1;
targetLastCharPosition = target.length - 1;
while (counter <= target.length &&
(target[targetLastCharPosition] === str[strLastCharPosition])) {
counter++;
strLastCharPosition--;
targetLastCharPosition--;
}
@ebragaparah
ebragaparah / largestItemsOfManyArrays.js
Last active April 3, 2016 22:11
Find the largest number of each array inside another array
function largestOfManyArrays(arr) {
function largestItemOfAnArray(arr) {
return arr.sort(function (a, b) { return b - a; }).shift();
}
var largestOfEachArray = arr.map(function(array) {
return largestItemOfAnArray(array);
});
return largestOfEachArray;
}
Rapaz, a dúvida é a seguinte:
eu tenho dois models, pesquisador e bolsista, preciso de uma interface administrativa, o que atualmente eu tenho como outro model, ou seja, tenho 'pesquisador.rb', 'bolsista.rb', 'admin.rb'
eu preciso utilizar um plugin de autenticação, seja devise, restful_authentication, authlogic...
só que uma coisa em comum em todos esses plugins é que eles trabalham somente com um modelo, geralmente 'user.rb'.
eu li em alguns lugares algumas coisas que possivelmente poderiam me ajudar com isso, como associações polimórficas ou STI(single table inheritance).