This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* for use with Array. Easy way to create an index, and then sort the index *) | |
let index a = Array.init ( Array.length a) (fun i -> i) | |
let sort_index a idx = | |
let cmpi i j = compare a.(i) a.(j) in | |
Array.fast_sort cmpi idx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* compute GCD. playing with OCaml *) | |
let rec gcd n m = | |
if m = 0 then | |
n | |
else | |
if n > m | |
then | |
gcd (n-m) m | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* 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 | |
;; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* 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 | |
;; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ) ) |
OlderNewer