Skip to content

Instantly share code, notes, and snippets.

View timokoola's full-sized avatar

Timo Koola timokoola

  • Skadi Oy
  • Helsinki
View GitHub Profile
@timokoola
timokoola / vimrc
Last active December 12, 2015 05:48
Vimrc for Python development. Adjusted from: http://svn.python.org/projects/python/trunk/Misc/Vim/vimrc
" vimrc file for following the coding standards specified in PEP 7 & 8.
"
" To use this file, source it in your own personal .vimrc file (``source
" <filename>``) or, if you don't have a .vimrc file, you can just symlink to it
" (``ln -s <this file> ~/.vimrc``). All options are protected by autocmds
" (read below for an explanation of the command) so blind sourcing of this file
" is safe and will not affect your settings for non-Python or non-C files.
"
"
" All setting are protected by 'au' ('autocmd') statements. Only files ending
@timokoola
timokoola / busstops.py
Created December 28, 2015 19:28
Create a static map of nearby public transport stops using Helsinki area Reittiopas API and Google Static Maps API
#!/usr/env/bin/python
# Create a static map of nearby public transport stops using Helsinki area Reittiopas API and Google Static Maps API
# pip install requests if needed
import requests
import sys
import urllib
import string
googleurl = "https://maps.googleapis.com/maps/api/staticmap?center=%s,%s&zoom=%d&scale=2&size=640x640&maptype=roadmap"
# Get API key for Google Static Maps API and documentation at
@timokoola
timokoola / gitlog.sh
Created January 6, 2016 12:11
My git log format line to create hourly reports from commit messages
# Prints out a tab separated line that includes short date format, placeholder for daily hours, double-slash, commit message and a full date in isoformat
git log --reverse --date=short --format="%cd%x0908:00%x09%s%x2F%x2F%ci"
@timokoola
timokoola / index.html
Created September 13, 2016 05:35 — forked from Culho/index.html
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="stylesheet" href="http://cmx.io/v/0.1/cmx.css">
<script src="http://cmx.io/v/0.1/cmx.js" charset="utf-8"></script>
<style>.cmx-user-scene4 .cmx-text-border .cmx-path {stroke: orange}</style>
<body>
<div style="max-width:900px; -webkit-transform:rotate(0deg)">
<scene id="scene1">
<label t="translate(0,346)">
@timokoola
timokoola / RecycleViewMatcher.java
Created November 30, 2016 08:29 — forked from baconpat/RecycleViewMatcher.java
RecycleViewMatcher (updated for scrolling)
package com.foo.RecyclerViewMatcher;
import android.content.res.Resources;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
@timokoola
timokoola / release_notes.py
Created February 23, 2017 02:13
Python project release note in code
import os.path
import datetime
text = """
# Release note
Creating semi-autoupdated Python release notes with some timestamp magic.
Timestamp updates when document is saved and/or is `touch`:ed by a build script.
"""
timestamp = datetime.datetime.fromtimestamp(os.path.getmtime("release_notes.py")).isoformat()
@timokoola
timokoola / adjective.py
Created July 6, 2017 11:43
Function to check if a word is an adjective in its baseform in Finnish using libvoikko
from libvoikko import Voikko
v = Voikko("fi")
def adjective(w):
analyzed = v.analyze(w)
for item in analyzed:
if "CLASS" in item and "laatusana" in item["CLASS"] and "SIJAMUOTO" in item and item[
"SIJAMUOTO"] == "nimento" and w == item["BASEFORM"]:
return True
return False
@timokoola
timokoola / s3_uploader.py
Created August 23, 2017 12:58
Snippet to (crudely) resize images in a directory and upload to a S3 bucket
import os
from PIL import Image
desired_w = 300.0
bucket_name = "mybucket"
files = [x for x in os.listdir() if x.endswith("jpg")]
for i in files:
@timokoola
timokoola / verb_end_syllable.py
Created August 24, 2017 19:31
End syllables of Finnish language verbs in base form (using Kotus sanalist)
import xmltodict
from libvoikko import Voikko
f = open("kotus-sanalista_v1.xml")
text = f.read()
f.close()
kotus = xmltodict.parse(text)
verbs = [x["s"] for x in kotus["kotus-sanalista"]["st"] if "t" in x and "tn" in x["t"] and int(x["t"]["tn"]) >= 52 and int(x["t"]["tn"]) <99 ]
@timokoola
timokoola / scrapegrammar.js
Created October 13, 2020 14:45
Node.js snippet for quick json creation from scraped webpage (Chinese Grammar Wiki)
const cheerio = require("cheerio");
const got = require("got");
const fs = require("fs");
const hsk3URL =
"https://resources.allsetlearning.com/chinese/grammar/HSK_3_grammar_points";
(async () => {
const response = await got(hsk3URL);
const $ = cheerio.load(response.body);