Skip to content

Instantly share code, notes, and snippets.

View mattapayne's full-sized avatar

Matt Payne mattapayne

View GitHub Profile
#Using Gistr within a view
<%= gist(12345) -%>
1. private List parseComplaints(String results)
2. {
3. List complaints = new ArrayList();
4. try
5. {
6. JSONArray objects = new JSONArray(results);
7. for(int i=0; i<objects.length(); i++)
8. {
9. JSONObject o = (JSONObject)objects.get(i);
10. Complaint c = new Complaint();
1. private String get(String url, Map params)
2. {
3. String result = null;
4. try
5. {
6. String queryString = getEncodedQueryString(params);
7. String fullUrl = url + "?" + queryString;
8. DefaultHttpClient client = new DefaultHttpClient();
9. HttpGet method = new HttpGet(new URI(fullUrl));
10. HttpResponse response = client.execute(method);
JSONArray objects = new JSONArray(response);
def create_bar_chart(opts, data)
g = Gruff::Bar.new(opts[:size])
g.title = opts[:title]
g.minimum_value = opts[:minimum]
g.maximum_value = opts[:maximum]
g.labels = data.map { |e| e.category }
g.data(opts[:legend], data.map { |e| e.count } )
g.x_axis_label = opts[:x_axis_label]
g.y_axis_label = opts[:y_axis_label]
return g.to_blob
configure do
RDefensio::API.configure do |conf|
conf.api_key = App::Config.defensio_api_key
conf.owner_url = App::Config.defensio_owner_url
end
end
#To announce an article:
RDefensio::API.announce_article({
"article-author" => "Me",
"article-author-email" => "my@email.com",
"article-title" => @post.title,
"article-content" => @post.body,
"permalink" => @post.slug
}
#To audit a comment:
#This is a Gist. This is also how you embed the Gist
<script src="http://gist.github.com/98216.js"></script>
#For Rails:
#in an initializer
JamBase4R.configure do |c|
c.api_key = "your JamBase API key" #this is mandatory
c.logger = RAILS_DEFAULT_LOGGER #or any class that implements the same interface (optional)
end
#For Sinatra
#within the main application file
configure do
#Using JamBase4R in Rails is simple. Just include it in the controller you want to use
class MyJamBaseController < ApplicationController
include JamBase4R
def search
@results = API.search(params[:search])
#You could also NOT include JamBase4R and just call it like so:
# @results = JamBase4R::API.search(params[:search])
end