Skip to content

Instantly share code, notes, and snippets.

View brikis98's full-sized avatar

Yevgeniy Brikman brikis98

View GitHub Profile
@brikis98
brikis98 / Existential.js
Created June 12, 2011 04:09
JavaScript existence
var country = model.profile().location.country.toString();
@brikis98
brikis98 / ExistentialDefensive.js
Created June 12, 2011 05:53
JavaScript defensive programming
var country = null;
if (typeof model !== 'undefined' && model && typeof model.profile === 'function') {
var profile = model.profile();
if (profile && profile.location && profile.location.country) {
country = profile.location.country.toString();
}
}
@brikis98
brikis98 / ExistentialDefensive.coffee
Created June 12, 2011 06:20
CoffeeScript defensive programming
country = model?.profile?()?.location?.country?.toString()
@brikis98
brikis98 / LinkedInClient.coffee
Created June 12, 2011 07:09
LinkedIn API Client in CoffeeScript
OAuth = require('oauth').OAuth
_ = require 'underscore'
class LinkedInClient
@baseUrl: 'https://api.linkedin.com'
@requestTokenUrl: "#{@baseUrl}/uas/oauth/requestToken"
@accessTokenUrl: "#{@baseUrl}/uas/oauth/accessToken"
@authorizeUrl: "#{@baseUrl}/uas/oauth/authorize"
@profileFields: ['id', 'headline', 'first-name', 'last-name', 'public-profile-url', 'picture-url', 'educations', 'positions', 'email-address']
@brikis98
brikis98 / LinkedInAuthMiddleware.coffee
Created June 12, 2011 07:10
LinkedIn Auth Middleware
LinkedInClient = require('./LinkedInClient').LinkedInClient
_ = require 'underscore'
url = require 'url'
exports.linkedinAuth = (apiKey, apiSecret, baseUrl, secureUrls) ->
(req, res, next) ->
req.session.tokens ?= {}
req.linkedInClient = new LinkedInClient {apiKey: apiKey, apiSecret: apiSecret}, req.session.tokens
handleError = (error) ->
@brikis98
brikis98 / gist:1024228
Created June 14, 2011 03:07
Java GC log example (Young Generation collections)
325209.429: [GC 325209.429: [ParNew
Desired survivor size 4128768 bytes, new threshold 2 (max 2)
- age 1: 1812544 bytes, 1812544 total
- age 2: 305568 bytes, 2118112 total
: 1034582K->2103K(1040512K), 0.0116910 secs]
2598263K->1565814K(3137664K), 0.0118312 secs]
@brikis98
brikis98 / gist:1024230
Created June 14, 2011 03:08
Java GC log explanation (Young Generation collections)
{Time since VM started, in seconds}: [GC {Time since VM started}: [{GC type}
Desired survivor size {size of one survivor space} bytes, new threshold {y} (max {x}) <- how many collections objects can stay in the young gen. More on this later
- age 1: {a} bytes, {a} total <- How many objects have survived one collection. Next collection, any surviving objects will appear in age 2
- age 2: {b} bytes, {a+b} total
: {pre-collection young gen[5] usage}K->{post-collection young gen usage}K({Total young gen size}K), {young gen time} secs]
{pre-collection heap size}K->{post-collection heap size}K({total heap size}K), {total collection time} secs]
@brikis98
brikis98 / gist:1024233
Created June 14, 2011 03:10
Java GC log example (CMS)
294989.748: [GC
[1 CMS-initial-mark: 1782676K(2097152K)] 1784501K(3137664K), 0.0067714 secs]
295047.329: [Rescan (parallel) , 0.2497803 secs]
295047.579: [weak refs processing, 0.1272999 secs]
[1 CMS-remark: 1782929K(2097152K)] 2303079K(3137664K), 0.3816787 secs]
295049.065: [CMS-concurrent-reset: 0.019/0.019 secs]
@brikis98
brikis98 / gist:1024235
Created June 14, 2011 03:11
Java GC log explanation (CMS)
{Time since VM started, in seconds}: [GC
[1 CMS-initial-mark: {estimated old gen usage}K({total old gen size}K)] {estimated heap usage}K({total heap size}K), {pause time} secs]
{Time since VM started, in seconds}: [Rescan (parallel) , {pause time} secs]
{Time since VM started, in seconds}: [weak refs processing, {pause time} secs]
[1 CMS-remark: {old gen usage}K({total old gen size}K)] {heap usage}K({total heap size}K), {pause time} secs]
{Time since VM started, in seconds}: [CMS-concurrent-reset: 0.019/0.019 secs]
@brikis98
brikis98 / PlayAsyncIOContinuations.java
Created July 6, 2011 00:46
Play framework async I/O with continuations
public class AsyncTest extends Controller
{
public static void continuation()
{
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);