Skip to content

Instantly share code, notes, and snippets.

View saml's full-sized avatar

Sam Lee saml

  • New York, NY
View GitHub Profile
// @flow
type Yo = Path | URL;
class Path {
title: string;
path: string;
}
class URL {
title: string;
GET _search
{
"explain": true,
"query": {
"function_score": {
"query": {
"filtered": {
"query": {
"query_string": {
"query": "\"cafe edison\"",
//Caused by: java.lang.ClassCastException: com.ning.http.client.providers.netty.NettyResponse cannot be cast to play.api.libs.ws.ning.NingWSResponse
//response.underlying[NingWSResponse].ahcResponse.getResponseBodyAsBytes() does not work
// Downloads content at url and saves to a temporary file.
private def downloadTempFile(url: String): Future[Option[(File, Option[String])]] =
WS.url(url).getStream().flatMap {
case (response, body) =>
val contentType = response.headers.get("Content-Type").flatMap(_.headOption)
if (response.status == 200) {
val tmpFile = File.createTempFile("imgContent", ".tmp")
var http = require('http');
var fs = require('fs');
var usage = `Usage: ${process.argv[0]} ${process.argv[1]} <filepath> <mimetype> [port]`;
var filePath = process.argv[2];
if (!filePath) {
throw new Error(usage);
}
var mimetype = process.argv[3]
if (!mimetype) {
throw new Error(usage);
<!doctype html>
<title>Object Literal or Block in JS</title>
<meta charset="utf-8">
<p>View Console. And View Source.</p>
<script>
{"x": 1};
</script>
import re
var r = re.re("((a+)+)$")
if re.match("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab", r):
echo("good")
else:
echo("bad")
cmd/command1/
Cargo.toml
src/
main.rs # want to use lib1 here.
pkg/lib1/
Cargo.toml
src/
lib.rs
'use strict';
const fs = require('fs');
const crypto = require('crypto');
const input = fs.createReadStream(__filename);
const encrypt = crypto.createCipher("aes-256-ctr", "iamapassword");
const decrypt = crypto.createDecipher("aes-256-ctr", "iamapassword");
input.pipe(encrypt).pipe(decrypt).pipe(process.stdout);
// http://hastebin.com/ubagequlal.pas
// pit bro
// find deepest pit (which is also the widest due to constraints given in the problem around strict ordering).
function Pit(start, middle, end) {
return {start: start, middle: middle, end: end};
}
var NoPit = Pit(-1, -1, -1);
.PHONY: clean test all
all: bin/foo bin/bar
bin/%: pkg/**/*.go cmd/%/*.go
go build -o $@ ./cmd/$(@F)
test:
go fmt ./pkg/... ./cmd/...
go vet ./pkg/... ./cmd/...