Skip to content

Instantly share code, notes, and snippets.

View cmcbride's full-sized avatar

Cameron McBride cmcbride

  • Boston, MA (USA)
View GitHub Profile

Keybase proof

I hereby claim:

  • I am cmcbride on github.
  • I am cmcbride (https://keybase.io/cmcbride) on keybase.
  • I have a public key ASA9sGOXeTsPKKs8InpZXzPbfGr3v0ehS9zIdPDK6pK1Rwo

To claim this, I am signing this object:

@cmcbride
cmcbride / SparkConjugateGradient.scala
Created September 29, 2015 19:20
Test Implementation of Conjugate Gradient for Linear Problem
import org.apache.spark.mllib.linalg.{Vector, Vectors, Matrices}
import org.apache.spark.mllib.linalg.distributed.{IndexedRow, IndexedRowMatrix}
// Ensure a properly ordered local vector from a distributed RDD
// (Int,Double) corresponds to (index, value) where index is the proper order
def array_from_rdd( rdd: RDD[(Int,Double)] ) : Array[Double] =
rdd.sortBy(_._1).map(_._2).toArray
def vec_from_rdd( rdd: RDD[(Int,Double)] ) =
Vectors.dense( array_from_rdd( rdd ) )
// this is a basic bookmarklet to simply CfA proxy use,
// especially with the NASA ADS system.
// (assuming one has a CfA PIN to log into the proxy)
//
// to make it a bookmarklet, run it through:
// John Gruber's Bookmarklet-Builder
// http://daringfireball.net/2007/03/javascript_bookmarklet_builder
// OR
// http://subsimple.com/bookmarklets/jsbuilder.htm
//
// this is a simple bookmarklet to make using NASA ADS simple at CfA
// (assuming one has a CfA PIN to log into the proxy)
//
// to make it a bookmarklet, run it through:
// John Gruber's Bookmarklet-Builder
// http://daringfireball.net/2007/03/javascript_bookmarklet_builder
// OR
// http://subsimple.com/bookmarklets/jsbuilder.htm
var public_url = "adsabs.harvard.edu";
@cmcbride
cmcbride / indent.pro
Created May 22, 2011 18:36
current indent config for C
/* some basic formatting guidelines for C code */
--indent-level 4
--tab-size 8
--no-tabs
--line-length 100
--braces-on-if-line
--braces-on-struct-decl-line
--cuddle-do-while
#include <stdio.h>
void
func( )
{
static int x = 0; // x is initialized only once across three calls of func()
printf( " %d", x ); // outputs the value of x
x = x + 1;
}
#include <stddef.h>
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
void
print_size( char const * const desc, const size_t size )
{
printf(" %10s: %zu bytes\n", desc, size);
@cmcbride
cmcbride / is_int.ml
Created May 16, 2011 01:13
ocaml: check if float is an int
(* ways to check if float is an integer *)
let is_int v =
v = (snd (modf v))
;;
let better_is_int v =
let c = classify_float (fst (modf v)) in
c == FP_zero
;;
@cmcbride
cmcbride / const.c
Created May 14, 2011 22:45
C const
// This is a slight modification of the original at:
// http://www.cap-lore.com/Languages/const.c
//
// Does "int const *" refer to a constant pointer, or a constant integer?
// The following shows what gcc thinks.
// gcc 4 rejects any of the lines below that are commented out.
typedef const int * cip;
typedef int const * icp;
typedef int * const ipc;
typedef int const * const icpc;
(* find min/max of an array, type generic *)
let minmax a =
let start = a.(0), a.(0) in
let mm t e = (min (fst t) e , max (snd t) e ) in
Array.fold_left mm start a
;;