Skip to content

Instantly share code, notes, and snippets.

View brikis98's full-sized avatar

Yevgeniy Brikman brikis98

View GitHub Profile
@brikis98
brikis98 / PlayAsyncIOCallback.java
Created July 6, 2011 01:18
Play framework async I/O with callbacks
public class AsyncTest extends Controller
{
public static void callback()
{
F.Promise<WS.HttpResponse> remoteCall1 = WS.url("http://www.remote-service.com/data/1").getAsync();
F.Promise<WS.HttpResponse> remoteCall2 = WS.url("http://www.remote-service.com/data/2").getAsync();
F.Promise<WS.HttpResponse> remoteCall3 = WS.url("http://www.remote-service.com/data/3").getAsync();
F.Promise<List<WS.HttpResponse>> promises = F.Promise.waitAll(remoteCall1, remoteCall2, remoteCall3);
@brikis98
brikis98 / PlayAsyncIOGotchas.java
Created July 6, 2011 01:43
Play framework async I/O gotchas
public class AsyncTest extends Controller
{
public static void gotchas()
{
params.put("foo", "bar"); // Check if changes to params survive the request being suspended
renderArgs.put("foo", "bar"); // Check if changes to renderArgs survive the request being suspended
final String foo = "bar"; // Must be declared final to use in the callback
F.Promise<WS.HttpResponse> remoteCall1 = WS.url("http://www.remote-service.com/data/1").getAsync();
F.Promise<WS.HttpResponse> remoteCall2 = WS.url("http://www.remote-service.com/data/2").getAsync();
@brikis98
brikis98 / LastModifiedComponent.java
Created July 18, 2011 18:27
Frontier component example
/**
*
* Sample Frontier Component. These are reusable blocks of functionality that can be used to fetch data from databases,
* external services, etc in parallel. This example just sets the lastModified date in the header and adds it to the
* derived data for the JSP.
*
*/
@MinimumAuthenticationLevel(AuthenticationLevel.identified)
public class LastModifiedComponent extends FrontierComponent implements FrontierLifecycleAware
@brikis98
brikis98 / framework.html
Created July 22, 2011 22:57
Getting started with LinkedIn API's
<!-- Add the following to the head of your webpage: -->
<script type="text/javascript" src="http://platform.linkedin.com/in.js">
api_key: your_api_key_goes_here
</script>
@brikis98
brikis98 / CheckBoxes.html
Created July 26, 2011 07:38
Proposed syntax for a Markdown extension that would support form elements
<label>Phones:</label>
<input type="checkbox" name="phones" id="Android" value="Android"/><label for="Android">Android</label>
<input type="checkbox" name="phones" id="iPhone" value="iPhone" checked="checked"/><label for="iPhone">iPhone</label>
<input type="checkbox" name="phones" id="Blackberry" value="Blackberry" checked="checked"/><label for="Blackberry">Blackberry</label>
@brikis98
brikis98 / PostCompanyExample.rb
Created August 9, 2011 00:25
Ruby/Sinatra examples
# For a given company id, update the company's location and website
post '/company' do
# ... process the request ...
"id = #{params[:companyId]}, location = #{params[:location]}, website = #{params[:website]}" # echo back the params
end
@brikis98
brikis98 / CompanyContentModel.java
Created August 9, 2011 00:38
Frontier Content Model Example
/**
*
* A simplified example of a Frontier Content Model that defines some basic data for a company
*
*/
public interface CompanyContentModel extends ContentModelPrototype
{
Integer getCompanyId();
void setCompanyId(Integer companyId);
@brikis98
brikis98 / stores.xml
Created August 9, 2011 00:57
Sample Voldemort Store Configuration
<!-- Sample Voldemort store for "share" data -->
<store>
<name>CompanyStore</name>
<persistence>bdb</persistence>
<routing>client</routing>
<replication-factor>3</replication-factor>
<required-reads>2</required-reads>
<required-writes>2</required-writes>
<key-serializer>
<type>json</type>
@brikis98
brikis98 / asap_example_1.rb
Created August 12, 2011 02:11
Example usage of the ASAP library for JRuby
# ASAP example 1: fetch a list of users and then for each user, fetch their data in parallel
# For simplicity, the format of data returned by our "services" are just CSV strings
data = Asap do
get "http://url/to/user/list" do |users|
# this block of code does not execute until the above request is completed
list = users.split(", ")
list.each do |user|
# all of these will execute in parallel
get "http://url/to/#{user}/data"
@brikis98
brikis98 / jasmine_spec_example.js
Created October 12, 2011 18:03
Jasmine vs. QUnit specs
// Jasmine example
it("expects value to be hello", function () {
var value = "hello";
expect(value).toEqual("hello");
expect(value).not.toEqual("good bye");
});