Skip to content

Instantly share code, notes, and snippets.

View pnomolos's full-sized avatar

Phil Schalm pnomolos

  • Jane.app
  • British Columbia, BC
  • 16:45 (UTC -12:00)
  • X @pnomolos
View GitHub Profile
Attaching to the process with GDB
Populate your .gdbinit and .gdb directories
In ~/.gdbinit:
define session-ruby
source ~/.gdb/ruby
end
@pnomolos
pnomolos / Gemfile
Last active August 29, 2015 14:17 — forked from solnic/ar_create.rb
Call-tree example for ActiveRecord vs. rom-sql
# A sample Gemfile
source "https://rubygems.org"
gem 'activerecord'
gem 'hotch'
gem 'rom-sql'
gem 'sqlite3'
module Packs
module Admin
class Grade < Grade
# Stub class extending from the real definition
end
end # Admin
end # Packs
window.addEvent('domready',function(){
if ($('section-menu')) {
$('section-menu').getElements('a.menuitem').each(function(n){
n.addEvent('click',function(ev){
new Event(ev).preventDefault();
})
})
var accordion = new Accordion('a.menuitem', 'ul.submenu', {
opacity: false,
onActive: function(toggler, element){
<!-- The cheater way -->
<a href="javascript:window.history.go(-2);">Go back 2 history</a>
<!-- The more correct way -->
<span id="go-back">Go back</span>
<script type="text/javascript">
document.getElementById('go-back').onclick = function() {
window.history.go(-2);
}
</script>
/*
*
* Copyright (c) 2006-2009 Sam Collett (http://www.texotela.co.uk)
* Modified by Phil Schalm to allow custom sorting via a passed in function
*
*/
$.fn.sortOptions = function(ascending)
{
// get selected values first
$.fn.sortOptions = function(ascending)
{
var _sortFunc;
if ( typeof(ascending) == "function") {
_sortFunc = ascending;
} else if (!!ascending) {
_sortFunc = function(a,b) {
return a.text < b.text ? -1 : 1;
}
} else {
# Get all the properties that aren't fulltext (which will cause the query to break)
props = Product.properties.reject{|p| p.type == DataMapper::Types::Text }.map{|p| "`products`.`#{p.name}`" }.join(', ')
# Get categories before hand as it tends to be a little faster.
@categories = Category.all( :name.like => "%#{params[:search]}%" )
# Do the massive query.
# You'll notice the << -1 on the queries. Since @category.id is an autoincrement it'll never be -1 and this is easier than a messey ternary statement. I'd imagine the messy statement could be a little faster, however.
@t_products = Product.find_by_sql(["SELECT " + props + "
FROM products
LEFT JOIN categories_products ON categories_products.product_id = products.id
module DataMapper
class Query
alias :old_assert_valid_order :assert_valid_order
def assert_valid_order(order, fields)
old_assert_valid_order(order, fields) unless !order.nil? && order.any? { |p| p.is_a?(Direction) && p.property.name == :sort_order }
end
end
end
namespace :admin do
resources :services
end