Skip to content

Instantly share code, notes, and snippets.

@asw456
asw456 / gist:5610026
Last active December 17, 2015 12:29
downloading all *.gpx route files from the Canterbury Tramping Club website
# commands to get the links (bash)
# $ wget -c -r --no-parent -k -U Mozilla http://www.ctc.org.nz/
# $ find ./www.ctc.org.nz/ -name "*gpx*" > gpxfiles.txt
# gpxfiles.txt has the numbers used in the script below
import re
import os
import requests
numberlist = [6,92,32,86,4,28,27,103,75,46,90,91,1,10,35,97,20,72,52,69,9,12,96,22,40,102,78,14,82,99,83,84,51,58,42,79,55,26,81,53,76,39,56,3,80,45,77,94,60,47,33,95,36,48,2,50,24,25,71,88,16,89,23,11,98,49,31,18,57,13,19,43,61,44,54,74,37,93,7,85,59,104,100,73,8,30,101,41,34,17,38,70,29,21,15,5,87]
function newCurve = spline3d(curve, dt)
% interpote a 3d curve using spline
% path 3*x
% newPath 3*x
x = curve(1, :);
y = curve(2, :);
z = curve(3, :);
t = cumsum([0;sqrt(diff(x(:)).^2 + diff(y(:)).^2 + diff(z(:)).^2)]);
sx = spline(t,x);
sy = spline(t,y);
function gplot3(A, xyz)
% GPLOT3(A, xyz) is nearly the same as GPLOT(A, xy) except
% that the xyz variable requires a third dimension.
% This function takes an adjacency matrix and visualizes it
% in 3D.
[d e] = size(A);
if d ~= e
error('A matrix must be square.');
end
function quickPlot(varargin)
% Quickly plot point clouds of data.
% This works for up to 5 datasets of
% 1D or 2D or 3D data, regardless of the
% row-order or column-order format.
%
% Also works with 2D or 3D matrices.
%
% How to use this function:
% --> Give it data. That's pretty much it.
import urllib
import sys
import re
troll = "dQw4w9WgXcQ"
urlsource = sys.argv[1]
f = urllib.urlopen(urlsource)
s = f.readlines()
@asw456
asw456 / hist3HeightColorMap.m
Created June 9, 2013 05:23
3D histogram colored by z-value in Matlab
%a = kelly(:)
%b = repmat([1:1:14]',8,1)
%c = kron([1:1:8],ones(1,14))'
%d = [ b, c]
%hist3(a,{ b c })
kelly1 = kelly';
close all
figure()
@asw456
asw456 / downloadGists.js
Created June 9, 2013 05:27
download all gists
var request = require('request')
, path = require('path')
, fs = require('fs')
, url = "https://api.github.com/users/thomastraum/gists"
, savepath = './gists';
request(url, function (error, response, body) {
if (!error && response.statusCode == 200) {
@asw456
asw456 / downloadGists.py
Created June 9, 2013 05:28
download Gists
#!/usr/bin/env python
# Clone or update all a user's gists
# curl -ks https://raw.github.com/gist/5466075/gist-backup.py | python
# curl -ks https://raw.github.com/gist/5466075/gist-backup.py | USER=fedir python
# USER=fedir python gist-backup.py
import json
import urllib
from subprocess import call
from urllib import urlopen
In [1]: import numpy as np
In [2]: from scipy.spatial.distance import cdist
In [3]: from distlib import pairwise_cython_blas, pairwise_cython
In [4]: a = np.random.random(size=(1000,3))
In [5]: %timeit cdist(a,a)
100 loops, best of 3: 11.3 ms per loop
import numpy as np
from collections import deque
import time
import threading
import matplotlib.pyplot as plt
def rollingFFT(s, n, dt):
fy = np.fft.fft(s)
# Frequencies associated with each samples