Reputation: 13
Good
- Group:
- Members
- Active Posts:
- 583 (0.67 per day)
- Most Active In:
- General Discussion (132 posts)
- Joined:
- 05-January 11
- Profile Views:
- 3153
- Last Active:
Today, 04:44 PM- Currently:
- Offline
My Information
- Age:
- 43 years old
- Birthday:
- November 13, 1969
- Gender:
-
Male
- Location:
- Toronto
Contact Information
- E-mail:
- Private
Posts I've Made
-
In Topic: Cheap Android based cell, what do you recommend?
18 May 2013 - 08:42 PM
Thanks for all the suggestions, it looks like I'll be looking for a Nexus S that will work with Bell Mobility (my iPhone is on Telus) for a few months, then will pass it on to a family member when I've finished with it. -
In Topic: How To Make a User Account System
18 May 2013 - 08:38 PM
So I finally decided to play around with Kyek's permission system in Ruby, and cam up with this:
module User class Permissions # all possible permissions P = Hash.new(1).merge( ACCESS_ADMIN_PANEL: i=1, REMOVE_USER_BAN: i*=2, BAN_USER: i*=2, SEND_MESSAGE_TO_USER: i*=2, SEND_MESSAGE_TO_GROUP: i*=2, SEND_MESSAGE_TO_ALL: i*=2, CREATE_PUBLIC_SECTION: i*=2, CREATE_PRIVATE_SECTION: i*=2, MODIFY_PUBLIC_SECTION: i*=2, MODIFY_PRIVATE_SECTION: i*=2, DELETE_PUBLIC_SECTION: i*=2, DELETE_PRIVATE_SECTION: i*=2, READ_PUBLIC_CONTENT: i*=2, READ_PRIVATE_CONTENT: i*=2, CREATE_PUBLIC_CONTENT: i*=2, CREATE_PRIVATE_CONTENT: i*=2, MODIFY_PUBLIC_CONTENT: i*=2, MODIFY_PRIVATE_CONTENT: i*=2, MOVE_PUBLIC_CONTENT: i*=2, MOVE_PRIVATE_CONTENT: i*=2) class << self # check if group allows 1 permission def allowed?(perm=:UNKNOWN, grp=0) P[perm]|grp == grp end # check if group allows 1 or more permissions def allowed_many?(*args, grp) args.map{|e| P[e]}.inject(0,:+)|grp == grp end def includes(grp) P.find_all{|k,v| v|grp == grp}.flatten.keep_if{|e| e.class == Symbol} end def group(*args) args.map{|e| P[e]}.inject(0,:+) end end end end
I put the permissions in a hash, instead of just constants, so I could use Ruby's Enumerable, Hash, and Array methods to manipulate and work with them (for example, this allows me to easily generate a list of all the permissions included in a group). I use thei*=2
so I can quickly add, remove, or re-arrange permissions without having to worry about setting the actual values.
I can quickly create a group's permission withnew_group = User::Permissions::P.group(:ONE, :TWO, :THREE)
, get an array of permissions' names in a group withUser::Permissions::P.includes(new_group) => [:ONE, :TWO, :THREE]
, or simply check if a single permission is allowed in a particular group withUser::Permissions::P.allowed?(:ONE, new_group) => true
.
I think it is a good start, what do you think? Can any Rubiests out there critique my code?
NOTE: I just wanted to point out that all thei*=2
is only for development, once the system is ready for production, they would be replaced with actual values, so that in the future if permissions were added or removed, the existing permissions would still work. -
In Topic: Pleas take a look at my iptables rules.
09 May 2013 - 03:57 PM
Figured it out, thanks anyway. -
In Topic: $8 per year VPS - What for?
09 May 2013 - 03:54 PM
Daniel15, on 08 May 2013 - 06:08 AM, said:My first computer was a second-hand one back in 1998 and had 16 MB RAM. At the time, some friends (not many) had computers with 32 or even 64 MB RAM! That was SO HUGE!)
My first system was an Apple II+, with 128KB RAM and a tape cassette drive to load/store your apps. Had to write apps in 6502 Assembly language (and then Applesoft Basic).
-
In Topic: Local "VPS" Testing Environment
09 May 2013 - 03:48 PM
I've been using Parallels on my Mac, which can run VMware, so I've been using that.






Cartoon Clouds
Mountains
Sunrise
Clouds
Green Clouds
None
Find My Content
Display name history


Help
Comments
gushort has no profile comments yet. Why not say hello?