Skip to content

Instantly share code, notes, and snippets.

View voltechs's full-sized avatar

Dale voltechs

  • Notion, Twilight Coders
  • Denver
View GitHub Profile
scope :roles_in_group, lambda { |g| { :conditions => { :roles => {:memberships => {:group => g.ancestors}}}}}
class Membership < ActiveRecord::Base
# attr_accessible :title, :body
set_primary_keys :user_id, :group_id
belongs_to :user
belongs_to :group
# Weird that we have to say "belongs_to", but it works.
belongs_to :role
has_many :members, :through => :memberships, :source => :user, :include => { :memberships => :role }, :order => 'roles.rank'
SELECT `users`.* FROM `users`
INNER JOIN `memberships`
ON `users`.`id` = `memberships`.`user_id`
INNER JOIN `roles`
ON `roles`.`id` = `memberships`.`role_id`
WHERE `memberships`.`group_id` = 'NUCC' AND (expiration > '2012-07-02')
ORDER BY `roles`.`rank` DESC
class Group < ActiveRecord::Base
set_primary_key :id
belongs_to :type, class_name: "GroupType"
belongs_to :parent, class_name: "Group", foreign_key: "parent_id"
has_many :children, class_name: "Group", foreign_key: "parent_id"
# Haven't played around with this part too much yet.
accepts_nested_attributes_for :children
@voltechs
voltechs / query.sql
Created July 8, 2012 23:45
Memberships ordered by the rank of membership's role.
SELECT `memberships`.* from `memberships`
INNER JOIN `groups` ON `groups`.id = `memberships`.group_id
INNER JOIN `roles` ON `memberships`.role_id = `roles`.id
INNER JOIN `roles` `role_cat` ON `role_cat`.id = `roles`.type_id
WHERE `groups`.id = "HHC" AND `memberships`.expiration > CURDATE()
ORDER BY `role_cat`.rank DESC, `roles`.rank DESC
irb(main):019:0> u.permissions
Permission Load (0.8ms) SELECT `permissions`.* FROM `permissions` INNER JOIN `groups` ON `permissions`.`group_id` = `groups`.`id` INNER JOIN `memberships` ON `groups`.`id` = `memberships`.`group_id` WHERE `memberships`.`user_id` = 1160 AND (expiration = "0000-00-00" OR expiration > '2012-07-10')
ActiveRecord::DangerousAttributeError: create is defined by ActiveRecord
from /usr/local/lib/ruby/gems/1.9/gems/activerecord-3.2.5/lib/active_record/attribute_methods.rb:91:in `instance_method_already_implemented?'
from /usr/local/lib/ruby/gems/1.9/gems/activemodel-3.2.5/lib/active_model/attribute_methods.rb:263:in `block in define_attribute_method'
from /usr/local/lib/ruby/gems/1.9/gems/activemodel-3.2.5/lib/active_model/attribute_methods.rb:260:in `each'
from /usr/local/lib/ruby/gems/1.9/gems/activemodel-3.2.5/lib/active_model/attribute_methods.rb:260:in `define_attribute_method'
from /usr/local/lib/ruby/gems/1.9/gems/activemodel-3.2.5/lib/act
@voltechs
voltechs / gist:59849ce491a5e1179e09
Created June 16, 2014 00:41
my stack trace for nsevent leak
0 libsystem_malloc.dylib malloc_zone_calloc
1 libsystem_malloc.dylib calloc
2 libobjc.A.dylib class_createInstance
3 libobjc.A.dylib +[NSObject allocWithZone:]
4 AppKit -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:]
5 sfml-window +[SFApplication processEvent]
6 sfml-window -[SFWindowController processEvent]
7 sfml-window sf::priv::WindowImpl::popEvent(sf::Event&, bool)
8 sfml-window sf::Window::pollEvent(sf::Event&)
9 Galaxer Client::run()
@echo off
cls
set x86=”%SYSTEMROOT%\System32\OneDriveSetup.exe”
set x64=”%SYSTEMROOT%\SysWOW64\OneDriveSetup.exe”
echo Closing OneDrive process.
echo.
@voltechs
voltechs / no_automount
Last active November 18, 2022 01:29
Add volume (UUID) to fstab to prevent automount (macOS)
#!/usr/bin/env ruby
# Usage: no_automount /Volumes/My\ Disk
diskinfo = `diskutil info '#{ARGV[0]}'`.gsub("\n\n", "\n").split("\n").collect { |b|
b.strip.split(/:\s+/)
}.to_h
disk_uuid = diskinfo['Volume UUID']
disk_type = diskinfo['Type (Bundle)']