Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Will Fitzgerald committed Apr 4, 2012
0 parents commit 6432780
Show file tree
Hide file tree
Showing 12 changed files with 3,358 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
.sass-cache/*
52 changes: 52 additions & 0 deletions Cakefile
@@ -0,0 +1,52 @@
fs = require 'fs'
{spawn, exec} = require 'child_process'

mergeFiles =(inputFiles, outputFile, minify=false) ->

# Add directories and extensions to filenames
inputFiles = for f in inputFiles
"src/#{f}.coffee"
outputFile = "lib/#{outputFile}.coffee"

remaining = inputFiles.length
appContents = new Array

for inputFile, index in inputFiles then do (inputFile, index) ->
fs.readFile inputFile, 'utf8', (err, fileContents) ->
throw err if err
appContents[index]= fileContents
process() if --remaining is 0

process = ->

fs.writeFile outputFile, appContents.join('\n\n'), 'utf8', (err) ->
throw err if err
exec "coffee --compile #{outputFile}", (err, stdout, stderr) ->
throw err if err
# console.log stdout + stderr
fs.unlink outputFile, (err) ->
throw err if err

js = outputFile.replace /coffee$/, 'js'
console.log js
if minify
js_output_file = js.replace /\.js$/, '.min.js'
exec "java -jar '/users/zeke/.jars/compiler.jar' --js #{js} --js_output_file #{js_output_file}", (err, stdout, stderr) ->
throw err if err
console.log js_output_file

# task 'bake', 'Compile and concatenate CoffeeScript files to JavaScript, and create minified versions', ->
# mergeFiles ['reqwest', 'swagger'], 'swagger', false

task 'watch', 'Automatically recompile CoffeeScript files to JavaScript', ->
coffee = spawn 'coffee', ['-cw', '-o', 'lib/js', 'src/coffee']
coffee.stdout.on 'data', (data) -> console.log data.toString().trim()
test_coffee = spawn 'coffee', ['-cw', '-o', 'test', 'test']
test_coffee.stdout.on 'data', (data) -> console.log data.toString().trim()


task 'dev', "Open source files, run spec in browser, and watch for changes", ->
exec "$EDITOR ."
exec "open test/suite.html"
coffee = spawn 'coffee', ['-cw', '-o', 'lib/js', 'src/coffee']
coffee.stdout.on 'data', (data) -> console.log data.toString().trim()
1 change: 1 addition & 0 deletions README.md
@@ -0,0 +1 @@
JsSet: A small set package for Sets in Javascript
153 changes: 153 additions & 0 deletions lib/js/jsset.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions run.sh
@@ -0,0 +1,7 @@
#!/bin/bash
# unbind if bound
ps -awx | grep "ssh -f -N -L" | grep "8012" | awk '{print $1}' | xargs kill
# bind
ssh -f -N -L 8012:localhost:8012 ec2-50-18-237-212.us-west-1.compute.amazonaws.com
#
open public/fretboard.html
83 changes: 83 additions & 0 deletions src/coffee/jsset.coffee
@@ -0,0 +1,83 @@
this.Set = class Set
constructor: (items=[]) ->
@store= {}
@store[item] = true for item in items

add: (object) ->
@store[object] = true

contains: (object) ->
@store[object] || false

delete: (object) ->
delete(@store[object])

items: () ->
Object.keys(@store)

size: () -> this.items().length

equals: (other) ->
s = @store
eq = true
for item in this.items()
do (item) ->
eq = false unless other.store[item]
return eq unless eq
loc = this
for item in other.items()
do (item) ->
eq = false unless loc.store[item]
return eq

union: (other) ->
new Set(other.items().concat(this.items()))

intersection: (other) ->
ks = []
for item in this.items()
do (item) ->
ks[ks.length] = item if other.contains(item)
new Set(ks)

difference: (other) ->
ks = []
for item in this.items()
do (item) ->
ks[ks.length] = item unless other.contains(item)
new Set(ks)

union_arity: (other) ->
(this.union(other)).size()

intersection_arity: (other) ->
n = 0
for item in this.items()
do (item) ->
n++ if other.contains(item)
n

difference_arity: (other) ->
n = 0
for item in this.items()
do (item) ->
n++ unless other.contains(item)
n

jaccardIndex: (other) -> this.intersection_arity(other) / this.union_arity(other)

jaccardDistance: (other) -> 1 - this.jaccardIndex(other)

hammingDistance: (other) ->
this.union_arity(other) - this.intersection_arity(other)

normalizedHammingDistance: (other,size=null) ->
if size == null
this.jaccardDistance(other)
else
(this.union_arity(other) - this.intersection_arity(other)) / size





0 comments on commit 6432780

Please sign in to comment.