Skip to content

Instantly share code, notes, and snippets.

def availableLocales: Array[Locale] = {
def availble(locale:Locale) = try {
println("trying to find: " + ("GUI_Strings", locale))
val rb = ResourceBundle.getBundle("GUI_Strings", locale, Thread.currentThread.getContextClassLoader)
println("found it: " + rb)
rb
}
catch { case m: MissingResourceException => println("didnt find it"); false }
Locale.getAvailableLocales.filter(availble)
package org.nlogo.hubnet.protocol
import org.nlogo.hubnet.connection.ClientRoles
import java.io.{DataOutputStream, DataInputStream}
import org.nlogo.api.LogoList
object TextProtocol {
val HANDSHAKE = 0
val LOGIN_FAILURE = 1
package org.nlogo.hubnet.protocol
import org.nlogo.hubnet.connection.ClientRoles
import org.nlogo.api.LogoList
import java.io._
case class BinaryProtocol(in:InputStream, out:OutputStream) extends Protocol {
val name = "Binary"
val dataIn = new DataInputStream(in)
val dataOut = new DataOutputStream(out)
#lang racket
;; ---------------------------------------------------------------------------------------------------
;; a functional brain control implementation
(require 2htdp/universe 2htdp/image)
;; decide what is an event on the data stream from the headset
(define meditation? (make-parameter (lambda (prev-med curr-med) (not (eq? 0 curr-med)))))
(define attention? (make-parameter (lambda (prev-att curr-att) #false)))
#lang racket
;; ---------------------------------------------------------------------------------------------------
;; a functional brain control implementation
(require 2htdp/universe 2htdp/image)
;; decide what is an event on the data stream from the headset
(define meditation? (make-parameter (lambda (meditation0 meditation1) #true)))
(define attention? (make-parameter (lambda (attention0 attention1) #false)))
(ns hw1
(:use clojure.test))
(defrecord StringLit [s])
(defrecord Concat [l r])
(defrecord RestAfter [l r])
(defn parse [sexp]
(cond
(symbol? sexp) (StringLit. (str sexp))
scala> val pid = java.lang.management.ManagementFactory.getRuntimeMXBean.getName.takeWhile(_ != '@')
pid: String = 59747
scala> def runProcess(command:String) =
| io.Source.fromInputStream(Runtime.getRuntime.exec(command).getInputStream).getLines()
runProcess: (command: String)Iterator[String]
scala> def findArraysIn_lsof = runProcess("lsof").filter(_.contains("array")).filter(_.contains(pid))
findArraysIn_lsof: Iterator[String]
@joshcough
joshcough / Josh.v
Created October 18, 2011 17:25
Josh Cough is Awesome
Require Import Coq.Strings.String.
Require Export "Prop".
Require Export "Logic".
Inductive person: Type := personc : string -> string -> person.
Definition jc: person := personc "Josh" "Cough".
Inductive awesome : person -> Prop := | ajc : awesome jc.
@joshcough
joshcough / Read.fs
Created October 31, 2011 16:32
Parser Combinator in F#
type ParseResult<'a> =
| Success of 'a * string
| Failure of string
type Parser<'a> =
abstract Parse: string -> ParseResult<'a>
type MappedParser<'a, 'b>(f: 'a -> 'b, m:Parser<'a>) =
interface Parser<'b> with
@joshcough
joshcough / box.fs
Created November 9, 2011 19:23
box
> let f<'a>(a:'a) = match box a with | :? string as s -> s | _ -> "hi";;
val f : 'a -> string
> f(1);;
val it : string = "hi"
> f("hello")
;;
val it : string = "hello"