Skip to content

Instantly share code, notes, and snippets.

View erraggy's full-sized avatar

Robbie Coleman erraggy

View GitHub Profile
@erraggy
erraggy / export_cs_Posts.sql
Created May 26, 2011 06:17
The final export query for CommunityServer 2008
SELECT [Subject], PostDate, FormattedBody,
dbo.old_url(PostDate, [Subject]) AS old_url,
dbo.make_slug([Subject]) AS slug
FROM dbo.cs_Posts
WHERE UserID = 2102
AND SectionID = 4
AND PostLevel = 1
AND IsApproved = 1
AND IsLocked = 0
@erraggy
erraggy / dbo.make_slug.sql
Created May 26, 2011 06:34
Scalar function to convert a post title into a URL slug
CREATE FUNCTION [dbo].[make_slug]
(
@post_title nvarchar(256)
)
RETURNS nvarchar(500)
AS
BEGIN
-- Declare the return variable here
DECLARE @slug nvarchar(500)
DECLARE @clean_title nvarchar(500)
@erraggy
erraggy / dbo.old_url.sql
Created May 26, 2011 06:36
Scalar function to format the post date and slug into the post URL
CREATE FUNCTION [dbo].[old_url]
(
@post_date datetime,
@post_title nvarchar(256)
)
RETURNS nvarchar(500)
AS
BEGIN
-- Declare the return variable here
DECLARE @url nvarchar(500)
@erraggy
erraggy / dbo.removePunctuation.sql
Created May 26, 2011 06:41
Scalar function to strip a string of all non-alphanumeric characters (except spaces)
CREATE FUNCTION [dbo].[removePunctuation]
(
@input nvarchar(500)
)
RETURNS nvarchar(500)
AS
BEGIN
/**
* Based on Nigel Rivett's SQL script found:
* http://www.nigelrivett.net/SQLTsql/RemoveNonNumericCharacters.html
@erraggy
erraggy / dbo.deDupeSpaces.sql
Created May 26, 2011 06:57
Scalar function to reduce all repeating space characters down to a single space character
CREATE FUNCTION [dbo].[deDupeSpaces]
(
@input nvarchar(500)
)
RETURNS nvarchar(500)
AS
BEGIN
/**
* Based on Nigel Rivett's SQL script found:
* http://www.nigelrivett.net/SQLTsql/RemoveNonNumericCharacters.html
@erraggy
erraggy / insert_cs_posts.sql
Created May 26, 2011 07:31
Custome query to insert the data I exported from CommunityServer into WordPress
INSERT INTO wp_xxxxx_posts
(post_author,
post_date,
post_date_gmt,
post_content,
post_title,
post_status,
post_name,
post_modified,
post_modified_gmt,
@erraggy
erraggy / gist:1903276
Created February 24, 2012 19:51
Maven Dependency example for HPaste
<dependency>
<groupId>com.gravity</groupId>
<artifactId>gravity-hpaste</artifactId>
<version>0.1.11</version>
</dependency>
@erraggy
erraggy / gist:1903478
Created February 24, 2012 20:19
Creating a WebTable
class WebTable extends HbaseTable[WebTable, String, WebPageRow](tableName = "pages", rowKeyClass = classOf[String]) {
def rowBuilder(result: DeserializedResult) = new WebPageRow(this, result)
val meta = family[String, String, Any]("meta")
val title = column(meta, "title", classOf[String])
val lastCrawled = column(meta, "lastCrawled", classOf[DateTime])
val content = family[String, String, Any]("text", compressed = true)
val article = column(content, "article", classOf[String])
val attributes = column(content, "attrs", classOf[Map[String, String]])
@erraggy
erraggy / gist:1903494
Created February 24, 2012 20:22
Putting values into the WebTable
WebCrawlingSchema.WebTable
.put("http://mycrawledsite.com/crawledpage.html")
.value(_.title, "My Crawled Page Title")
.value(_.lastCrawled, new DateTime())
.value(_.article, "Jonsie went to the store. She didn't notice the spinning of the Earth, nor did the Earth notice the expansion of the Universe.")
.value(_.attributes, Map("foo" -> "bar", "custom" -> "data"))
.valueMap(_.searchMetrics, Map(new DateMidnight(2011, 6, 5) -> 3l, new DateMidnight(2011, 6, 4) -> 34l))
.execute()
@erraggy
erraggy / gist:1903511
Created February 24, 2012 20:25
Querying values out of the WebTable
WebCrawlingSchema.WebTable.query2.withKey("http://mycrawledsite.com/crawledpage.html")
.withColumns(_.title, _.lastCrawled)
.withFamilies(_.searchMetrics)
.singleOption() match {
case Some(pageRow) => {
println("Title: " + pageRow.column(_.title).getOrElse("No Title"))
println("Crawled on: " + pageRow.column(_.lastCrawled).getOrElse(new DateTime()))
pageRow.family(_.searchMetrics).foreach {
case (date: DateMidnight, views: Long) =>