Skip to content

Instantly share code, notes, and snippets.

@daniel-perry
daniel-perry / ssh-agent-singleton-bashrc.sh
Created August 3, 2012 21:58
how to setup ssh-agent so there is only one process running.
# ssh-agent singleton setup
# If no SSH agent is already running, start one now. Re-use sockets so we never
# have to start more than one session.
export SSH_AUTH_SOCK=$HOME/.ssh-socket
NKEYS_SSHAGENT=`ssh-add -l 2> /dev/null | wc -l`
if [ $NKEYS_SSHAGENT = 0 ]; then
# No ssh-agent running
rm -f $SSH_AUTH_SOCK
ssh-agent -a $SSH_AUTH_SOCK >/tmp/.ssh-script
source /tmp/.ssh-script
@daniel-perry
daniel-perry / inverse.cc
Created December 11, 2012 23:53
inverse of a symmetric matrix... taking into account singularity due to numerical error...
template < class MatrixType >
MatrixType inverse(const MatrixType & m)
{
typedef itk::Vector<typename MatrixType::ValueType, MatrixType::RowDimensions> VectorType;
typedef itk::SymmetricEigenAnalysis<MatrixType,VectorType> EigenAnalysisType;
EigenAnalysisType eigenAnalysis;
eigenAnalysis.SetOrderEigenMagnitudes(true); // order by abs val of eigenvals..
eigenAnalysis.SetDimension(MatrixType::RowDimensions);
VectorType eigenVals;
MatrixType eigenVecs;
# originally from:
# http://groups.google.com/group/ggplot2/attach/6bf632a9718dddd6/ggcorplot.R?part=2
# linked to from here:
# http://www.r-bloggers.com/five-ways-to-visualize-your-pairwise-comparisons/
# I've updated to remove warnings and errors.
library(ggplot2)
#define a helper function (borrowed from the "ez" package)
ezLev=function(x,new_order){
@daniel-perry
daniel-perry / pom.xml
Created December 4, 2013 16:23
This mahout example: https://cwiki.apache.org/confluence/display/MAHOUT/Quick+tour+of+text+analysis+using+the+Mahout+command+line assumes you know how to use maven to run apache lucene on some text.. which I didn't. This gist is a pom.xml file that will allow you to run the indicated maven command on the reuters text dataset, cobbled together fr…
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>dataproj.maven</groupId>
<artifactId>running-lucene-with-maven</artifactId>
<packaging>war</packaging>
<version>0.1</version>
<profiles>
<!-- Add profile configuration here -->
</profiles>
#! /usr/bin/env python
"""BIL parser to load elevation info from sites like
http://earthexplorer.usgs.gov/
Mostly based of:
http://stevendkay.wordpress.com/2010/05/29/parsing-usgs-bil-digital-elevation-models-in-python/
Documentation for the format itself:
http://webhelp.esri.com/arcgisdesktop/9.2/index.cfm?TopicName=BIL,_BIP,_and_BSQ_raster_files
# 30D gaussian data set with the following properties:
# anisotropic (covariance not scaled identity)
# non-axis aligned (rotated)
# non-centered (translated)
n = 300
d = 30
Sigma = eye(d)
Sigma[1,1] = 20
@daniel-perry
daniel-perry / kd tree
Last active August 29, 2015 14:18
untested kd tree code
#ifndef COMMON_KDTREE_H
#define COMMON_KDTREE_H
/*
* Copyright (c) 2015 Daniel Perry
*
*/
#include <vector>
using std::vector;
@daniel-perry
daniel-perry / psb2raw.jl
Created April 11, 2015 19:56
rough go at converting .psb (photoshop) image to raw data (block of ints). Assumes .psb is not compressed and uses RGB (easy to change to grayscale).
# converts a .psb (photoshop photo type) to a raw image format.
#
# Raw format:
# height Uint32
# width Uint32
# depth Uint32 (8,16,32)
# data block Uint8, Uint16, Uint32 (depending on depth value = 8, 16, 32)
# using file description Oct 2013 version here:
@daniel-perry
daniel-perry / curve_fitting.jl
Last active October 1, 2015 21:14
curve_fitting.c example from Ceres translated from c to julia
# Conversion of Ceres solver curve fitting example to julia - see http://ceres-solver.org/.
# Copyright (c) Daniel Perry 2015
# MIT License
function init()
ccall((:ceres_init,"libceres"), Void, ())
end
init()
@daniel-perry
daniel-perry / overfeat_sample.jl
Created October 12, 2015 18:09
sample.py from overfeat library translated into julia
using PyPlot
using PyCall
@pyimport overfeat
@pyimport scipy.ndimage as pyndimage
@pyimport scipy.misc as pymisc
# read image
image = pyndimage.imread("../../samples/bee.jpg")
# resize and crop into a 231x231 image