Skip to content

Instantly share code, notes, and snippets.

View lancejpollard's full-sized avatar
😍
Lots of coding

Lance Pollard lancejpollard

😍
Lots of coding
View GitHub Profile
@lancejpollard
lancejpollard / Rails Nested Forms with belongs_to
Created January 13, 2010 23:09
Rails Nested Forms with belongs_to, doesn't work by default
# user.rb
class User < ActiveRecord::Base
belongs_to :address
accepts_nested_attributes_for :address # can't have allow_destroy
end
# users_controller.rb
class UsersController < ApplicationController
@lancejpollard
lancejpollard / Flex Keyboard Handler
Created January 18, 2010 13:50
Simple Example of Using Keyboard Events from Javascript to Actionscript, so you can hijack Browser Keyboard Handlers
var FlexKeyboardHandler = FlexKeyboardHandler || {}
FlexKeyboardHandler.setup = function ()
{
window.addEventListener("keypress", FlexKeyboardHandler.keydownHandler, true);
window.addEventListener("keydown", FlexKeyboardHandler.keydownHandler, true);
getFlexApplication("MyApp").addEventListener("keypress", FlexKeyboardHandler.keydownHandler, true);
getFlexApplication("MyApp").addEventListener("keypress", FlexKeyboardHandler.keydownHandler, false);
window.focus();
};
SQL (0.4ms) SELECT COUNT(*) AS count_id FROM "posts" WHERE ("posts"."parent_id" IS NULL)
Post Load (0.7ms) SELECT "posts".* FROM "posts" WHERE ("posts"."parent_id" IS NULL) ORDER BY "lft"
Slug Load (0.4ms) SELECT "slugs".* FROM "slugs" WHERE ("slugs".sluggable_id = 13 AND "slugs".sluggable_type = 'Post') ORDER BY id DESC LIMIT 1
SQL (0.3ms) SELECT COUNT(*) AS count_id FROM "posts" WHERE ("posts".parent_id = 13)
Post Load (0.7ms) SELECT "posts".* FROM "posts" WHERE ("posts".parent_id = 13) ORDER BY "lft"
Post Load (0.4ms) SELECT "posts".* FROM "posts" WHERE ("posts"."id" = 13) LIMIT 1
CACHE (0.0ms) SELECT "slugs".* FROM "slugs" WHERE ("slugs".sluggable_id = 13 AND "slugs".sluggable_type = 'Post') ORDER BY id DESC LIMIT 1
Slug Load (0.4ms) SELECT "slugs".* FROM "slugs" WHERE ("slugs".sluggable_id = 39 AND "slugs".sluggable_type = 'Post') ORDER BY id DESC LIMIT 1
SQL (0.4ms) SELECT COUNT(*) AS count_id FROM "posts" WHERE ("posts".parent_id = 39)
CACHE (0.0ms) SELECT "posts".* FROM "po
@lancejpollard
lancejpollard / awesome_nested_set_optimization_helper.rb
Created July 2, 2010 01:39
Goal: Convert entire hierarchy of models into tree in 1 database call, such that you can loop through them depth-first
def simple_nested_set(clazz) # Post for example
stack = [] # Post for example
result = []
clazz.all(:order => "lft").each do |node|
if stack.empty?
stack.push({:node => node, :children => []})
result << stack.last
next
end
if stack.last[:node].lft < node.lft && node.lft < stack.last[:node].rgt
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Parent Page wanting to Parse Children</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<meta name="keywords" content="parent, html, parsing">
</head>
<body>
<script type="text/javascript">
$(document).ready(function() {
<body>
<section class="top" role="definition">
<div class="header">
<div class="frame">
<header></header>
<nav></nav>
</div>
</div>
</section>
<section class="main" role="main">
stylesheets/
  application.scss
  base/
    _base.scss
    _grid.scss
    _reset.scss
    _typography.scss
  components/
    editor/

_design.scss

<div class='document' role='document'>
<section class='header container' role='definition'>
<div class='navigation'>
<div class='frame'>
<header class='logo'>
<h1></h1>
</header>
<nav class='menu' role='directory'>
<ul>
<li>
class Hash
def recursively_symbolize_keys!
self.symbolize_keys!
self.values.each do |v|
if v.is_a? Hash
v.recursively_symbolize_keys!
elsif v.is_a? Array
v.recursively_symbolize_keys!
end
end
git clone git://github.com/ry/node.git
cd node
./configure
make
sudo make install