Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-4 of 4 total  RSS 

Eclipse template: User specific comment for new methods

Window -> Preferences -> Java -> Code Style -> Code Templates -> Code -> Method body

Usefull for multiuser-projects!

Pattern:
// ${todo} ${user}: not yet implemented - ${enclosing_method}
${body_statement}

Rails task to find code typos in rhtml templates


namespace :typos do 
  task :rhtml do
    require 'erb'
    require 'active_support'
    require 'action_view'

    module TempTemplates; end
    Dir["./app/views/**/*.rhtml"].each do |fname|
      local_source = ERB.new(IO.read(fname), nil, '-').src
      template_source = "def _tmpl\n#{local_source}\nend"
      begin
        TempTemplates.module_eval(template_source, fname, 0 )
      rescue Object => e
        t = ActionView::TemplateError.new("./app/views/", fname, {}, template_source, e)
        puts "TemplateError (#{t.message}) on line ##{t.line_number} of #{t.file_name}:\n"+t.source_extract + "\n------\n"
      end
    end
  end
end

Bootstrap Django templates out-of-framework

This is the quickest way I've found to bootstrap Django templates without using the entire framework. This is suited for "plain-python" apps without using all the Django types. You'll probably want to cache the Template returns for each given name, but here's the basics.

# Kick off django config machinery first
from django.conf import settings
settings.configure(TEMPLATE_DIRS=("/whatever/templates",))

import django.template
import django.template.loader


def render(name, *values):
    ctx = django.template.Context()
    for d in values:
        ctx.push()
        ctx.update(d)

    t = django.template.loader.get_template(name)
    return t.render(ctx)

print render('layout.tmpl', dict(title='User'), dict(name='Bob', gender='M'))

Generic XHTML template

I'm often having to reconstruct this, as I can no longer memorize everything (just blank HTML and BODY tags used to be acceptable ;-)) with the DOCTYPE and namespaces.. so to make it easier to grab in future:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
	<head>
		<title></title>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<link rel="stylesheet" href="styles.css" type="text/css" media="screen" />
		<script type="text/javascript" src="common.js"></script>
	</head>

	<body>
		<div id="container">

			<div id="header">
			</div>

			<div id="wrapper">
				<div id="main">
					
				</div>
			</div>

			<div id="footer">
			</div>
			
		</div>
	</body>

</html>
« Newer Snippets
Older Snippets »
Showing 1-4 of 4 total  RSS