Skip to content

Instantly share code, notes, and snippets.

View dgfitch's full-sized avatar

Dan Fitch dgfitch

View GitHub Profile
@dgfitch
dgfitch / level1_qc.bash
Last active May 23, 2016 14:34
Level 1 QC script converted to bash with some functions and features
#!/bin/bash
#
# Script that combines all run images into one
# html file for quality assurance.
#
# Assess plots for unusually bad motion or extreme
# amounts of censoring
#
# Examples of functions and redirecting output
#
@dgfitch
dgfitch / gcCursor_excerpt.py
Created January 9, 2015 22:18
Example of drawing left and right eye data in gcCursor psychopy example
while run_trial is True:
imageStim.draw()
# Additional debug dumping crap
data=tracker.getLastSample()
if data:
gaze_dot_left.setPos([data[11],data[12]])
gaze_dot_left.draw()
gaze_dot_right.setPos([data[30],data[31]])
gaze_dot_right.draw()
@dgfitch
dgfitch / gist:4636234
Created January 25, 2013 17:18
VB Area API routes
Public Overrides Sub RegisterArea(ByVal context As System.Web.Mvc.AreaRegistrationContext)
'' general api routes
context.MapRoute(
"api_default_sub_resource",
"api/v1/{controller}/{resource}/{subresource}/{action}.xml",
New With {.version = "1"}
)
context.MapRoute(
@dgfitch
dgfitch / http_stopwatch.fs
Created October 4, 2011 18:32
Simple HTTP statistics timer in F#
open System
open System.IO
open System.Net
open System.Diagnostics
let track (url:string) (log:string) =
while true do
let stopwatch = new Stopwatch()
stopwatch.Start()
(* insert `thing` into each possible place of a list *)
let rec inserts thing = function
| [] -> [ [thing] ]
| (head :: rest) as all ->
let normal = thing :: all
let inserted = List.map (fun n -> head::n) (inserts thing rest)
normal :: inserted
(* give all possible permutations of a list (does not care about uniqueness of elements) *)
let rec permutations = function
let (|>) a b =
let result = a |> b
result (* breakpoint goes here *)
let (|Matches|_|) pattern input =
let matches = Regex.Matches(input, pattern)
if matches.Count > 0 then Some [ for m in matches -> m ] else None
let (|MatchesR|_|) (regex:Regex) input =
let matches = regex.Matches input
if matches.Count > 0 then Some [ for m in matches -> m ] else None
let book = Map [(1, ["daniel"; "martin"; "bella"]); (2, ["daniel"; "martin"]); (3, ["bella"])];;
let words = book |> Map.toList |> List.map snd |> List.concat |> Set.ofList
let inverseBook =
[ for word in words do
let pages =
book
|> Map.toList
|> List.choose (fun (page, pageWords) -> if List.exists ((=) word) pageWords then Some page else None)
let parseFacets (input:Dictionary<string,obj>) =
let facets = new Dictionary<string,IDictionary<string,int>>()
let add k v = facets.Add(k, v)
let parse k =
input.[k]
:?> IEnumerable<KeyValuePair<string,obj>>
|> Seq.map (fun kvp -> kvp.Key, kvp.Value :?> int)
|> Map.ofSeq
:> IDictionary<string,int>
|> add k
let rec union l1 l2 =
match l2 with
| [] -> l1
| x :: xs ->
if memb x l1 then
union l1 xs
else
union (x::l1) xs