Skip to content

Instantly share code, notes, and snippets.

View ergo70's full-sized avatar

Ernst-Georg Schmid ergo70

View GitHub Profile
DROP TYPE public.fraction CASCADE;
CREATE TYPE public.fraction AS
(z numeric(1000,0),
n numeric(1000,0));
CREATE OR REPLACE FUNCTION frac_make_fraction(z NUMERIC(1000,0), n NUMERIC(1000,0))
RETURNS fraction AS $$
declare retval fraction;
BEGIN
@ergo70
ergo70 / cats.py
Last active November 19, 2016 21:51
psycopg2 asynchronous cache updates w. LISTEN/NOTIFY and tcn
# -*- coding: utf-8 -*-
"""
Created on Sun Nov 13 00:00:06 2016
@author: ergo
"""
import select
import psycopg2
import psycopg2.extensions
import threading
@ergo70
ergo70 / notify.py
Created November 13, 2016 17:54
psycopg2 asynchronous notifications w. LISTEN/NOTIFY
# -*- coding: utf-8 -*-
"""
Created on Sun Nov 13 00:00:06 2016
@author: ergo
"""
import select
import psycopg2
import psycopg2.extensions
@ergo70
ergo70 / __init__.py
Created March 9, 2016 20:27
Multicorn soilgrids_fdw_json
from multicorn import ForeignDataWrapper
import urllib2
class SoilGridsForeignDataWrapper(ForeignDataWrapper):
def __init__(self, options, columns):
super(SoilGridsForeignDataWrapper, self).__init__(options, columns)
def execute(self, quals, columns):
@ergo70
ergo70 / __init__.py
Created February 12, 2016 22:00
Multicorn soilgrids_fdw
from multicorn import ForeignDataWrapper
import json
import urllib2
class SoilGridsForeignDataWrapper(ForeignDataWrapper):
def __init__(self, options, columns):
super(SoilGridsForeignDataWrapper, self).__init__(options, columns)
@ergo70
ergo70 / insert.sql
Created January 28, 2016 14:05
Insert
INSERT INTO plr_modules VALUES (0, 'library(e1071)');
INSERT INTO plr_modules VALUES (1, 'mysvm <- readRDS("mysvm.RDS")');
@ergo70
ergo70 / r_predict5.sql
Last active January 28, 2016 19:28
predict5
CREATE OR REPLACE FUNCTION r_predict5(inp integer[])
RETURNS SETOF text AS
$BODY$
if (pg.state.firstpass)
{
library(e1071)
mysvm <- readRDS("mysvm.rds")
assign("pg.state.firstpass", FALSE, env=.GlobalEnv)
@ergo70
ergo70 / r_predict4.sql
Last active January 28, 2016 13:45
predict4
CREATE OR REPLACE FUNCTION r_predict4(inp integer)
RETURNS text AS
$BODY$
result <- predict(mysvm, inp)
return(as.character(result[1:1]))
$BODY$
LANGUAGE plr IMMUTABLE STRICT
COST 100;
@ergo70
ergo70 / r_predict3.sql
Created January 28, 2016 07:03
predict3
CREATE OR REPLACE FUNCTION r_predict3(inp integer)
RETURNS text AS
$BODY$
if (pg.state.firstpass)
{
library(e1071)
mysvm <- readRDS("mysvm.rds")
assign("pg.state.firstpass", FALSE, env=.GlobalEnv)
@ergo70
ergo70 / svm2.R
Created January 28, 2016 06:39
R svm demo code
library(e1071)
data <- seq(1,10)
classes <- c('b','b','b','b','a','a','a','a','b','b')
mysvm = svm (data, classes, type='C', kernel='radial', gamma=0.1, cost=10)
saveRDS(mysvm, "mysvm.rds")