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-5 of 5 total  RSS 

firefox not showing vertical scrollbars in blog

hey everyone,

I'm new here and wondering if someone can help me out. i have a couple wordpress blogs i've built for clients, and i'm occasionally getting a wierd behavior in Firefox Win/Mac: sometimes even though there is plenty of content below the fold, no vertical scrollbar will show at all. it only does this on firefox.

here's an example (must view in firefox):

http://www.lorihedrickphotography.com/blog/

and i've tried adding this:


html {
height:101%;
overflow-y:scroll;
}


i looked at it with firebug, it validates. i'm stumped! any help would be greatly appreciated.

-jared

MetaWeblog API in PHP

Implementation of the MetaWeblog API http://www.xmlrpc.com/metaWeblogApi in PHP.

<?php
/**
 * Skeleton file for MetaWeblog API http://www.xmlrpc.com/metaWeblogApi in PHP
 * Requires Keith Deven's XML-RPC Library http://keithdevens.com/software/xmlrpc and store it as xmlrpc.php in the same folder
 * Written by Daniel Lorch, based heavily on Keith Deven's examples on the Blogger API.
 */

require_once dirname(__FILE__) . '/xmlrpc.php';

function metaWeblog_newPost($params) {
  list($blogid, $username, $password, $struct, $publish) = $params;
  $title = $struct['title'];
  $description = $struct['description'];


  // YOUR CODE:
  $post_id = 0; // id of the post you just created


  XMLRPC_response(XMLRPC_prepare((string)$post_id), WEBLOG_XMLRPC_USERAGENT);
}

function metaWeblog_editPost($params) {
  list($postid, $username, $password, $struct, $publish) = $params;


  // YOUR CODE:
  $result = false; // whether or not the action succeeded


  XMLRPC_response(XMLRPC_prepare((boolean)$result), WEBLOG_XMLRPC_USERAGENT);
}

function metaWeblog_getPost($params) {
  list($postid, $username, $password) = $params;
  $post = array();


  // YOUR CODE:
  $post['userId'] = '1';
  $post['dateCreated'] = XMLRPC_convert_timestamp_to_iso8601(time());
  $post['title'] = 'Replace me';
  $post['content'] = 'Replace me, too';
  $post['postid'] = '1';


  XMLRPC_response(XMLRPC_prepare($post), WEBLOG_XMLRPC_USERAGENT);
}

function XMLRPC_method_not_found($methodName) {
  XMLRPC_error("2", "The method you requested, '$methodName', was not found.", WEBLOG_XMLRPC_USERAGENT);
}

$xmlrpc_methods = array(
  'metaWeblog.newPost'  => 'metaWeblog_newPost',
  'metaWeblog.editPost' => 'metaWeblog_editPost',
  'metaWeblog.getPost'  => 'metaWeblog_getPost'
);

$xmlrpc_request = XMLRPC_parse($HTTP_RAW_POST_DATA);
$methodName = XMLRPC_getMethodName($xmlrpc_request);
$params = XMLRPC_getParams($xmlrpc_request);

if(!isset($xmlrpc_methods[$methodName])) {
  XMLRPC_method_not_found($methodName);
} else {
  $xmlrpc_methods[$methodName]($params);
}
?>

Test Trackback using cURL

I've Googled this about 20 times - documenting it here for convenience.

curl -d url=TRACKBACK_URL -d title=TRACKBACK_TITLE -d blog_name=TRACKBACK_BLOG_NAME -d excerpt=TRACKBACK_EXCERPT URL


A correct response:

<?xml version="1.0" encoding="utf-8"?>
<response>
<error>0</error>
</response>

Latex2wiki

Translate a subset of LaTeX into MoinMoin wiki syntax.


#!/usr/bin/env python

#    Copyright (C) 2003, Maxime Biais <maxime@biais.org>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# $Id: latex2wiki.py,v 1.1.1.1 2004/03/14 18:31:50 max Exp $

import sys, re

def dummy(d):
    pass

NONE = "__@NONE@__"

tr_list = [
    (r"\\includegraphics.*{(.*)\.eps}", "attachment::%s.png", dummy),
    (r"\\caption{.*}", "", dummy),
    (r"\\label{.*}", "", dummy),
    (r"(.*)\\emph{(.*)}(.*)", """%s'''%s'''%s""", dummy),
    (r"\\item (.*)", " * %s", dummy),
    (r"\\begin{.*}", "", dummy),
    (r"\\end{.*}", "", dummy),
    (r"(.*)``(.*)''(.*)", "%s\"%s\"%s", dummy),
    (r"\\chapter{(.*)}", NONE, dummy),
    (r"\\paragraph{(.*)}", "==== %s ====", dummy),
    (r"\\subsubsection{(.*)}", "==== %s ====", dummy),
    (r"\\subsection{(.*)}", "=== %s ===", dummy),
    (r"\\section{(.*)}", "== %s ==", dummy),
    (r"(.*)\\fig{.*}(.*)", "%s suivant %s", dummy)
    ]

in_stream  = open(sys.argv[1], "r")
if len(sys.argv) < 3:
    out_stream = sys.stdout
else:
    out_stream = open(sys.argv[2], "w")


for i in in_stream.readlines():
    cur_write = 0
    for reg in tr_list:
        m = re.search(reg[0], i)
        if m:
            reg[2](i)
            cur_write = 1
            if reg[1] == NONE:
                break
            print >> out_stream, reg[1] % m.groups()
            break
    if not cur_write:
        out_stream.write(i)

Use the contents of a WordPress database in your Rails app

These two models can be used to access the posts and associated comments of a WordPress database.

class WpBlogComment < ActiveRecord::Base

  # if wordpress tables live in a different database (i.e. 'wordpress') change the following
  # line to set_table_name "wordpress.wp_comments"
  # don't forget to give the db user permissions to access the wordpress db
  set_table_name "wp_comments"
  set_primary_key "comment_ID"

  belongs_to :post , :class_name => "WpBlogPost", :foreign_key => "comment_post_ID"

  validates_presence_of :comment_post_ID, :comment_author, :comment_content, :comment_author_email
  
  def validate_on_create
    if WpBlogPost.find(comment_post_ID).comment_status != 'open'
      errors.add_to_base('Sorry, comments are closed for this post')
    end
  end

end 


class WpBlogPost < ActiveRecord::Base

  set_table_name "wp_posts"
  set_primary_key "ID"

  has_many :comments, :class_name => "WpBlogComment", :foreign_key => "comment_post_ID"

  def self.find_by_permalink(year, month, day, title)
    find(:first, 
         :conditions => ["YEAR(post_date) = ? AND MONTH(post_date) = ? AND DAYOFMONTH(post_date) = ? AND post_name = ?", year.to_i, month.to_i, day.to_i, title])
  end
end 


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