Skip to content

Instantly share code, notes, and snippets.

@johnhw
johnhw / umap_sparse.py
Last active January 6, 2024 16:09
1 million prime UMAP layout
### JHW 2018
import numpy as np
import umap
# This code from the excellent module at:
# https://stackoverflow.com/questions/4643647/fast-prime-factorization-module
import random

A Few Useful Things to Know about Machine Learning

The paper presents some key lessons and "folk wisdom" that machine learning researchers and practitioners have learnt from experience and which are hard to find in textbooks.

1. Learning = Representation + Evaluation + Optimization

All machine learning algorithms have three components:

  • Representation for a learner is the set if classifiers/functions that can be possibly learnt. This set is called hypothesis space. If a function is not in hypothesis space, it can not be learnt.
  • Evaluation function tells how good the machine learning model is.
  • Optimisation is the method to search for the most optimal learning model.
@jarmitage
jarmitage / himawari-8.py
Last active March 5, 2018 09:21
Himawari-8 Wallpaper Bot: Fresh images of the whole Earth from space, every 10 minutes
import urllib
import datetime as dt
import pytz
from PIL import Image
import numpy as np
import subprocess
import socket
import os
dir = '/FULL/PATH/TO/SCRIPT/DIR'
/**
* Based on the mysql cluster
* @link http://jonisalonen.com/2012/k-means-clustering-in-mysql/
*/
-- SELECT
-- * FROM
-- unnest(kmeans(array(SELECT
-- (
-- lat,
@samuelschumacher
samuelschumacher / Installation - Linux
Last active November 13, 2015 18:17
Serving Vector Tiles from a Linux Server- Tilestache + PostgreSQL + Mapnik + Leaflet
From https://github.com/NelsonMinar/vector-river-map (Could be great for PLSSFinder reset, includes basemap and server configuration)
We should set up an NGINX server if we reconfigure the Ubuntu Servers.
Mapbox studio creates vector tiles using protocol buffer format. This is efficient, but also not supported by tilestache currently. We can, however, render JSONs from a postgres database and use the cartoCSS from mapbox for styling.
If one would like to open a project created from a different machine, paths must be changed in the following files (using LCFRstyle4 and LCFRtiles for example, your names may vary):
LCFRstyle4.tm2/project.yml
LCFRstyle4.tm2/project.xml
@wboykinm
wboykinm / README.md
Last active August 29, 2015 13:57 — forked from NelsonMinar/README.md
vectors from tilestache test

Fun with vector maps

Quick TopoJSON vector tile demo map, derived from Nelson Minar's awesome work.

A goofy slippy map of various vector tile data sources.

Want to make maps like this? See my vector tiles tutorial.

Tested with Chrome. If the background tiles are pepto-bismol pink instead of gunmetal grey, your browser doesn't support -webkit-filter.

@jimkang
jimkang / README.md
Last active December 30, 2015 17:59 — forked from mbostock/.block

This example, using satirical data from The Onion, demonstrates how to wrap long axis labels to fit on multiple lines.

Update (jimkang): Added a data accessor function as a parameter to mbostock's wrap() so that it can fetch the text from the data source rather than using text().

The problem with text() is that it is built on textContent which "returns the text content of this node and its descendants." If a text element has several tspan descendants, it joins their contents without spaces. e.g. a text element with three tspans each containing 'why', 'are', and 'we' will give back 'whyarewe' through text(). The rest of wrap will proceed to treat that as one word, naturally.

This becomes an issue when wrap() is called multiple times on text elements that have already been processed by wrap().

@phette23
phette23 / current-dir-in-iterm-tab-title.sh
Last active August 3, 2024 16:51
Set the iTerm tab title to the current directory, not full path.
# put this in your .bash_profile
if [ $ITERM_SESSION_ID ]; then
export PROMPT_COMMAND='echo -ne "\033];${PWD##*/}\007"; ':"$PROMPT_COMMAND";
fi
# Piece-by-Piece Explanation:
# the if condition makes sure we only screw with $PROMPT_COMMAND if we're in an iTerm environment
# iTerm happens to give each session a unique $ITERM_SESSION_ID we can use, $ITERM_PROFILE is an option too
# the $PROMPT_COMMAND environment variable is executed every time a command is run
# see: ss64.com/bash/syntax-prompt.html
@bmcbride
bmcbride / LeafletToWKT.js
Last active June 7, 2022 02:17
Leaflet layer to WKT
function toWKT(layer) {
var lng, lat, coords = [];
if (layer instanceof L.Polygon || layer instanceof L.Polyline) {
var latlngs = layer.getLatLngs();
for (var i = 0; i < latlngs.length; i++) {
latlngs[i]
coords.push(latlngs[i].lng + " " + latlngs[i].lat);
if (i === 0) {
lng = latlngs[i].lng;
lat = latlngs[i].lat;
@senko
senko / onchange.sh
Last active July 14, 2023 07:54
OnChange - Watch current directory and execute a command if anything in it changes
#!/bin/bash
#
# Watch current directory (recursively) for file changes, and execute
# a command when a file or directory is created, modified or deleted.
#
# Written by: Senko Rasic <senko.rasic@dobarkod.hr>
#
# Requires Linux, bash and inotifywait (from inotify-tools package).
#
# To avoid executing the command multiple times when a sequence of