Skip to content

Instantly share code, notes, and snippets.

<div class="outer">
<div class="inner">
</div>
</div>
var html_to_inject = "<div class=\"middle\"></div>"
$(".outer").inject(html_to_inject).html(); //gives us:
@eqdw
eqdw / ProperOO.rb
Created October 28, 2010 18:48
In case you miss Java...
module ProperOO
self.instance_variables.each do |i|
class_eval <<CODE
def get_#{i}
i
end
def set_#{i} newVal
@#{i} = newVal
end
CODE
if params[:title]
@posts = Post.where("UPPER(posts.title) LIKE UPPER(%?%)", parmas[:title]).paginate(:page => 1, :order => "created_at DESC", :per_page => 20)
else
@posts = Post.paginate(:page => 1, :orde r= "created_at DESC", :per_page => 20)
end
<?php
/**
* @version $Id: mod_latestnews.php 14401 2010-01-26 14:10:00Z louis $
* @package Joomla
* @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
<?php
/**
* @version $Id: helper.php 14401 2010-01-26 14:10:00Z louis $
* @package Joomla
* @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
<?php // no direct access
defined('_JEXEC') or die('Restricted access'); ?>
<ul class="blogmenuouter<?php echo $params->get('moduleclass_sfx'); ?>">
<?php foreach ($list as $item) : ?>
<li class="blogmenuouter<?php echo $params->get('moduleclass_sfx'); ?>">
<a href="<?php echo $item->link; ?>" class="latestnews<?php echo $params->get('moduleclass_sfx'); ?>">
<?php echo $item->text; ?></a>
</li>
<?php endforeach; ?>
</ul>
<?php // @version $Id: blog_item.php 11917 2009-05-29 19:37:05Z ian $
defined('_JEXEC') or die('Restricted access');
?>
<?php if ($this->user->authorize('com_content', 'edit', 'content', 'all') || $this->user->authorize('com_content', 'edit', 'content', 'own')) : ?>
<div class="contentpaneopen_edit<?php echo $this->escape($this->item->params->get('pageclass_sfx')); ?>">
<?php echo JHTML::_('icon.edit', $this->item, $this->item->params, $this->access); ?>
</div>
<?php endif; ?>
<div class="blogpostheader">
@eqdw
eqdw / heredoc.rb
Created November 4, 2010 21:04
scary ruby syntax!
string = [<<ONE, <<TWO, <<THREE]
the first thing
ONE
the second thing
TWO
and the third thing
THREE
# evaluates to:
# ["the first thing", "the second thing", "and the third thing"]
##in view:
link_to "TEST", blog_path(:year => 2010, :month => 09)
##when routes looks like:
match 'blog', => 'blog#index'
match 'blog(/:year/:month)' => 'blog#index'
class Post < ActiveRecord::Base
scope :date_counts, lambda {
group('DATE_FORMAT(created_at, "%Y/%m")').count
}
##Post.date_counts GENERATES ERROR: ArgumentError: Unknown key(s): 2009/01, 2009/02, 2009/03, 2009/04, 2009/06 ... etc
def self.date_counts
self.group('DATE_FORMAT(created_at, "%Y/%m")').count
end