Skip to content

Instantly share code, notes, and snippets.

View saml's full-sized avatar

Sam Lee saml

  • New York, NY
View GitHub Profile
from lxml import etree
import requests
from dateutil.parser import parse as parsedate
import pytz
import sys
from cStringIO import StringIO
import gzip
import io
java.lang.IllegalStateException: Connection pool shut down
	at org.apache.http.impl.conn.tsccm.ConnPoolByRoute.getEntryBlocking(ConnPoolByRoute.java:346)
	at org.apache.http.impl.conn.tsccm.ConnPoolByRoute$1.getPoolEntry(ConnPoolByRoute.java:300)
	at org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager$1.getConnection(ThreadSafeClientConnManager.java:224)
	at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:401)
	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)
	at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:732)

at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:352)

private def _t[A](title: String = "")(f: => A): A = {
val t: Long = System.currentTimeMillis()
try {
f
} finally {
Logger.debug(s"${title} took ${(System.currentTimeMillis() - t)/1000.0} secs")
}
}
private def _tf[A](title: String = "")(f: => Future[A]): Future[A] = {
//trying this http://stackoverflow.com/a/1560052
def readImageDimension(file: File): Option[Dimension] = {
def getDimension(reader: ImageReader, input: ImageInputStream): Dimension = try {
reader.setInput(input)
val width: Int = reader.getWidth(0)
val height: Int = reader.getHeight(0)
Dimension(width, height)
} finally {
reader.dispose()
def findFirstSuccess[A, B](f: A => B)(iter: Iterator[A]): Option[B] = {
var result: Option[B] = None
iter.find { a: A =>
Try {
result = Option(f(a))
}.isSuccess
}
result
}
@saml
saml / trim.scala
Last active December 19, 2015 15:49
def trim(s: String, c: Char): String = {
val prefixDropped: String = s.dropWhile(_ == c)
val lastNotC: Int = prefixDropped.lastIndexWhere(_ != c)
if (lastNotC == -1) prefixDropped
else prefixDropped.substring(0, lastNotC + 1)
}
@saml
saml / git-example.md
Last active December 19, 2015 18:49
git example messy.
  • master, qa
  • f1 starts.
  • f2 starts.
  • f1 in qa.
  • f2 in qa.
  • f1 gets accepted. f1 goes to master.
  • f3 starts.
  • f3 in qa.
  • f2 gets accepted. f2 goes to master.
  • f3 gets accepted. f3 goes to master.
@saml
saml / github-workflow.md
Created July 15, 2013 17:56
github workflow

Overview

master branch is mainline. You work on features. Features are throughly tested. Features get signed off for release and are merged back to master. When master gets enough features for a release, it's tagged and released. Hotfixes are made against release tags, and merged back to master.

Normal Workflow

*   35f15b3 (HEAD, master) Merge f1
|\  
| * 3a97d51 f1.b
| * 8108b2e f1.a
|/  
| * db73034 (f2) f2.b
| * 0d4b922 f2.a
|/  
* 7ae194b start
@saml
saml / solr nginx.conf
Last active December 20, 2015 02:19
solr nginx conf
location /homepage-latest-articles/ {
proxy_cache default;
proxy_cache_valid 200 10m;
if ($request_method !~ ^GET$) {
return 405;
}
if ($args !~ ^json\.wrf=([^=&]+)$) {
return 400 "need json.wrf= param for callback.\n";