Skip to content

Instantly share code, notes, and snippets.

def tryWithDefault[A, B](a: A, b: B)(pf: PartialFunction[A, B]): B =
if (pf isDefinedAt a) pf(a)
else b
println(tryWithDefault(1, 0) { case n if n % 2 == 0 => n / 2 }) // 0
println(tryWithDefault(12, 0) { case n if n % 2 == 0 => n / 2 }) // 6
@dwins
dwins / gist:953516
Created May 3, 2011 15:20
sample gsconfig datastore creation
ds = self.cat.create_datastore()
ds.name = "gsconfig"
ds.parameters.update(
host="localhost", port="5432", database="db", user="postgres",
passwd="password", dbtype="postgis")
self.cat.save(ds)
@dwins
dwins / upload-roads.py
Created April 28, 2011 13:29
basic gsconfig load test
#!/usr/bin/env python
from geoserver.catalog import Catalog
cat = Catalog("http://localhost:8001/geoserver/rest", username="admin", password="geoserver")
topp = cat.get_workspace("topp")
files = dict((x, "roads." + x) for x in ["shp", "prj", "dbf", "shx"])
for i in xrange(0, 200):
cat.create_featurestore("roads_" + str(i), files, workspace=topp)
for i in xrange(0, 200):
@dwins
dwins / point.xml
Created April 25, 2011 20:02
Sample point symbolizer in SLD
<?xml version="1.0" encoding="UTF-8"?>
<sld:UserStyle xmlns="http://www.opengis.net/sld" xmlns:sld="http://www.opengis.net/sld" xmlns:ogc
<sld:Name>Default Styler</sld:Name>
<sld:Title/>
<sld:FeatureTypeStyle>
<sld:Name>name</sld:Name>
<sld:Rule>
<sld:PointSymbolizer>
<sld:Graphic>
<sld:Mark>
override def managedStyle = ManagedStyle.Maven
lazy val publishTo = Resolver.file("local maven repo", (Path.userHome / ".m2" / "repository") asFile)
@dwins
dwins / find_nulls.py
Created March 28, 2011 19:18
test geoserver config using gsconfig.py
#! /usr/bin/env python
from geoserver.catalog import Catalog
cat = Catalog('http://host/geoserver/rest', 'user', 'password')
def internal_name(s):
return s.startswith("__") and s.endswith("__")
def check(x):
apache-tomcat-6.0.32/bin/catalina.sh start
paster serve --reload riab_geonode/riab/deploy/project.paste.ini
apache-tomcat-6.0.32/bin/catalina.sh stop
function checkup() {
REPO="$1"
WORKING_DIR="$2"
if [ -d "${WORKING_DIR}" ];
then
echo "Updating ${WORKING_DIR} from upstream"
# (cd "${WORKING_DIR}" && git pull)
else
git clone "${REPO}" "${WORKING_DIR}"
fi
#! /usr/bin/env python
from geoserver.catalog import Catalog
cat = Catalog('http://demo.geonode.org/geoserver-geonode-dev/rest/') # + username, password)...
def check(x):
for name in dir(x):
if getattr(x, name) is None:
print x, name, "IS NONE"
def reverse[A](xs: List[A]): List[A] = {
def reverse0(xs: List[A], accum: List[A]): List[A] =
xs match {
case Nil => accum
case h :: t => reverse0(t, h :: accum)
}
reverse0(xs, Nil)
}