Skip to content

Instantly share code, notes, and snippets.

View gklopper's full-sized avatar

Grant Klopper gklopper

  • The Guardian
  • London
View GitHub Profile

Keybase proof

I hereby claim:

  • I am gklopper on github.
  • I am grantk (https://keybase.io/grantk) on keybase.
  • I have a public key whose fingerprint is EA21 FA51 57A9 E67C 579A A979 EB5A 0218 BC5A 3F89

To claim this, I am signing this object:

# Safari HTTP Pipelining bug.
if(
req.http.user-agent ~ ".*Version/.*Safari/.*" &&
req.http.user-agent !~ ".*Chrome.*"
&& req.http.user-agent !~ ".*BB.*"
) {
set resp.http.Connection = "close";
}
@gklopper
gklopper / gist:7230260
Created October 30, 2013 10:22
Getting Cost metrics from AWS - before these are recorded in CloudWatch you first need to setup a billing alarm (use the web console) You need to use the 'default' region, don't set endpoint to eu-west (or anything else)
// charges are only available from the 'default' region
private lazy val defaultCloudClient = new AmazonCloudWatchAsyncClient(Configuration.aws.credentials)
def cost = new CostMetric(defaultCloudClient.getMetricStatisticsAsync(new GetMetricStatisticsRequest()
.withNamespace("AWS/Billing")
.withMetricName("EstimatedCharges")
.withStartTime(new DateTime().toLocalDate.toDate)
.withEndTime(new DateTime().toDate)
.withStatistics("Maximum")
.withPeriod(60 * 60 * 24)
.withDimensions(new Dimension().withName("Currency").withValue("USD")), asyncHandler))
@gklopper
gklopper / gist:5421043
Created April 19, 2013 15:18
How to get AWS load balancer metrics
val cloudClient = new AmazonCloudWatchClient(credentials)
cloudClient.setEndpoint("monitoring.eu-west-1.amazonaws.com")
cloudClient.getMetricStatistics(
new GetMetricStatisticsRequest()
.withStartTime(new DateTime().minusHours(3).toDate)
.withEndTime(new DateTime().toDate)
.withPeriod(60)
.withUnit(StandardUnit.Seconds)
@gklopper
gklopper / gist:4557297
Created January 17, 2013 16:31
Simple working with Amazon DynamoDB
import com.amazonaws.auth.BasicAWSCredentials
import com.amazonaws.services.dynamodb.AmazonDynamoDBClient
import collection.JavaConversions._
import com.amazonaws.services.dynamodb.model.{AttributeValue, PutItemRequest}
object Value {
def apply(s: String) = new AttributeValue(s)
def apply(l: Long) = new AttributeValue().withN(l.toString)
}
@gklopper
gklopper / gist:4493676
Created January 9, 2013 14:48
Ubuntu desktop shortcut
sudo gnome-desktop-item-edit /usr/share/applications/ --create-new
@gklopper
gklopper / gist:1470892
Created December 13, 2011 06:25
How to create a shortcut in Ubuntu
gnome-desktop-item-edit ~/tools/idea-IU-111.69/bin/ --create-new
Reply from 209.85.229.99: bytes=32 time=29ms TTL=52
Reply from 209.85.229.99: bytes=32 time=31ms TTL=52
Reply from 209.85.229.99: bytes=32 time=34ms TTL=52
Request timed out.
Request timed out.
Request timed out.
Reply from 209.85.229.99: bytes=32 time=33ms TTL=52
Reply from 209.85.229.99: bytes=32 time=41ms TTL=52
Reply from 209.85.229.99: bytes=32 time=65ms TTL=52
@gklopper
gklopper / gist:1016110
Created June 9, 2011 05:20
JavaScript that writes out a noscript tag
document.write (');\n');
document.write ('</script><noscript><a href="http://oas.guardian.co.uk/5c/www.guardian.co.uk/commentisfree/2011/jun/08/us-withdraw-talk-iraq-afghanistan/oas.html/L32/895912589/Right1/Guardian/DirectLineHomeInsurance_Right_010611/DirLine_Right_010611.html/545765594e6b794d6461674142366755?http://clk.atdmt.com/DIR/go/330467665/direct/01/895912589" target="_blank"><img border="0" src="http://view.atdmt.com/DIR/view/330467665/direct/01/895912589" /></a></noscript></iframe>\n');
document.write ('<IMG SRC="http://oas.guardian.co.uk/5/www.guardian.co.uk/commentisfree/2011/jun/08/us-withdraw-talk-iraq-afghanistan/oas.html/L32/895912589/Right1/Guardian/DirectLineHomeInsurance_Right_010611/DirLine_Right_010611.html/545765594e6b794d6461674142366755?_RM_EMPTY_&k=usa&k=us-politics&k=usforeignpolicy&k=afghanistan&k=world&k=us-military&cf=us+elections&pid=&ct=article&pt=article&pt=blog&" WIDTH=1 HEIGHT=1>\n');
@gklopper
gklopper / gist:843453
Created February 25, 2011 06:53
Beautifying cache code
val result = cache.get("missing-key") orElse {
cache.put("missing-key", "dog")
Some("dog")
}