<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: snippets code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 16 May 2008 14:30:09 GMT</pubDate>
    <description>DZone Snippets: snippets code</description>
    <item>
      <title>RSS Feed for DZone Snippets Comments</title>
      <link>http://snippets.dzone.com/posts/show/5031</link>
      <description>&lt;a href="http://feed43.com/8055673348816228.xml"&gt;http://feed43.com/8055673348816228.xml&lt;/a&gt;</description>
      <pubDate>Wed, 23 Jan 2008 14:23:09 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5031</guid>
      <author>timmorgan (Tim Morgan)</author>
    </item>
    <item>
      <title>Logging in + posting reactivated</title>
      <link>http://snippets.dzone.com/posts/show/2322</link>
      <description>There were some problems with a software upgrade. You can now log in and post again! :)</description>
      <pubDate>Mon, 24 Jul 2006 14:56:20 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2322</guid>
      <author>peter (Peter Cooperx)</author>
    </item>
    <item>
      <title>Using multiple tags on Code Snippets</title>
      <link>http://snippets.dzone.com/posts/show/1615</link>
      <description>I spent a lot of time trying to select snippets with&lt;br /&gt;contain multiple tags. (series60 and sql)&lt;br /&gt;There is no '+' links I can click anymore.&lt;br /&gt;After about 10 minutes of trial and error, I find out how.&lt;br /&gt;This also answer another question on correct use of URL.&lt;br /&gt;&lt;code&gt;&lt;br /&gt;# for tag 'series60' AND 'sql'&lt;br /&gt;http://www.bigbold.com/snippets/tags/series60/sql/&lt;br /&gt;&lt;br /&gt;# this doesn't work&lt;br /&gt;http://www.bigbold.com/snippets/tag/series60/sql/&lt;br /&gt;&lt;br /&gt;# all of these work (single tag case)&lt;br /&gt;http://bigbold.com/snippets/tag/series60/&lt;br /&gt;http://bigbold.com/snippets/tags/series60/&lt;br /&gt;http://www.bigbold.com/snippets/tag/series60/&lt;br /&gt;http://www.bigbold.com/snippets/tags/series60/&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;My conclusion is that.&lt;br /&gt;For a single tag, use '/tag/...'.&lt;br /&gt;For multiple tags, use '/tags/...'.&lt;br /&gt;The first is quicker to type, while the second is flexible in case you want to filter further.</description>
      <pubDate>Thu, 02 Mar 2006 18:39:29 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1615</guid>
      <author>korakot (Korakot Chaovavanich)</author>
    </item>
    <item>
      <title>Backup all of your Code Snippets posts</title>
      <link>http://snippets.dzone.com/posts/show/971</link>
      <description>We've just added support for backing up ALL your posts here at Snippets!&lt;br /&gt;&lt;br /&gt;If you're logged in.. http://www.bigbold.com/snippets/api/posts/all will return an RSS file with ALL of your posts.&lt;br /&gt;&lt;br /&gt;For occasional use.. http://www.bigbold.com/snippets/api/posts/all?username=whatever&amp;password=whatever will get you all of your posts.&lt;br /&gt;</description>
      <pubDate>Tue, 13 Dec 2005 14:06:17 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/971</guid>
      <author>peter (Peter Cooperx)</author>
    </item>
    <item>
      <title>Snippets 2 Launches!</title>
      <link>http://snippets.dzone.com/posts/show/956</link>
      <description>If you're a regular visitor to the site, you'll notice the layout has change a lot around here.. well, actually.. most of the code has too! Yes, you're now using Snippets 2, a total rewrite. It still lacks some of the things the old one lacked, but the infrastructure is now there. The old Snippets was notoriously unstable on the newer versions of Rails.&lt;br /&gt;&lt;br /&gt;New features include.. syntax coloring (for Ruby, primarily, at the moment), the ability to mark posts as 'private', an all new design, and better URLs and RSS, etc.&lt;br /&gt;&lt;br /&gt;Source access for this new version will be via SVN and will be made available in the next couple of weeks as the bugs are wriggled out of this version and I fix up all of the 'hacks'! Post your comments/praise/bug reports on the new version here..</description>
      <pubDate>Sat, 10 Dec 2005 14:46:50 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/956</guid>
      <author>peter (Peter Cooperx)</author>
    </item>
    <item>
      <title>A simple python class to browse snippets website (with beautifoulsoup)</title>
      <link>http://snippets.dzone.com/posts/show/692</link>
      <description>if you got some path/enhancements, you can mail me at my pseudo at gmail.com, i'll update it.&lt;br /&gt;(you should install the marvellous beautifulsoup module, http://www.crummy.com/software/BeautifulSoup/documentation.html)&lt;br /&gt;&lt;br /&gt;the snippets.py file :&lt;br /&gt;&lt;code&gt;&lt;br /&gt;from BeautifulSoup import BeautifulSoup&lt;br /&gt;import urllib&lt;br /&gt;&lt;br /&gt;class Keyword: # top tags&lt;br /&gt;    def __init__(self,tag,nb):&lt;br /&gt;        self.tag=tag&lt;br /&gt;        self.nb=int(nb)&lt;br /&gt;    def __repr__(self):&lt;br /&gt;        return "&lt;Keyword '%s' : %d&gt;" % (self.tag,self.nb)&lt;br /&gt;&lt;br /&gt;class Snippet:&lt;br /&gt;    def __init__(self,title,code,tags):&lt;br /&gt;        self.title=title&lt;br /&gt;        self.code=code&lt;br /&gt;        self.tags = tags&lt;br /&gt;    def __repr__(self):&lt;br /&gt;        return "&lt;Snippet '%s' : tags %s&gt;" % (self.title,str(self.tags))&lt;br /&gt;&lt;br /&gt;class Snippets:&lt;br /&gt;    urlForTags = "http://www.bigbold.com/snippets/tags"&lt;br /&gt;    &lt;br /&gt;    def __init__(self,l=[]):&lt;br /&gt;        url = self.__getUrlForTags(l)&lt;br /&gt;        &lt;br /&gt;        #load the url&lt;br /&gt;        fu = urllib.urlopen(url)&lt;br /&gt;        content = fu.read()&lt;br /&gt;        fu.close()&lt;br /&gt;&lt;br /&gt;        self.tags = l&lt;br /&gt;        self.keywords,self.snippets = self.__extractContent(content)&lt;br /&gt;&lt;br /&gt;    def __repr__(self):&lt;br /&gt;        return "&lt;Snippets for tags:%s&gt;" % (str(self.tags))&lt;br /&gt;&lt;br /&gt;    def __getUrlForTags(self, l ):&lt;br /&gt;        assert type(l)==list&lt;br /&gt;        l = [Snippets.urlForTags] + l&lt;br /&gt;        return "/".join(l)&lt;br /&gt;    &lt;br /&gt;    def __extractContent(self,content):&lt;br /&gt;        &lt;br /&gt;        soup = BeautifulSoup( content ) &lt;br /&gt;            &lt;br /&gt;        # get the keywords&lt;br /&gt;        tagTable=soup('div', {'id' : "sidebar"})[0].table&lt;br /&gt;        keywords=[]&lt;br /&gt;        for i in tagTable("tr"):&lt;br /&gt;            td = i("td")&lt;br /&gt;            &lt;br /&gt;            # add this keyword&lt;br /&gt;            try:&lt;br /&gt;                # extract from the empty selection page "/tags"&lt;br /&gt;                keywords.append( Keyword(td[1].span.a.string , td[0].string) )&lt;br /&gt;            except TypeError:&lt;br /&gt;                # extract from a selected selection page "/tag/something"&lt;br /&gt;                keywords.append( Keyword(td[2].span.a.string , td[1].string) )&lt;br /&gt;        &lt;br /&gt;        # get the snippets&lt;br /&gt;        postList=soup('div', {'class' : "post"})&lt;br /&gt;        snippets=[]&lt;br /&gt;        for i in postList:&lt;br /&gt;            divs = i("div")&lt;br /&gt;            &lt;br /&gt;            # get title and tags&lt;br /&gt;            title =  divs[0].h3.a.string # title&lt;br /&gt;            tags = [j.string for j in divs[1]("a")][:-1] #don't get the user ;-)&lt;br /&gt;&lt;br /&gt;            # get code of the snippet&lt;br /&gt;            list = [j for j in divs[0]][1:]# zap the first (h3)&lt;br /&gt;            code=""&lt;br /&gt;            for i in list: &lt;br /&gt;                try:&lt;br /&gt;                    if i.name == "pre":&lt;br /&gt;                        try:&lt;br /&gt;                            code+=i.string&lt;br /&gt;                        except TypeError:&lt;br /&gt;                            pass&lt;br /&gt;                except AttributeError:&lt;br /&gt;                    # transform "out-pre-text" in comment&lt;br /&gt;                    out = str(i).strip()&lt;br /&gt;                    if out:&lt;br /&gt;                        code+="#| "+out+"\n" &lt;br /&gt;            &lt;br /&gt;            # add this snippet&lt;br /&gt;            snippets.append( Snippet(title,code,tags) )&lt;br /&gt;            &lt;br /&gt;        return keywords,snippets&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;and an example (all returned "strings" are in utf-8):&lt;br /&gt;&lt;code&gt;&lt;br /&gt;from snippets import Snippets&lt;br /&gt;&lt;br /&gt;s = Snippets(["python","xml"])&lt;br /&gt;print s&lt;br /&gt;print s.keywords # the "top tags" column&lt;br /&gt;for i in s.snippets:&lt;br /&gt;    print i&lt;br /&gt;print s.snippets[6].title # the title of the 6th&lt;br /&gt;print s.snippets[6].code  # the code of the 6th&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 09 Sep 2005 19:31:22 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/692</guid>
      <author>manatlan (manatlan)</author>
    </item>
    <item>
      <title>Apologies for downtime - weird Rails issues</title>
      <link>http://snippets.dzone.com/posts/show/314</link>
      <description>I apologise for the downtime on Sunday and early Monday. I am buying a new server to spread the load.&lt;br /&gt;&lt;br /&gt;One of the biggest problems with this server is that after an hour or two, Snippets' dispatch.fcgi is using tons of CPU and not serving requests. Despite setting FCGIConfig properly, these processes are not getting killed.&lt;br /&gt;&lt;br /&gt;I've written and cronned a Perl script that does a killall -9 on ruby and dispatch.fcgi processes whenever load goes over a certain amount.&lt;br /&gt;&lt;br /&gt;Bloocy weird, and highly annoying. It's like dispatch.fcgi is getting caught someplace.</description>
      <pubDate>Mon, 23 May 2005 22:55:24 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/314</guid>
      <author>peter (Peter Cooperx)</author>
    </item>
    <item>
      <title>How Snippets gets general post counts for tags</title>
      <link>http://snippets.dzone.com/posts/show/102</link>
      <description>This is in models/tag.rb&lt;br /&gt;&lt;br /&gt;&lt;code&gt;def find_all_with_count&lt;br /&gt;    self.find_by_sql("SELECT t.*, COUNT(pt.post_id) AS count FROM tags t, posts_tags pt WHERE pt.tag_id = t.id GROUP BY t.id ORDER BY count DESC;")&lt;br /&gt;end&lt;/code&gt;&lt;br /&gt;This is a basic non-specific overview of all tags, as you would see on Snippets' front page. So:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;@tag_info = Tag.find_all_with_count&lt;br /&gt;@tag_info.each { |t| .. you now have t.name, t.count, etc .. }&lt;/code&gt;</description>
      <pubDate>Sat, 09 Apr 2005 07:46:34 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/102</guid>
      <author>peter (Peter Cooperx)</author>
    </item>
    <item>
      <title>Snippets' routes</title>
      <link>http://snippets.dzone.com/posts/show/64</link>
      <description>These routes allow URLs like tags/whatever/whatever/whatever to put 'whatever', 'whatever', and 'whatever' into the @params[:tags] array, etc.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;map.connect '', :controller =&gt; "posts", :action =&gt; "index"&lt;br /&gt;map.connect 'tags/*tags', :controller =&gt; 'tag', :action =&gt; 'show'&lt;br /&gt;map.connect 'user/:user', :controller =&gt; 'user', :action =&gt; 'show'&lt;br /&gt;map.connect 'user/:user/tags/*tags', :controller =&gt; 'tag', :action =&gt; 'show'&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;</description>
      <pubDate>Fri, 08 Apr 2005 01:46:38 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/64</guid>
      <author>peter (Peter Cooperx)</author>
    </item>
    <item>
      <title>Find items with similar (or as many as possible) relationships - for a 'related posts' box etc</title>
      <link>http://snippets.dzone.com/posts/show/35</link>
      <description>If we have the id for a post in &lt;em&gt;postid&lt;/em&gt; and a limit of &lt;em&gt;num&lt;/em&gt; and we want to find posts which share as many tags as possible with &lt;em&gt;postid&lt;/em&gt;'s post, the following SQL will get you there.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;SELECT p.*, COUNT(pt2.post_id) AS count FROM posts p, posts_tags pt, tags t, posts_tags pt2 WHERE pt.post_id=#{postid} AND t.id = pt.tag_id AND pt2.post_id != pt.post_id AND pt2.tag_id=pt.tag_id AND p.id = pt2.post_id GROUP BY pt2.post_id ORDER BY count DESC LIMIT #{num};")&lt;/code&gt;</description>
      <pubDate>Mon, 04 Apr 2005 02:00:47 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/35</guid>
      <author>peter (Peter Cooperx)</author>
    </item>
  </channel>
</rss>
