Skip to content

Instantly share code, notes, and snippets.

View attentive's full-sized avatar

Tom attentive

View GitHub Profile
@thbaumann
thbaumann / pyqgis_common_functions_examples.py
Created February 20, 2019 13:42
examples for pyqgis common functions
Examples for some pyqgis common functions.
Some may be outdated as things can be done easier in qgis3 now but they should just be an example
for some functions that were use to make life easier during the development of QGIS plugins:
examples from https://github.com/boundlessgeo/lib-qgis-commons/blob/master/qgiscommons2/layers.py
def load_layer(filename, name = None):
'''
Tries to load a layer from the given file
:param filename: the path to the file to load.
@tmcw
tmcw / hygxyz.py
Created June 12, 2012 16:00
process hyg star database into a shapefile with shapely and fiona
import shapely
import fiona
from fiona import collection
import csv
star_csv = csv.reader(open('hygxyz.csv', 'rb'))
header = star_csv.next()
max_x = 10000000
@ithayer
ithayer / tf-idf.clj
Created June 28, 2011 06:32
Simple tf-idf in 30 lines of clojure. Inspired by a nice simple scala implementation: https://github.com/felipehummel/TinySearchEngine/blob/master/scala/tinySearch.scala and matches as closely as possible the computation.
(ns ignacio.tfidf (:require [clojure.contrib.string :as string])) ;; Simple tfidf in clojure, for fun.
(def stopwords (set (string/split #"\n" (slurp "./stopwords.txt"))))
(defn tokenize [raw-text] ;; Lowercases and splits on non-letters, non-numbers.
(remove stopwords (string/split #"[^a-z0-9äöüáéíóúãâêîôûàèìòùçñ]+" (string/lower-case raw-text))))
(defn idf2 [n-docs match] (Math/pow (Math/log (/ n-docs (count (keys match)))) 2))
(defn index-one [fname] ;; Index for one file. Given an fname, returns a map of token -> map of (fname, count)