Skip to content

Instantly share code, notes, and snippets.

View statguy's full-sized avatar

Jussi Jousimo statguy

  • Bangkok, Thailand
View GitHub Profile
@statguy
statguy / write_read_pickle_example.py
Last active February 10, 2022 08:59
Write pickle to and read from S3 and local file system
from typing import Any
import fsspec
import pickle
def write_pickle(data: Any, path: str) -> None:
with fsspec.open(path, "wb") as file:
pickle.dump(data, file)
def read_pickle(path: str) -> Any:
@statguy
statguy / postgis_geometry_column_insert_demo.sql
Created August 9, 2018 03:28
Inserting data to geometry column in PostGIS directly, enforcing SRID
DROP TABLE IF EXISTS temp;
CREATE TABLE temp (
id INT,
geom GEOMETRY(POINT, 4326)
);
-- \d temp
INSERT INTO temp VALUES (1, 'SRID=4326;0000000001C051C3DC37A3DB3C4048374D37C1376D');
# 1. Copy table from http://thai-language.com/ref/starred
# 2. Paste to Google Sheets
# 3. Save as CSV
# 4. Run through top_1000_thai_words.R
# 5. Upload to Anki App via https://api.ankiapp.com/nexus/
library(tidyverse)
library(stringr)
setwd("~/Downloads")
@statguy
statguy / capture.sh
Created November 2, 2017 07:53
Capture video from second screen
#!/bin/bash
ffmpeg -f x11grab -framerate 25 -s 1920x1080 -i :0.0+1920,0 -c:v libx264 -crf 0 -preset ultrafast -qp 0 output.mpg
@statguy
statguy / .profile
Created December 15, 2016 02:02
Bash profile extensions
jsoncatfun() { cat $1 | python -c'import fileinput, json;print(json.dumps(json.loads("".join(fileinput.input())),sort_keys=True, indent=4))'; }
alias jsoncat=jsoncatfun

Most active GitHub users in Thailand

The count of contributions (summary of Pull Requests, opened issues and commits) to public repos at GitHub.com from Wed, 29 Jul 2015 01:52:41 GMT till Fri, 29 Jul 2016 01:52:41 GMT.

Only first 1000 GitHub users according to the count of followers are taken. This is because of limitations of GitHub search. Sorting algo in pseudocode:

githubUsers
 .filter(user => user.followers > 6)
@statguy
statguy / gist:3184ea6ff4ebb927c747
Last active February 16, 2018 16:50
INLA spatial parameters test
library(INLA)
m = 50
points = matrix(runif(m*2), m, 2)
mesh = inla.mesh.2d(loc=points,cutoff=0.05,offset=c(0.1, 0.4),max.edge=c(0.05, 0.5) )
bnd = inla.nonconvex.hull(points, convex=0.12)
mesh = inla.mesh.2d(boundary=bnd,cutoff=0.05,offset = c(1, 0.5),max.edge=c(0.1, 0.5) )
A = inla.spde.make.A(mesh, loc=points)
sigma0 = 1 ## Field std.dev. for theta=0
size = min(c(diff(range(mesh$loc[,1])), diff(range(mesh$loc[,2]))))
range0 = size/5 ## A fifth of the approximate domain width.
library(spdep)
library(INLA)
# Take a subset of the data.
diamina <- read.csv("~/Downloads/diamina_meadows_125000_sample.csv", sep=";", dec=",")
diamina <- subset(diamina, Xcoord>230000 & Ycoord>6910000)
diamina$habitable <- as.factor(diamina$habitable)
diamina$id <- 1:nrow(diamina)
@statguy
statguy / givemeINLA-testing.R
Last active August 29, 2015 13:56
givemeINLA-testing.R patched for downgrading R-INLA
`inla.update` = function(lib = NULL, testing = FALSE, force = FALSE, build.epoch=NULL, build.date=NULL)
{
inla.installer(lib=lib, testing=testing, force=force, build.epoch=build.epoch, build.date=build.date)
}
`inla.installer` = function(lib = NULL, testing = FALSE, force = FALSE, build.epoch=NULL, build.date=NULL)
{
## include depends-on packages here
for(p in c("sp", "Matrix", "splines")) {
if (length(grep(paste("^package:", p, "$", sep=""), search())) == 0) {