Skip to content

Instantly share code, notes, and snippets.

def fetch[R : Fetchable](s: SQLCursor): R = implicitly[Fetchable[R]].fetch(s)
trait Fetchable[R] {
def fetch(s: SQLCursor): R
}
implicit object IntIsFetchable extends Fetchable[Int] {
def fetch(s: SQLCursor): Int = s.getInt
}
def countChange(money: Int, coins: List[Int]): Int =
if (money < 0 || coins.isEmpty)
0
else if (money == 0)
1
else
countChange(money - coins.head, coins) + countChange(money, coins.tail)
def powerSet[A](xs: List[A]): List[List[A]] =
xs.foldLeft(List(Nil: List[A]))((accum, elem) => accum.flatMap(l => Seq(l, elem :: l)))
@dwins
dwins / prose.vim
Created April 25, 2012 13:08
Custom command for switching to "prose" editing mode
command Prose set background=light wrap linebreak
@dwins
dwins / raster.css
Created April 12, 2012 18:23
Raster properties in CSS
* {
raster-opacity: 0.7;
raster-channel-selection: 1;
raster-channel-selection: 1 2 3;
raster-contrast-enhancement: normalize;
raster-contrast-enhancement: histogram;
raster-contrast-enhancement: gamma-value(2);
raster-shaded-relief: brightness-only;
raster-shaded-relief: relief-factor(55);
raster-shaded-relief: brightness-only relief-factor(55);
@dwins
dwins / gist:1790448
Created February 10, 2012 15:56
Pylint rc file to identify functions, classes, and modules without docstrings
[MASTER]
# Specify a configuration file.
#rcfile=
# Python code to execute, usually for sys.path manipulation such as
# pygtk.require().
#init-hook=
# Profiled execution.
trait Request
class RequestVerbs(req: Request) {
def <:< (headers: Map[String, String]): Request
}
implicit def requestsForVerbs(req: Request): RequestVerbs =
new RequestVerbs(req)
def url(theUrl: String): Request
@dwins
dwins / switch-on-env.sld.xml
Created December 29, 2011 18:55
Switch off rules in GeoServer styles based on query parameters
<?xml version="1.0" encoding="UTF-8"?>
<sld:UserStyle xmlns="http://www.opengis.net/sld"
xmlns:sld="http://www.opengis.net/sld" xmlns:ogc="http://www.opengis.net/ogc"
xmlns:gml="http://www.opengis.net/gml">
<sld:Name>Default Styler</sld:Name>
<sld:Title/>
<sld:FeatureTypeStyle>
<sld:Name>name</sld:Name>
<sld:Rule>
<ogc:Filter>
import org.apache.commons
<?xml version="1.0"?>
<wfs:GetFeature xmlns:wfs="http://www.opengis.net/wfs" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" service="WFS" version="1.1.0" maxFeatures="100" xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd">
<wfs:Query xmlns:feature="http://geonode.org" typeName="feature:conflicts" srsName="EPSG:900913">
<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
<ogc:And>
<ogc:PropertyIsBetween>
<ogc:PropertyName>EpEndDate</ogc:PropertyName>
<ogc:LowerBoundary>
<ogc:Literal>1946-07-21T04:00:00.000Z</ogc:Literal>
</ogc:LowerBoundary>