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

Snippets 2 Launches!

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.

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.

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..

Getting and Parsing 10x10

Here's my source code in ColdFusion for parsing 10x10. I can't imagine it being different in other languages.

----

<!--- build the wordsURL before getting the data --->
<cfset year = DateFormat(Now(),"YYYY")>
<cfset month = DateFormat(Now(),"MM")>
<cfset day = DateFormat(Now(),"DD")>
<cfset hour = TimeFormat(Now(),"HH")>
<cfset wordsURL = "http://tenbyten.org/Data/#year#/#month#/#day#/#hour#/words.txt">

<!--- connect to the url --->
<cfhttp method="get" url="#wordsURL#" timeout="60"></cfhttp>

<cfset wordlist = cfhttp.FileContent>

<!--- write the data into a text file --->
<cffile action="write" file="#ExpandPath('words.txt')#" output="#ToString(wordlist)#">


----

Reading the content is as simple as opening the file and traversing through it like so. I also added in a link to Google news. I've found it helpful to click on news bits in the past.

----

<cfhttp method="get" url="http://path/to/words.txt" timeout="60"></cfhttp>

<cfset wordlist = cfhttp.FileContent>

<ul><li>
<cfloop list="#wordlist#" delimiters="#chr(13)##chr(10)#" index="word">
  <cfoutput>
    <a href="http://news.google.com/news?q=#word#" target="_blank">#word#</a>
  </cfoutput>
</cfloop>
</li></ul>
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS